3 * Platform-independent interface to the logger
5 * This module contains the POSIX syslog logger interface
8 * Neale Ferguson <neale@sinenomine.net>
29 #include "mono-logger-internals.h"
30 #include "mono-proclib.h"
32 static FILE *logFile
= NULL
;
33 static void *logUserData
= NULL
;
38 * @level - GLogLevelFlags value
39 * @returns The equivalent character identifier
42 mapLogFileLevel(GLogLevelFlags level
)
44 if (level
& G_LOG_LEVEL_ERROR
)
46 if (level
& G_LOG_LEVEL_CRITICAL
)
48 if (level
& G_LOG_LEVEL_WARNING
)
50 if (level
& G_LOG_LEVEL_MESSAGE
)
52 if (level
& G_LOG_LEVEL_INFO
)
54 if (level
& G_LOG_LEVEL_DEBUG
)
60 * mono_log_open_logfile:
61 * \param path Path for log file
62 * \param userData Not used
63 * Open the logfile. If the path is not specified default to stdout. If the
64 * open fails issue a warning and use stdout as the log file destination.
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:
92 * \param domain Identifier string
93 * \param level Logging level flags
94 * \param format \c printf format string
95 * \param vargs Variable argument list
96 * Write data to the log file.
99 mono_log_write_logfile (const char *log_domain
, GLogLevelFlags level
, mono_bool hdr
, const char *message
)
110 #ifdef HAVE_LOCALTIME_R
113 localtime_r(&t
, &tod
);
114 strftime(logTime
, sizeof(logTime
), "%Y-%m-%d %H:%M:%S", &tod
);
119 strftime(logTime
, sizeof(logTime
), "%F %T", tod
);
122 pid
= mono_process_current_pid ();
124 fprintf (logFile
, "%s level[%c] mono[%d]: %s\n", logTime
, mapLogFileLevel (level
), pid
, message
);
126 fprintf (logFile
, "%s%s%s\n",
127 log_domain
!= NULL
? log_domain
: "",
128 log_domain
!= NULL
? ": " : "",
134 if (level
& G_LOG_LEVEL_ERROR
)
139 * mono_log_close_logfile:
143 mono_log_close_logfile()
146 if (logFile
!= stdout
)