#define DEBUG_LOG_BUFFER_MARGIN 1024
// Initialize logging. Call only once.
-bool
+void
init_log(const Config& config)
{
- logfile_path = config.log_file();
-
- if (logfile_path.empty()) {
- return false;
- }
-
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 (config.log_file().empty()) {
- return config.debug();
- }
+
#ifdef HAVE_SYSLOG
if (config.log_file() == "syslog") {
use_syslog = true;
openlog("ccache", LOG_PID, LOG_USER);
- return true;
+ return; // Don't open logfile
}
#endif
+
+ logfile_path = config.log_file();
logfile = fopen(logfile_path.c_str(), "a");
- if (logfile) {
#ifndef _WIN32
+ if (logfile) {
set_cloexec_flag(fileno(logfile));
-#endif
- return true;
- } else {
- return false;
}
+#endif
}
static void
class Config;
-bool init_log(const Config& config);
+void 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);
expect_stat 'cache miss' 2
expect_stat 'files in cache' 1
+ # -------------------------------------------------------------------------
+ TEST "CCACHE_DEBUG"
+
+ unset CCACHE_LOGFILE
+ unset CCACHE_NODIRECT
+ CCACHE_DEBUG=1 $CCACHE_COMPILE -c test1.c
+ if ! grep -q Result: test1.o.ccache-log; then
+ test_failed "Unexpected data in <obj>.ccache-log"
+ fi
+ if ! grep -q "PREPROCESSOR MODE" test1.o.ccache-input-text; then
+ test_failed "Unexpected data in <obj>.ccache-input-text"
+ fi
+ for ext in c p d; do
+ if ! [ -f test1.o.ccache-input-$ext ]; then
+ test_failed "<obj>.ccache-input-$ext missing"
+ fi
+ done
+
# -------------------------------------------------------------------------
TEST "CCACHE_DISABLE"