mce-log.h 3.75 KB
Newer Older
1 2 3 4 5
/**
 * @file mce-log.h
 * Headers for the logging functions for Mode Control Entity
 * <p>
 * Copyright © 2006-2007, 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
6
 * Copyright (C) 2012-2019 Jolla Ltd.
7 8
 * <p>
 * @author David Weinehall <david.weinehall@nokia.com>
9
 * @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * mce is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation.
 *
 * mce 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with mce.  If not, see <http://www.gnu.org/licenses/>.
 */
23 24
#ifndef MCE_LOG_H_
# define MCE_LOG_H_
25

26
# include <syslog.h>
27
# include <stdarg.h>
28

29 30
# define MCE_LOG_SYSLOG		1	/**< Log to syslog */
# define MCE_LOG_STDERR		0	/**< Log to stderr */
31

32
/** Severity of loglevels (subset of syslog priorities) */
33
typedef enum {
34
	LL_NONE    = 0,			/**< No logging at all */
spiiroin's avatar
spiiroin committed
35
	LL_EXTRA   = LOG_ALERT,		/**< Placeholder for devel logging */
36 37 38 39 40 41
	LL_CRIT    = LOG_CRIT,		/**< Critical error */
	LL_ERR     = LOG_ERR,		/**< Error */
	LL_WARN    = LOG_WARNING,	/**< Warning */
	LL_NOTICE  = LOG_NOTICE,	/**< Normal but noteworthy */
	LL_INFO    = LOG_INFO,		/**< Informational message */
	LL_DEBUG   = LOG_DEBUG,		/**< Useful when debugging */
42

43
	LL_DEFAULT = LL_WARN,		/**< Default log level */
44

45
# ifdef ENABLE_DEVEL_LOGGING
spiiroin's avatar
spiiroin committed
46
	LL_DEVEL   = LL_EXTRA,		/**< Log by default on devel build */
47
# else
48
	LL_DEVEL   = LL_NOTICE,		/**< Otherwise verbose mode needed */
49
# endif
50

51 52 53
	LL_MAXIMUM = LOG_DEBUG,		/**< Minimum for bounds checking */
	LL_MINIMUM = LOG_EMERG,		/**< Maximum for bounds checking */

54 55 56 57
	LL_CRUCIAL = LOG_EMERG,		/**< Elevated priority for solving
					 *   problems that require logs from
					 *   the whole user base. Should be
					 *   downgraded as soon as possible. */
58 59
} loglevel_t;

60
# ifdef OSSOLOG_COMPILE
61
void mce_log_add_pattern(const char *pat);
62 63
void mce_log_set_verbosity(int verbosity);
int  mce_log_get_verbosity(void);
64

65
int  mce_log_p_(loglevel_t loglevel,
66
		const char *const file, const char *const function);
67

68 69 70 71 72 73
void mce_log_unconditional_va(loglevel_t loglevel, const char *const file, const char *const function, const char *const fmt, va_list va);

void mce_log_unconditional(loglevel_t loglevel, const char *const file,
		 const char *const function, const char *const fmt, ...)
		  __attribute__((format(printf, 4, 5)));

74
void mce_log_file(loglevel_t loglevel, const char *const file,
75
		  const char *const function, const char *const fmt, ...)
76
		  __attribute__((format(printf, 4, 5)));
77

78 79
void mce_log_open(const char *const name, const int facility, const int type);
void mce_log_close(void);
80

81 82
#  define mce_log_p(LEV_)\
	mce_log_p_(LEV_,__FILE__,__FUNCTION__)
83

84 85
#  define mce_log_raw(LEV_, FMT_, ARGS_...)\
	mce_log_file(LEV_, NULL, NULL, FMT_ , ## ARGS_)
86

87 88 89 90 91 92
#  define mce_log(LEV_, FMT_, ARGS_...)\
	do {\
		if( mce_log_p(LEV_) )\
			mce_log_file(LEV_, __FILE__, __FUNCTION__,\
				     FMT_ , ## ARGS_);\
	} while(0)
93

94 95 96 97 98 99 100 101 102 103 104
# else
/* Dummy versions used when logging is disabled at compile time */
#  define mce_log_add_pattern(PAT_)             do {} while (0)
#  define mce_log_set_verbosity(LEV_)           do {} while (0)
#  define mce_log_open(NAME_, FACILITY_, TYPE_) do {} while (0)
#  define mce_log_close()                       do {} while (0)
#  define mce_log_p(LEV_)                       0
#  define mce_log(LEV_, FMT_, ...)              do {} while (0)
#  define mce_log_raw(LEV_, FMT_, ARGS_...)     do {} while (0)
# endif /* OSSOLOG_COMPILE */
#endif /* MCE_LOG_H_ */