Skip to content

Commit

Permalink
feat(logging): setup min log level, log dir and set file mode to log …
Browse files Browse the repository at this point in the history
…files
  • Loading branch information
lotem committed Dec 17, 2019
1 parent 27ac4dd commit 90839b0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/rime/setup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/rime/setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/rime_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/rime_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 90839b0

Please sign in to comment.