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"
31 #include "mono-time.h"
33 static FILE *logFile
= NULL
;
34 static void *logUserData
= NULL
;
39 * @level - GLogLevelFlags value
40 * @returns The equivalent character identifier
43 mapLogFileLevel(GLogLevelFlags level
)
45 if (level
& G_LOG_LEVEL_ERROR
)
47 if (level
& G_LOG_LEVEL_CRITICAL
)
49 if (level
& G_LOG_LEVEL_WARNING
)
51 if (level
& G_LOG_LEVEL_MESSAGE
)
53 if (level
& G_LOG_LEVEL_INFO
)
55 if (level
& G_LOG_LEVEL_DEBUG
)
61 * mono_log_open_logfile:
62 * \param path Path for log file
63 * \param userData Not used
64 * Open the logfile. If the path is not specified default to stdout. If the
65 * open fails issue a warning and use stdout as the log file destination.
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:
93 * \param domain Identifier string
94 * \param level Logging level flags
95 * \param format \c printf format string
96 * \param vargs Variable argument list
97 * Write data to the log file.
100 mono_log_write_logfile (const char *log_domain
, GLogLevelFlags level
, mono_bool hdr
, const char *message
)
111 #ifdef HAVE_LOCALTIME_R
114 localtime_r(&t
, &tod
);
115 strftime(logTime
, sizeof(logTime
), MONO_STRFTIME_F
" " MONO_STRFTIME_T
, &tod
);
120 strftime(logTime
, sizeof(logTime
), MONO_STRFTIME_F
" " MONO_STRFTIME_T
, tod
);
123 pid
= mono_process_current_pid ();
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:
144 mono_log_close_logfile()
147 if (logFile
!= stdout
)