/usr/include/nih/logging.h is in libnih-dev 1.0.3-6ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | /* libnih
*
* Copyright © 2009 Scott James Remnant <scott@netsplit.com>.
* Copyright © 2009 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2, as
* published by the Free Software Foundation.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef NIH_LOGGING_H
#define NIH_LOGGING_H
/**
* These functions provide a logging interface for outputting messages
* at different priorities, and filtering based on them.
*
* The output for the logger can be selected using nih_log_set_logger(),
* where nih_logger_printf() is the default and nih_logger_syslog() another
* popular alternative.
*
* Log messages are output with different macros.
**/
#include <stdlib.h>
#include <nih/macros.h>
/**
* NihLogLevel:
*
* Severity of log messages, used both to influence formatting of the
* message and to filter messages below a particular severity.
**/
typedef enum {
NIH_LOG_UNKNOWN,
NIH_LOG_DEBUG,
NIH_LOG_INFO,
NIH_LOG_MESSAGE,
NIH_LOG_WARN,
NIH_LOG_ERROR,
NIH_LOG_FATAL
} NihLogLevel;
/**
* NihLogger:
* @priority: priority of message,
* @message: message to log.
*
* A logger is a function that receives a formatted message to be logged
* in whatever manner is appropriate. The priority of the message is given
* so that the logger may direct it appropriately, however the function
* should not discard any messages and instead nih_log_set_priority() used
* to decide the treshold of logged messages.
*
* Returns: zero on success, negative value if the logger was not able
* to output the message.
**/
typedef int (*NihLogger) (NihLogLevel priority, const char *message);
/**
* nih_debug:
* @format: printf-style format string.
*
* Outputs a debugging message, including the name of the function that
* generated it. Almost never shown, except when debugging information is
* required.
**/
#define nih_debug(format, ...) \
nih_log_message (NIH_LOG_DEBUG, "%s: " format, \
__FUNCTION__, ##__VA_ARGS__)
/**
* nih_info:
* @format: printf-style format string.
*
* Outputs a message that is purely informational, usually not shown unless
* the user wants verbose operation.
**/
#define nih_info(format, ...) \
nih_log_message (NIH_LOG_INFO, format, ##__VA_ARGS__)
/**
* nih_message:
* @format: printf-style format string.
*
* Outputs a message from a non-daemon process that is normally shown unless
* the user wants quiet operation. The difference between this and nih_warn()
* is that this is usually send to standard output, instead of standard
* error, and it is not prefixed.
**/
#define nih_message(format, ...) \
nih_log_message (NIH_LOG_MESSAGE, format, ##__VA_ARGS__)
/**
* nih_warn:
* @format: printf-style format string.
*
* Outputs a warning message, one that indicates a potential problem that
* has been ignored; these are shown by default unless the user wants quiet
* operation.
**/
#define nih_warn(format, ...) \
nih_log_message (NIH_LOG_WARN, format, ##__VA_ARGS__)
/**
* nih_error:
* @format: printf-style format string.
*
* Outputs an error message, one that the software may be able to recover
* from but that has caused an operation to fail. These are shown in all
* but the most quiet of operation modes.
**/
#define nih_error(format, ...) \
nih_log_message (NIH_LOG_ERROR, format, ##__VA_ARGS__)
/**
* nih_fatal:
* @format: printf-style format string.
*
* Outputs a fatal error message that caused the software to cease
* functioning. Always shown.
**/
#define nih_fatal(format, ...) \
nih_log_message (NIH_LOG_FATAL, format, ##__VA_ARGS__)
/**
* nih_assert:
* @expr: expression to check.
*
* Outputs a fatal error message and terminates the process if @expr is
* false.
**/
#define nih_assert(expr) \
if (! NIH_LIKELY(expr)) { \
nih_fatal ("%s:%d: Assertion failed in %s: %s", \
__FILE__, __LINE__, __FUNCTION__, #expr); \
abort (); \
}
/**
* nih_assert_not_reached:
*
* Outputs a fatal error message and terminates the process if this
* line of code is reached.
**/
#define nih_assert_not_reached() \
do { \
nih_fatal ("%s:%d: Not reached assertion failed in %s", \
__FILE__, __LINE__, __FUNCTION__); \
abort (); \
} while (0)
NIH_BEGIN_EXTERN
extern NihLogLevel nih_log_priority;
void nih_log_init (void);
void nih_log_set_logger (NihLogger new_logger);
void nih_log_set_priority (NihLogLevel new_priority);
int nih_log_message (NihLogLevel priority, const char *format, ...)
__attribute__ ((format (printf, 2, 3)));
int nih_logger_printf (NihLogLevel priority, const char *message);
int nih_logger_syslog (NihLogLevel priority, const char *message);
NIH_END_EXTERN
#endif /* NIH_LOGGING_H */
|