* These have default values specified for rolling_enabled and rolling_interval_seconds in Logger.h */
| 88 | * These have default values specified for rolling_enabled and rolling_interval_seconds in Logger.h |
| 89 | */ |
| 90 | bool |
| 91 | Logger::init(const string &file, bool add_timestamp, bool rename_file, LogLevel level, bool rolling_enabled, |
| 92 | int rolling_interval_seconds) |
| 93 | { |
| 94 | if (state_->initialized_) { |
| 95 | LOG_ERROR("Attempt to reinitialize a logger named '%s' that's already been initialized to '%s'.", file.c_str(), |
| 96 | state_->filename_.c_str()); |
| 97 | return false; |
| 98 | } |
| 99 | state_->filename_ = file; |
| 100 | state_->add_timestamp_ = add_timestamp; |
| 101 | state_->rename_file_ = rename_file; |
| 102 | state_->level_ = level; |
| 103 | state_->rolling_enabled_ = rolling_enabled; |
| 104 | state_->rolling_interval_seconds_ = rolling_interval_seconds; |
| 105 | state_->initialized_ = true; // set this to true always - we are not providing re-init() after a failed init() |
| 106 | |
| 107 | int mode = 0; |
| 108 | if (state_->add_timestamp_) { |
| 109 | mode |= TS_LOG_MODE_ADD_TIMESTAMP; |
| 110 | } |
| 111 | |
| 112 | if (!state_->rename_file_) { |
| 113 | mode |= TS_LOG_MODE_DO_NOT_RENAME; |
| 114 | } |
| 115 | |
| 116 | TSReturnCode result = TSTextLogObjectCreate(state_->filename_.c_str(), mode, &state_->text_log_obj_); |
| 117 | |
| 118 | if (result == TS_SUCCESS) { |
| 119 | TSTextLogObjectRollingEnabledSet(state_->text_log_obj_, state_->rolling_enabled_ ? ROLL_ON_TIME : 0); |
| 120 | TSTextLogObjectRollingIntervalSecSet(state_->text_log_obj_, state_->rolling_interval_seconds_); |
| 121 | LOG_DEBUG("Initialized log [%s]", state_->filename_.c_str()); |
| 122 | } else { |
| 123 | state_->level_ = LOG_LEVEL_NO_LOG; |
| 124 | LOG_ERROR("Failed to initialize for log [%s]", state_->filename_.c_str()); |
| 125 | } |
| 126 | |
| 127 | return result == TS_SUCCESS; |
| 128 | } |
| 129 | |
| 130 | void |
| 131 | Logger::setLogLevel(Logger::LogLevel level) |
nothing calls this directly
no test coverage detected