-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlogmsg.h
92 lines (80 loc) · 2.46 KB
/
logmsg.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*************************************************
* logmsg.h
* Copyright (c) Rennie deGraaf, 2005-2007. All rights reserved.
* $Id: logmsg.h 14 2005-07-26 02:00:59Z degraaf $
*
* Generic system for logging error or status messages to various targets.
* See logmsg.c for further details.
*
* This file is part of the libwheel project.
*
* libwheel is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* libwheel is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with libwheel; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
**************************************************/
#ifndef LOGMSG_H
#define LOGMSG_H
#ifdef __cplusplus
#include <cstring>
#include <cstdarg>
#include <cerrno>
using std::strerror;
using std::va_list;
#else
#include <errno.h>
#include <string.h>
#include <stdarg.h>
#endif
#ifdef __cplusplus
namespace LibWheel
{
#endif
/* valid log facilities */
typedef enum
{
logmsg_stderr,
logmsg_stdout,
logmsg_syslog,
logmsg_file
} logmsg_facility_t;
/* valid log priorities */
typedef enum
{
logmsg_emerg,
logmsg_alert,
logmsg_crit,
logmsg_err,
logmsg_warning,
logmsg_notice,
logmsg_info,
logmsg_debug
} logmsg_priority_t;
/* flags for logmsg options */
#define LOGMSG_PID 1
#ifdef __cplusplus
extern "C" {
#endif
#if (!defined LOGMSG_HPP || defined LOGMSG_CPP) /* don't pollute the C++ namespace */
int logmsg_open(logmsg_facility_t facility, unsigned options, const char* name);
int logmsg(logmsg_priority_t priority, const char* format, ...) __attribute__((format(printf, 2, 3)));
int vlogmsg(logmsg_priority_t priority, const char* format, va_list args);
int logmsg_close();
#endif
/* shortcut to log library function errors */
#define LOGMSG_LIB(FUNC) logmsg(logmsg_err, "%s: %s (%s:%i)", #FUNC, strerror(errno), __FILE__, __LINE__)
/* shortcut to log a fatal exit message */
#define LOGMSG_FATAL_EXIT() logmsg(logmsg_notice, "Exiting due to fatal error")
#ifdef __cplusplus
}}
#endif
#endif /* LOGMSG_H */