diff --git a/include/eepp/system/log.hpp b/include/eepp/system/log.hpp index a1e9b4239..737df276c 100644 --- a/include/eepp/system/log.hpp +++ b/include/eepp/system/log.hpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace EE { namespace System { @@ -32,6 +33,16 @@ class EE_API Log : protected Mutex { SINGLETON_DECLARE_HEADERS( Log ) public: + static std::unordered_map getMapFlag(); + + static constexpr LogLevel getDefaultLogLevel() { +#ifdef EE_DEBUG + return LogLevel::Debug; +#else + return LogLevel::Info; +#endif + } + static Log* create( const std::string& logPath, const LogLevel& level, bool consoleOutput, bool liveWrite ); @@ -112,7 +123,9 @@ class EE_API Log : protected Mutex { Log::instance()->writel( LogLevel::Debug, text ); } - static void info( const std::string& text ) { Log::instance()->writel( LogLevel::Info, text ); } + static void info( const std::string& text ) { + Log::instance()->writel( LogLevel::Info, text ); + } static void notice( const std::string& text ) { Log::instance()->writel( LogLevel::Notice, text ); @@ -172,11 +185,7 @@ class EE_API Log : protected Mutex { bool mSave; bool mConsoleOutput; bool mLiveWrite; -#ifdef EE_DEBUG - LogLevel mLogLevelThreshold{ LogLevel::Debug }; -#else - LogLevel mLogLevelThreshold{ LogLevel::Notice }; -#endif + LogLevel mLogLevelThreshold{ getDefaultLogLevel() }; IOStreamFile* mFS; std::list mReaders; diff --git a/src/eepp/system/log.cpp b/src/eepp/system/log.cpp index b5d70db92..30ae0c749 100644 --- a/src/eepp/system/log.cpp +++ b/src/eepp/system/log.cpp @@ -20,6 +20,13 @@ namespace EE { namespace System { SINGLETON_DECLARE_IMPLEMENTATION( Log ) +std::unordered_map Log::getMapFlag() { + return { { "debug", LogLevel::Debug }, { "info", LogLevel::Info }, + { "notice", LogLevel::Notice }, { "warning", LogLevel::Warning }, + { "error", LogLevel::Error }, { "critical", LogLevel::Critical }, + { "assert", LogLevel::Assert } }; +} + Log* Log::create( const std::string& logPath, const LogLevel& level, bool consoleOutput, bool liveWrite ) { if ( NULL == ms_singleton ) { diff --git a/src/eepp/system/translator.cpp b/src/eepp/system/translator.cpp index cf5f21c01..4eedd41c0 100644 --- a/src/eepp/system/translator.cpp +++ b/src/eepp/system/translator.cpp @@ -226,7 +226,7 @@ void Translator::setLanguageFromLocale( std::locale locale ) { if ( "C" == name ) { #if defined( EE_SUPPORT_EXCEPTIONS ) && EE_PLATFORM != EE_PLATFORM_WIN try { - const char* loc = setlocale( LC_ALL, "" ); + const char* loc = setlocale( LC_CTYPE, "" ); locale = std::locale( loc ); name = locale.name(); } catch ( ... ) { diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index 633e9f567..0d7c2e36b 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -333,7 +333,7 @@ void App::runCommand( const std::string& command ) { } } -void App::loadConfig() { +void App::loadConfig( const LogLevel& logLevel ) { mConfigPath = Sys::getConfigPath( "ecode" ); if ( !FileSystem::fileExists( mConfigPath ) ) FileSystem::makeDir( mConfigPath ); @@ -347,9 +347,9 @@ void App::loadConfig() { FileSystem::makeDir( mPluginsPath ); FileSystem::dirAddSlashAtEnd( mPluginsPath ); #ifndef EE_DEBUG - Log::create( mConfigPath + "ecode.log", LogLevel::Info, false, true ); + Log::create( mConfigPath + "ecode.log", logLevel, false, true ); #else - Log::create( mConfigPath + "ecode.log", LogLevel::Debug, true, true ); + Log::create( mConfigPath + "ecode.log", logLevel, true, true ); #endif mConfig.load( mConfigPath, mKeybindingsPath, mInitColorScheme, mRecentFiles, mRecentFolders, @@ -3221,13 +3221,13 @@ FontTrueType* App::loadFont( const std::string& name, std::string fontPath, return FontTrueType::New( name, fontPath ); } -void App::init( std::string file, const Float& pidelDensity, const std::string& colorScheme, - bool terminal ) { +void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDensity, + const std::string& colorScheme, bool terminal ) { DisplayManager* displayManager = Engine::instance()->getDisplayManager(); Display* currentDisplay = displayManager->getDisplayIndex( 0 ); mDisplayDPI = currentDisplay->getDPI(); - loadConfig(); + loadConfig( logLevel ); currentDisplay = displayManager->getDisplayIndex( mConfig.window.displayIndex < displayManager->getDisplayCount() @@ -3275,8 +3275,8 @@ void App::init( std::string file, const Float& pidelDensity, const std::string& } ContextSettings contextSettings = engine->createContextSettings( &mConfig.ini, "window" ); contextSettings.SharedGLContext = true; - mWindow = engine->createWindow( winSettings, contextSettings ); + mWindow = engine->createWindow( winSettings, contextSettings ); Log::info( "%s (codename: \"%s\") initializing", ecode::Version::getVersionName().c_str(), ecode::Version::getCodename().c_str() ); @@ -3791,6 +3791,10 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { parser, "prefers-color-scheme", "Set the preferred color scheme (\"light\" or \"dark\")", { 'c', "prefers-color-scheme" } ); args::Flag terminal( parser, "terminal", "Open a new terminal", { 't', "terminal" } ); + args::MapFlag logLevel( + parser, "log-level", "The level of details that the application will emmit logs.", + { 'l', "log-level" }, Log::getMapFlag(), Log::getDefaultLogLevel() ); + try { #if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN parser.ParseCLI( argc, argv ); @@ -3811,7 +3815,7 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { } appInstance = eeNew( App, () ); - appInstance->init( filePos ? filePos.Get() : file.Get(), + appInstance->init( logLevel.Get(), filePos ? filePos.Get() : file.Get(), pixelDenstiyConf ? pixelDenstiyConf.Get() : 0.f, prefersColorScheme ? prefersColorScheme.Get() : "", terminal.Get() ); eeSAFE_DELETE( appInstance ); diff --git a/src/tools/ecode/ecode.hpp b/src/tools/ecode/ecode.hpp index 644c83a21..9422b2595 100644 --- a/src/tools/ecode/ecode.hpp +++ b/src/tools/ecode/ecode.hpp @@ -34,8 +34,8 @@ class App : public UICodeEditorSplitter::Client { void createWidgetTreeView(); - void init( std::string file, const Float& pidelDensity, const std::string& colorScheme, - bool terminal ); + void init( const LogLevel& logLevel, std::string file, const Float& pidelDensity, + const std::string& colorScheme, bool terminal ); void setAppTitle( const std::string& title ); @@ -55,7 +55,7 @@ class App : public UICodeEditorSplitter::Client { void runCommand( const std::string& command ); - void loadConfig(); + void loadConfig( const LogLevel& logLevel ); void saveConfig(); diff --git a/src/tools/ecode/plugins/formatter/formatterplugin.cpp b/src/tools/ecode/plugins/formatter/formatterplugin.cpp index cd8ef8646..81f21905c 100644 --- a/src/tools/ecode/plugins/formatter/formatterplugin.cpp +++ b/src/tools/ecode/plugins/formatter/formatterplugin.cpp @@ -162,8 +162,8 @@ void FormatterPlugin::formatDoc( UICodeEditor* editor ) { path = doc->getFilePath(); } - Log::info( "FormatterPlugin::formatDoc for %s took %.2fms", path.c_str(), - clock.getElapsedTime().asMilliseconds() ); + Log::debug( "FormatterPlugin::formatDoc for %s took %.2fms", path.c_str(), + clock.getElapsedTime().asMilliseconds() ); } void FormatterPlugin::runFormatter( UICodeEditor* editor, const Formatter& formatter, diff --git a/src/tools/ecode/plugins/linter/linterplugin.cpp b/src/tools/ecode/plugins/linter/linterplugin.cpp index 4eb745afe..59eb8ec06 100644 --- a/src/tools/ecode/plugins/linter/linterplugin.cpp +++ b/src/tools/ecode/plugins/linter/linterplugin.cpp @@ -376,10 +376,10 @@ void LinterPlugin::runLinter( std::shared_ptr doc, const Linter& l invalidateEditors( doc.get() ); - Log::info( "LinterPlugin::runLinter for %s took %.2fms. Found: %d matches. Errors: %d, " - "Warnings: %d, Notices: %d.", - path.c_str(), clock.getElapsedTime().asMilliseconds(), totalMatches, totalErrors, - totalWarns, totalNotice ); + Log::debug( "LinterPlugin::runLinter for %s took %.2fms. Found: %d matches. Errors: %d, " + "Warnings: %d, Notices: %d.", + path.c_str(), clock.getElapsedTime().asMilliseconds(), totalMatches, + totalErrors, totalWarns, totalNotice ); } }