Skip to content

Commit d5a770b

Browse files
committed
Add option to always log to syslog.
1 parent ca2cd8f commit d5a770b

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/client.cc

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,24 @@ int RequestPrompts(sasl_client_params_t *params, sasl_interact_t **prompts,
133133
return SASL_INTERACT;
134134
}
135135

136+
Log::Options GetLogOptions() {
137+
if (Config::Get()->always_log_to_syslog()) return Log::OPTIONS_IMMEDIATE;
138+
if (Config::Get()->log_full_trace_on_failure())
139+
return Log::OPTIONS_FULL_TRACE_ON_FAILURE;
140+
return Log::OPTIONS_NONE;
141+
}
142+
143+
Log::Target GetLogTarget() {
144+
if (Config::Get()->always_log_to_syslog() ||
145+
Config::Get()->log_to_syslog_on_failure())
146+
return Log::TARGET_SYSLOG;
147+
return Log::TARGET_NONE;
148+
}
149+
136150
} // namespace
137151

138152
Client::Client() {
139-
const Log::Options log_options = Config::Get()->log_full_trace_on_failure()
140-
? Log::OPTIONS_FULL_TRACE_ON_FAILURE
141-
: Log::OPTIONS_NONE;
142-
const Log::Target log_target = Config::Get()->log_to_syslog_on_failure()
143-
? Log::TARGET_DEFAULT
144-
: Log::TARGET_NONE;
145-
log_ = Log::Create(log_options, log_target);
153+
log_ = Log::Create(GetLogOptions(), GetLogTarget());
146154
log_->Write("Client: created");
147155
}
148156

src/config.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ int Config::Init(const Json::Value &root) {
145145
err = Fetch(root, "client_secret", false, &client_secret_);
146146
if (err != SASL_OK) return err;
147147

148+
err = Fetch(root, "always_log_to_syslog", true,
149+
&always_log_to_syslog_);
150+
if (err != SASL_OK) return err;
151+
148152
err = Fetch(root, "log_to_syslog_on_failure", true,
149153
&log_to_syslog_on_failure_);
150154
if (err != SASL_OK) return err;

src/config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Config {
3434

3535
std::string client_id() const { return client_id_; }
3636
std::string client_secret() const { return client_secret_; }
37+
bool always_log_to_syslog() const { return always_log_to_syslog_; }
3738
bool log_to_syslog_on_failure() const { return log_to_syslog_on_failure_; }
3839
bool log_full_trace_on_failure() const { return log_full_trace_on_failure_; }
3940
std::string token_endpoint() const { return token_endpoint_; }
@@ -48,6 +49,7 @@ class Config {
4849

4950
std::string client_id_;
5051
std::string client_secret_;
52+
bool always_log_to_syslog_ = false;
5153
bool log_to_syslog_on_failure_ = true;
5254
bool log_full_trace_on_failure_ = false;
5355
std::string token_endpoint_ = "https://accounts.google.com/o/oauth2/token";

0 commit comments

Comments
 (0)