#include "logging.hpp"
#include "Config.hpp"
+#include "File.hpp"
#include "exceptions.hpp"
#include "execute.hpp"
#endif
// Destination for g_config.log_file.
-static FILE* logfile;
+static File logfile;
// Path to the logfile.
static std::string logfile_path;
#endif
logfile_path = config.log_file();
- logfile = fopen(logfile_path.c_str(), "a");
+ logfile.open(logfile_path, "a");
#ifndef _WIN32
if (logfile) {
- set_cloexec_flag(fileno(logfile));
+ set_cloexec_flag(fileno(*logfile));
}
#endif
}
snprintf(prefix, sizeof(prefix), "[%-5d] ", (int)getpid());
#endif
if (logfile) {
- fputs(prefix, logfile);
+ fputs(prefix, *logfile);
}
#ifdef HAVE_SYSLOG
if (use_syslog) {
va_copy(aq, ap);
log_prefix(log_updated_time);
if (logfile) {
- int rc1 = vfprintf(logfile, format, ap);
- int rc2 = fprintf(logfile, "\n");
+ int rc1 = vfprintf(*logfile, format, ap);
+ int rc2 = fprintf(*logfile, "\n");
if (rc1 < 0 || rc2 < 0) {
warn_log_fail();
}
vlog(format, ap, true);
va_end(ap);
if (logfile) {
- fflush(logfile);
+ fflush(*logfile);
}
}
log_prefix(true);
if (logfile) {
- fputs(prefix, logfile);
- print_command(logfile, argv);
- int rc = fflush(logfile);
+ fputs(prefix, *logfile);
+ print_command(*logfile, argv);
+ int rc = fflush(*logfile);
if (rc) {
warn_log_fail();
}