#endif
}
+ set_up_config(g_config);
+
+ init_log(g_config);
+
exitfn_init();
exitfn_add_nullary(stats_flush);
exitfn_add_nullary(clean_up_pending_tmp_files);
- set_up_config(g_config);
cc_log("=== CCACHE %s STARTED =========================================",
CCACHE_VERSION);
// Destination for g_config.log_file.
static FILE* logfile;
+// Path to the logfile.
+static std::string logfile_path;
+
// Whether to use syslog() instead.
static bool use_syslog;
#define DEBUG_LOG_BUFFER_MARGIN 1024
-static bool
-init_log(void)
+// Initialize logging. Call only once.
+bool
+init_log(const Config& config)
{
- if (debug_log_buffer || logfile || use_syslog) {
- return true;
+ logfile_path = config.log_file();
+
+ if (logfile_path.empty()) {
+ return false;
}
- if (g_config.debug()) {
+
+ if (config.debug()) {
debug_log_buffer_capacity = DEBUG_LOG_BUFFER_MARGIN;
debug_log_buffer = static_cast<char*>(x_malloc(debug_log_buffer_capacity));
debug_log_size = 0;
}
- if (g_config.log_file().empty()) {
- return g_config.debug();
+ if (config.log_file().empty()) {
+ return config.debug();
}
#ifdef HAVE_SYSLOG
- if (g_config.log_file() == "syslog") {
+ if (config.log_file() == "syslog") {
use_syslog = true;
openlog("ccache", LOG_PID, LOG_USER);
return true;
}
#endif
- logfile = fopen(g_config.log_file().c_str(), "a");
+ logfile = fopen(logfile_path.c_str(), "a");
if (logfile) {
#ifndef _WIN32
set_cloexec_flag(fileno(logfile));
// Note: Can't call fatal() since that would lead to recursion.
fprintf(stderr,
"ccache: error: Failed to write to %s: %s\n",
- g_config.log_file().c_str(),
+ logfile_path.c_str(),
strerror(errno));
x_exit(EXIT_FAILURE);
}
static void
vlog(const char* format, va_list ap, bool log_updated_time)
{
- if (!init_log()) {
+ if (!(debug_log_buffer || logfile || use_syslog)) {
return;
}
void
cc_log_argv(const char* prefix, char** argv)
{
- if (!init_log()) {
+ if (!(debug_log_buffer || logfile || use_syslog)) {
return;
}
#include <string>
+class Config;
+
+bool init_log(const Config& config);
void cc_log(const char* format, ...) ATTR_FORMAT(printf, 1, 2);
void cc_bulklog(const char* format, ...) ATTR_FORMAT(printf, 1, 2);
void cc_log_argv(const char* prefix, char** argv);