[logging] Fix g_error not aborting.
[mono.git] / mono / utils / mono-log-posix.c
1 /*
2  * mono-log-posix.c: POSIX interface to the logger
3  *
4  * This module contains the POSIX syslog logger routines
5  *
6  * Author:
7  *    Neale Ferguson <neale@sinenomine.net>
8  *
9  */
10 #include <config.h>
11
12 #ifdef HAVE_UNISTD_H
13 #include <unistd.h>
14 #endif
15
16 #if defined(_POSIX_VERSION) 
17
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <ctype.h>
21 #include <string.h>
22 #include <glib.h>
23 #include <syslog.h>
24 #include <stdarg.h>
25 #include <errno.h>
26 #include <time.h>
27 #include <sys/time.h>
28 #include "mono-logger-internals.h"
29
30 static void *logUserData = NULL;
31
32 /**
33  * mapSyslogLevel:
34  *      
35  *      @level - GLogLevelFlags value
36  *      @returns The equivalent syslog priority value
37  */
38 static __inline__ int
39 mapSyslogLevel(GLogLevelFlags level) 
40 {
41         if (level & G_LOG_LEVEL_ERROR)
42                 return (LOG_ERR);
43         if (level & G_LOG_LEVEL_CRITICAL)
44                 return (LOG_CRIT);
45         if (level & G_LOG_LEVEL_WARNING)
46                 return (LOG_WARNING);
47         if (level & G_LOG_LEVEL_MESSAGE)
48                 return (LOG_NOTICE);
49         if (level & G_LOG_LEVEL_INFO)
50                 return (LOG_INFO);
51         if (level & G_LOG_LEVEL_DEBUG)
52                 return (LOG_DEBUG);
53         return (LOG_INFO);
54 }
55
56 /**
57  * mono_log_open_logfile
58  *      
59  *      Open the syslog interface specifying that we want our PID recorded 
60  *      and that we're using the LOG_USER facility.
61  *
62  *      @ident - Identifier: ignored
63  *      @userData - Not used
64  */
65 void
66 mono_log_open_syslog(const char *ident, void *userData)
67 {
68         openlog("mono", LOG_PID, LOG_USER);
69         logUserData = userData;
70 }
71
72 /**
73  * mono_log_write_syslog
74  *      
75  *      Write data to the log file.
76  *
77  *      @domain - Identifier string
78  *      @level - Logging level flags
79  *      @format - Printf format string
80  *      @vargs - Variable argument list
81  */
82 void
83 mono_log_write_syslog(const char *domain, GLogLevelFlags level, mono_bool hdr, const char *message)
84 {
85         syslog (mapSyslogLevel(level), "%s", message);
86
87         if (level & G_LOG_LEVEL_ERROR)
88                 abort();
89 }
90
91 /**
92  * mono_log_close_logfile
93  *
94  *      Close the log file
95  */
96 void
97 mono_log_close_syslog()
98 {
99         closelog();
100 }
101 #endif