3 This file is part of Cygwin.
5 This software is a copyrighted work licensed under the terms of the
6 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
8 #ifdef __OUTSIDE_CYGWIN__
11 #define __BSD_VISIBLE 1
16 int32_t log_level
= 8; /* Illegal value. Don't change! */
17 tun_bool_t log_debug
= TUN_UNDEF
;
18 tun_bool_t log_syslog
= TUN_UNDEF
;
19 tun_bool_t log_stderr
= TUN_UNDEF
;
21 static CRITICAL_SECTION cs
;
22 static bool cs_inited
;
25 loginit (tun_bool_t opt_stderr
, tun_bool_t opt_syslog
)
27 if (log_debug
== TUN_UNDEF
)
28 TUNABLE_BOOL_FETCH ("kern.log.debug", &log_debug
);
29 if (log_debug
== TUN_UNDEF
)
30 log_debug
= TUN_FALSE
;
32 if (opt_stderr
!= TUN_UNDEF
)
33 log_stderr
= opt_stderr
;
35 TUNABLE_BOOL_FETCH ("kern.log.stderr", &log_stderr
);
36 if (log_stderr
== TUN_UNDEF
)
37 log_stderr
= TUN_FALSE
;
39 if (opt_syslog
!= TUN_UNDEF
)
40 log_syslog
= opt_syslog
;
42 TUNABLE_BOOL_FETCH ("kern.log.syslog", &log_syslog
);
43 if (log_syslog
== TUN_UNDEF
)
44 log_syslog
= TUN_FALSE
;
47 TUNABLE_INT_FETCH ("kern.log.level", &log_level
);
50 InitializeCriticalSection (&cs
);
55 _vlog (const char *file
, int line
, int level
,
56 const char *fmt
, va_list ap
)
61 if ((level
== LOG_DEBUG
&& log_debug
!= TUN_TRUE
)
62 || (level
!= LOG_DEBUG
&& level
>= log_level
))
64 pos
= stpcpy (buf
, "cygserver: ");
65 if (file
&& log_debug
== TUN_TRUE
)
66 pos
+= snprintf (pos
, 16384 - (pos
- buf
), "%s, line %d: ",
67 basename ((char *) file
), line
);
68 vsnprintf (pos
, 16384 - (pos
- buf
), fmt
, ap
);
69 if (log_syslog
== TUN_TRUE
&& level
!= LOG_DEBUG
)
71 if (log_stderr
== TUN_TRUE
|| level
== LOG_DEBUG
)
73 if (!cs_inited
) /* Only occurs in --help scenario */
75 InitializeCriticalSection (&cs
);
78 EnterCriticalSection (&cs
);
81 LeaveCriticalSection (&cs
);
86 _log (const char *file
, int line
, int level
, const char *fmt
, ...)
90 _vlog (file
, line
, level
, fmt
, ap
);
94 _vpanic (const char *file
, int line
, const char *fmt
, va_list ap
)
96 _vlog (file
, line
, LOG_EMERG
, fmt
, ap
);
101 _panic (const char *file
, int line
, const char *fmt
, ...)
105 _vpanic (file
, line
, fmt
, ap
);
107 #endif /* __OUTSIDE_CYGWIN__ */