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
)
113 localtime_r(&t
, &tod
);
115 strftime(logTime
, sizeof(logTime
), "%Y-%m-%d %H:%M:%S", &tod
);
120 pid
= mono_process_current_pid ();
121 strftime(logTime
, sizeof(logTime
), "%F %T", tod
);
123 fprintf (logFile
, "%s level[%c] mono[%d]: %s\n", logTime
, mapLogFileLevel (level
), pid
, message
);
125 fprintf (logFile
, "%s%s%s\n",
126 log_domain
!= NULL
? log_domain
: "",
127 log_domain
!= NULL
? ": " : "",
133 if (level
& G_LOG_LEVEL_ERROR
)
138 * mono_log_close_logfile:
142 mono_log_close_logfile()
145 if (logFile
!= stdout
)