#include <glib.h>
#include <errno.h>
#include <time.h>
+#ifndef HOST_WIN32
#include <sys/time.h>
-#include "mono-logger.h"
+#else
+#include <process.h>
+#endif
+#include "mono-logger-internals.h"
static FILE *logFile = NULL;
static void *logUserData = NULL;
* @level - GLogLevelFlags value
* @returns The equivalent character identifier
*/
-static __inline__ char
+static inline char
mapLogFileLevel(GLogLevelFlags level)
{
if (level & G_LOG_LEVEL_ERROR)
if (path == NULL) {
logFile = stdout;
} else {
+#ifndef HOST_WIN32
logFile = fopen(path, "w");
+#else
+ gunichar2 *wPath = g_utf8_to_utf16(path, -1, 0, 0, 0);
+ if (wPath != NULL) {
+ logFile = _wfopen((wchar_t *) wPath, L"w");
+ g_free (wPath);
+ }
+#endif
if (logFile == NULL) {
g_warning("opening of log file %s failed with %s - defaulting to stdout",
path, strerror(errno));
+ logFile = stdout;
}
}
logUserData = userData;
* @vargs - Variable argument list
*/
void
-mono_log_write_logfile(const char *domain, GLogLevelFlags level, const char *format, va_list args)
+mono_log_write_logfile (const char *log_domain, GLogLevelFlags level, mono_bool hdr, const char *message)
{
time_t t;
- struct tm tod;
- char logTime[80];
- pid_t pid;
if (logFile == NULL)
logFile = stdout;
- time(&t);
- localtime_r(&t, &tod);
- pid = getpid();
- strftime(logTime, sizeof(logTime), "%F %T", &tod);
- fprintf(logFile, "%s level[%c] mono[%d]: ",logTime,mapLogFileLevel(level),pid);
- vfprintf(logFile, format, args);
- fputc('\n', logFile);
+ if (hdr) {
+ pid_t pid;
+ char logTime [80];
+
+#ifndef HOST_WIN32
+ struct tm tod;
+ time(&t);
+ localtime_r(&t, &tod);
+ pid = getpid();
+ strftime(logTime, sizeof(logTime), "%Y-%m-%d %H:%M:%S", &tod);
+#else
+ struct tm *tod;
+ time(&t);
+ tod = localtime(&t);
+ pid = _getpid();
+ strftime(logTime, sizeof(logTime), "%F %T", tod);
+#endif
+ fprintf (logFile, "%s level[%c] mono[%d]: %s\n", logTime, mapLogFileLevel (level), pid, message);
+ } else {
+ fprintf (logFile, "%s%s%s\n",
+ log_domain != NULL ? log_domain : "",
+ log_domain != NULL ? ": " : "",
+ message);
+ }
+
fflush(logFile);
if (level == G_LOG_FLAG_FATAL)