From 90839b0b3d47cbfef715ea5f061c7505666ff75d Mon Sep 17 00:00:00 2001 From: Chen Gong Date: Fri, 13 Dec 2019 03:31:35 +0800 Subject: [PATCH] feat(logging): setup min log level, log dir and set file mode to log files --- src/rime/setup.cc | 12 +++++++++++- src/rime/setup.h | 1 + src/rime_api.cc | 2 +- src/rime_api.h | 10 ++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/rime/setup.cc b/src/rime/setup.cc index 9d1b67d8e..7767ed795 100644 --- a/src/rime/setup.cc +++ b/src/rime/setup.cc @@ -33,10 +33,20 @@ RIME_API void LoadModules(const char* module_names[]) { } } -RIME_API void SetupLogging(const char* app_name) { +RIME_API void SetupLogging(const char* app_name, int min_log_level, const char* log_dir) { #ifdef RIME_ENABLE_LOGGING + FLAGS_minloglevel = min_log_level; + if (log_dir) { + FLAGS_log_dir = log_dir; + } + // Do not allow other users to read/write log files created by current process. + FLAGS_logfile_mode = 0600; google::InitGoogleLogging(app_name); #endif // RIME_ENABLE_LOGGING } +RIME_API void SetupLogging(const char* app_name) { + SetupLogging(app_name, 0, NULL); +} + } // namespace rime diff --git a/src/rime/setup.h b/src/rime/setup.h index a089c0798..6382692f3 100644 --- a/src/rime/setup.h +++ b/src/rime/setup.h @@ -17,6 +17,7 @@ extern const char* kLegacyModules[]; RIME_API void LoadModules(const char* module_names[]); +RIME_API void SetupLogging(const char* app_name, int min_log_level, const char* log_dir); RIME_API void SetupLogging(const char* app_name); } // namespace rime diff --git a/src/rime_api.cc b/src/rime_api.cc index 31df7101b..a13fd4bb2 100644 --- a/src/rime_api.cc +++ b/src/rime_api.cc @@ -68,7 +68,7 @@ RIME_API void RimeSetup(RimeTraits *traits) { setup_deployer(traits); if (PROVIDED(traits, app_name)) { - SetupLogging(traits->app_name); + SetupLogging(traits->app_name, traits->min_log_level, traits->log_dir); } } diff --git a/src/rime_api.h b/src/rime_api.h index 015ccde5b..107c161f3 100644 --- a/src/rime_api.h +++ b/src/rime_api.h @@ -77,6 +77,16 @@ typedef struct rime_traits_t { //! A list of modules to load before initializing const char** modules; + // v1.6 + /*! Minimal level of logged messages. + * Value is passed to Glog library using FLAGS_minloglevel variable. + * 0 = INFO (default), 1 = WARNING, 2 = ERROR, 3 = FATAL + */ + int min_log_level; + /*! Directory of log files. + * Value is passed to Glog library using FLAGS_log_dir variable. + */ + const char* log_dir; } RimeTraits; typedef struct {