2 * mono-log-windows.c: Simplistic simulation of a syslog logger for Windows
4 * This module contains the Windows syslog logger interface
7 * Neale Ferguson <neale@sinenomine.net>
26 #include "mono-logger.h"
28 static FILE *logFile = NULL;
29 static void *logUserData = NULL;
30 static char *logFileName = L".//mono.log";
35 * @level - GLogLevelFlags value
36 * @returns The equivalent character identifier
38 static __inline__ char
39 mapLogFileLevel(GLogLevelFlags level)
41 if (level & G_LOG_LEVEL_ERROR)
43 if (level & G_LOG_LEVEL_CRIT)
45 if (level & G_LOG_LEVEL_WARNING)
47 if (level & G_LOG_LEVEL_MESSAGE)
49 if (level & G_LOG_LEVEL_INFO)
51 if (level & G_LOG_LEVEL_DEBUG)
57 * mono_log_open_logfile
59 * Open the logfile. If the path is not specified default to stdout. If the
60 * open fails issue a warning and use stdout as the log file destination.
62 * @ident - Identifier: ignored
63 * @userData - Not used
66 mono_log_open_syslog(const char *ident, void *userData)
68 logFile = fopen(logFileName, "w");
69 if (logFile == NULL) {
70 g_warning("opening of log file %s failed with %s",
73 logUserData = userData;
77 * mono_log_write_logfile
79 * Write data to the log file.
81 * @domain - Identifier string
82 * @level - Logging level flags
83 * @format - Printf format string
84 * @vargs - Variable argument list
87 mono_log_write_syslog(const char *domain, GLogLevelFlags level, mono_bool hdr, const char *format, va_list args)
98 mono_log_open_logfile(NULL, NULL);
101 localtime_r(&t, &tod);
103 strftime(logTime, sizeof(logTime), "%F %T", &tod);
104 iLog = snprintf(logMessage, sizeof(logMessage), "%s level[%c] mono[%d]: ",
105 logTime,mapLogFileLevel(level),pid);
106 nLog = sizeof(logMessage) - iLog - 2;
107 iLog = vsnprintf(logMessage=iLog, nLog, format, args);
108 logMessage[iLog++] = '\n';
109 logMessage[iLog++] = 0;
110 fputs(logMessage, logFile);
113 if (level == G_LOG_FLAG_FATAL)
118 * mono_log_close_logfile
123 mono_log_close_syslog()