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"
30 static FILE *logFile = NULL;
31 static void *logUserData = NULL;
36 * @level - GLogLevelFlags value
37 * @returns The equivalent character identifier
40 mapLogFileLevel(GLogLevelFlags level)
42 if (level & G_LOG_LEVEL_ERROR)
44 if (level & G_LOG_LEVEL_CRITICAL)
46 if (level & G_LOG_LEVEL_WARNING)
48 if (level & G_LOG_LEVEL_MESSAGE)
50 if (level & G_LOG_LEVEL_INFO)
52 if (level & G_LOG_LEVEL_DEBUG)
58 * mono_log_open_logfile
60 * Open the logfile. If the path is not specified default to stdout. If the
61 * open fails issue a warning and use stdout as the log file destination.
63 * @path - Path for log file
64 * @userData - Not used
67 mono_log_open_logfile(const char *path, void *userData)
73 logFile = fopen(path, "w");
75 gunichar2 *wPath = g_utf8_to_utf16(path, -1, 0, 0, 0);
77 logFile = _wfopen((wchar_t *) wPath, L"w");
81 if (logFile == NULL) {
82 g_warning("opening of log file %s failed with %s - defaulting to stdout",
83 path, strerror(errno));
87 logUserData = userData;
91 * mono_log_write_logfile
93 * Write data to the log file.
95 * @domain - Identifier string
96 * @level - Logging level flags
97 * @format - Printf format string
98 * @vargs - Variable argument list
101 mono_log_write_logfile (const char *log_domain, GLogLevelFlags level, mono_bool hdr, const char *message)
115 localtime_r(&t, &tod);
117 strftime(logTime, sizeof(logTime), "%Y-%m-%d %H:%M:%S", &tod);
123 strftime(logTime, sizeof(logTime), "%F %T", tod);
125 fprintf (logFile, "%s level[%c] mono[%d]: %s\n", logTime, mapLogFileLevel (level), pid, message);
127 fprintf (logFile, "%s%s%s\n",
128 log_domain != NULL ? log_domain : "",
129 log_domain != NULL ? ": " : "",
135 if (level & G_LOG_LEVEL_ERROR)
140 * mono_log_close_logfile
145 mono_log_close_logfile()
148 if (logFile != stdout)