#include "system/filesys.h"
#include "system/syslog.h"
#include "system/locale.h"
+#include "system/network.h"
+#include "system/time.h"
#include "time_basic.h"
#include "close_low_fd.h"
#include "memory.h"
bool initialized;
enum debug_logtype logtype; /* The type of logging we are doing: eg stdout, file, stderr */
char prog_name[255];
+ char hostname[HOST_NAME_MAX+1];
bool reopening_logs;
bool schedule_reopen_logs;
debug_set_backends(logging_param);
}
+static void ensure_hostname(void)
+{
+ int ret;
+
+ if (state.hostname[0] != '\0') {
+ return;
+ }
+
+ ret = gethostname(state.hostname, sizeof(state.hostname));
+ if (ret != 0) {
+ strlcpy(state.hostname, "unknown", sizeof(state.hostname));
+ return;
+ }
+
+ /*
+ * Ensure NUL termination, since POSIX isn't clear about that.
+ *
+ * Don't worry about truncating at the first '.' or similar,
+ * since this is usually not fully qualified. Trying to
+ * truncate opens up the multibyte character gates of hell.
+ */
+ state.hostname[sizeof(state.hostname) - 1] = '\0';
+}
+
+void debug_set_hostname(const char *name)
+{
+ strlcpy(state.hostname, name, sizeof(state.hostname));
+}
+
/**
control the name of the logfile and whether logging will be to stdout, stderr
or a file, and set up syslog
* not yet loaded, then default to timestamps on.
*/
if (!(state.settings.timestamp_logs ||
- state.settings.debug_prefix_timestamp)) {
+ state.settings.debug_prefix_timestamp ||
+ state.settings.debug_syslog_format)) {
return true;
}
GetTimeOfDay(&tv);
+
+ if (state.settings.debug_syslog_format) {
+ if (state.settings.debug_hires_timestamp) {
+ timeval_str_buf(&tv, true, true, &tvbuf);
+ } else {
+ time_t t;
+ struct tm *tm;
+
+ t = (time_t)tv.tv_sec;
+ tm = localtime(&t);
+ if (tm != NULL) {
+ size_t len;
+ len = strftime(tvbuf.buf,
+ sizeof(tvbuf.buf),
+ "%b %e %T",
+ tm);
+ if (len == 0) {
+ /* Trigger default time format below */
+ tm = NULL;
+ }
+ }
+ if (tm == NULL) {
+ snprintf(tvbuf.buf,
+ sizeof(tvbuf.buf),
+ "%ld seconds since the Epoch", (long)t);
+ }
+ }
+
+ ensure_hostname();
+ state.hs_len = snprintf(state.header_str,
+ sizeof(state.header_str),
+ "%s %s %s[%u]: ",
+ tvbuf.buf,
+ state.hostname,
+ state.prog_name,
+ (unsigned int) getpid());
+
+ goto full;
+ }
+
timeval_str_buf(&tv, false, state.settings.debug_hires_timestamp,
&tvbuf);
bool timestamp_logs;
bool debug_prefix_timestamp;
bool debug_hires_timestamp;
+ bool debug_syslog_format;
bool debug_pid;
bool debug_uid;
bool debug_class;
void debug_set_settings(struct debug_settings *settings,
const char *logging_param,
int syslog_level, bool syslog_only);
+void debug_set_hostname(const char *name);
bool reopen_logs_internal( void );
void force_check_log_size( void );
bool need_to_check_log_size( void );