2 * mono-log-common.c: Platform-independent interface to the logger
4 * This module contains the POSIX syslog logger interface
7 * Neale Ferguson <neale@sinenomine.net>
28 #include "mono-logger-internals.h"
29 #include "mono-proclib.h"
31 static FILE *logFile = NULL;
32 static void *logUserData = NULL;
37 * @level - GLogLevelFlags value
38 * @returns The equivalent character identifier
41 mapLogFileLevel(GLogLevelFlags level)
43 if (level & G_LOG_LEVEL_ERROR)
45 if (level & G_LOG_LEVEL_CRITICAL)
47 if (level & G_LOG_LEVEL_WARNING)
49 if (level & G_LOG_LEVEL_MESSAGE)
51 if (level & G_LOG_LEVEL_INFO)
53 if (level & G_LOG_LEVEL_DEBUG)
59 * mono_log_open_logfile
61 * Open the logfile. If the path is not specified default to stdout. If the
62 * open fails issue a warning and use stdout as the log file destination.
64 * @path - Path for log file
65 * @userData - Not used
68 mono_log_open_logfile(const char *path, void *userData)
74 logFile = fopen(path, "w");
76 gunichar2 *wPath = g_utf8_to_utf16(path, -1, 0, 0, 0);
78 logFile = _wfopen((wchar_t *) wPath, L"w");
82 if (logFile == NULL) {
83 g_warning("opening of log file %s failed with %s - defaulting to stdout",
84 path, strerror(errno));
88 logUserData = userData;
92 * mono_log_write_logfile
94 * Write data to the log file.
96 * @domain - Identifier string
97 * @level - Logging level flags
98 * @format - Printf format string
99 * @vargs - Variable argument list
102 mono_log_write_logfile (const char *log_domain, GLogLevelFlags level, mono_bool hdr, const char *message)
116 localtime_r(&t, &tod);
118 strftime(logTime, sizeof(logTime), "%Y-%m-%d %H:%M:%S", &tod);
123 pid = mono_process_current_pid ();
124 strftime(logTime, sizeof(logTime), "%F %T", tod);
126 fprintf (logFile, "%s level[%c] mono[%d]: %s\n", logTime, mapLogFileLevel (level), pid, message);
128 fprintf (logFile, "%s%s%s\n",
129 log_domain != NULL ? log_domain : "",
130 log_domain != NULL ? ": " : "",
136 if (level & G_LOG_LEVEL_ERROR)
141 * mono_log_close_logfile
146 mono_log_close_logfile()
149 if (logFile != stdout)