mirror of
https://github.com/troglobit/finit.git
synced 2026-11-08 16:11:10 +00:00
Refactor, _d() et al to use logit() instead of err.h
This patch is the first in a series of changes to clean up the internal logging APIs of Finit: 1. Convert log macros to use logit() for everything (this patch) 2. Set correct syslog() log level based on debug flag 3. Do closelog()/openlog() when toggling debug flag to control LOG_PERROR Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
d1df837d04
commit
5e8cb63f9a
3 files changed
+12
-15
No files matched your search
@@ -39,8 +39,6 @@
|
|||||||
#include "private.h"
|
#include "private.h"
|
||||||
#include "utmp-api.h"
|
#include "utmp-api.h"
|
||||||
|
|
||||||
int _slup = 0; /* INTERNAL: Is syslog up yet? */
|
|
||||||
|
|
||||||
char *strip_line(char *line)
|
char *strip_line(char *line)
|
||||||
{
|
{
|
||||||
char *ptr;
|
char *ptr;
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <lite/lite.h>
|
#include <lite/lite.h>
|
||||||
@@ -46,6 +47,7 @@ void log_toggle_debug(void)
|
|||||||
void logit(int prio, const char *fmt, ...)
|
void logit(int prio, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
static int _slup = 0;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
if (!_slup && !fexist("/dev/log")) {
|
if (!_slup && !fexist("/dev/log")) {
|
||||||
|
|||||||
@@ -24,24 +24,21 @@
|
|||||||
#ifndef FINIT_LOG_H_
|
#ifndef FINIT_LOG_H_
|
||||||
#define FINIT_LOG_H_
|
#define FINIT_LOG_H_
|
||||||
|
|
||||||
#include <err.h>
|
|
||||||
#include <string.h> /* strerror() */
|
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Error and debug messages
|
* Developer error and debug messages, otherwise --> use logit() <--
|
||||||
|
* ~~~~~~~~~~~
|
||||||
|
* All of these prepend the function, so only use for critical warnings
|
||||||
|
* errors and debug messages. For all other user messages, see logit()
|
||||||
*
|
*
|
||||||
* Use of logit() is preferred, but these are guaranteed to display on
|
* The default log level is LOG_NOTICE. To toggle LOG_DEBUG messages,
|
||||||
* /dev/console as well. Useful for critical errors and early debug.
|
* use `initctl debug` or add `--debug` to the kernel cmdline.
|
||||||
*/
|
*/
|
||||||
#define _l(prio, fmt, args...) do { if (_slup) warnx(fmt, ##args); logit(prio, fmt "\n", ##args); } while (0)
|
#define _d(fmt, args...) logit(LOG_DEBUG, "%s():" fmt, __func__, ##args)
|
||||||
#define _m(prio, fmt, args...) do { _l(prio, "%s() - " fmt, __func__, ##args); } while (0)
|
#define _w(fmt, args...) logit(LOG_WARNING, "%s():" fmt, __func__, ##args)
|
||||||
#define _d(fmt, args...) do { if (debug) { _m(LOG_DEBUG, fmt, ##args); } } while (0)
|
#define _e(fmt, args...) logit(LOG_ERR, "%s():" fmt, __func__, ##args)
|
||||||
#define _w(fmt, args...) do { _m(LOG_WARNING, fmt, ##args); } while (0)
|
#define _pe(fmt, args...) logit(LOG_ERR, "%s():" fmt ": %m", __func__, ##args)
|
||||||
#define _e(fmt, args...) do { _m(LOG_ERR, fmt, ##args); } while (0)
|
|
||||||
#define _pe(fmt, args...) do { _m(LOG_ERR, fmt ". Error %d: %s", ##args, errno, strerror(errno)); } while (0)
|
|
||||||
|
|
||||||
extern int _slup; /* INTERNAL: Is syslog up yet? */
|
|
||||||
|
|
||||||
void log_toggle_debug(void);
|
void log_toggle_debug(void);
|
||||||
void logit (int prio, const char *fmt, ...);
|
void logit (int prio, const char *fmt, ...);
|
||||||
|
|||||||
Reference in new issue
Block a user