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