Commit 764b8674 authored by Pavel Emelyanov's avatar Pavel Emelyanov

log: Swap contents of criu-log and log headers

The former one (criu-log.h) is now for service functions like logfile
management, pidfile and alike. It's only needed by files that set up
logging and for users that want specific functions like log_get_fd or
pr_quelled.

The latter (log.h) is purely for those who need pr_xxx helpers only.
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent 58ee7c63
......@@ -13,6 +13,7 @@
#include "cgroup-props.h"
#include "cr_options.h"
#include "pstree.h"
#include "criu-log.h"
#include "util.h"
#include "imgset.h"
#include "util-pie.h"
......
......@@ -32,7 +32,7 @@
#include "image.h"
#include "util.h"
#include "util-pie.h"
#include "log.h"
#include "criu-log.h"
#include "restorer.h"
#include "sockets.h"
#include "sk-packet.h"
......
......@@ -19,7 +19,7 @@
#include "cr_options.h"
#include "external.h"
#include "util.h"
#include "log.h"
#include "criu-log.h"
#include "cpu.h"
#include "files.h"
#include "pstree.h"
......
......@@ -36,6 +36,7 @@
#include "file-lock.h"
#include "cr-service.h"
#include "plugin.h"
#include "criu-log.h"
#include "mount.h"
#include "filesystems.h"
#include "namespaces.h"
......
......@@ -33,7 +33,7 @@
#include "files.h"
#include "files-reg.h"
#include "file-ids.h"
#include "log.h"
#include "criu-log.h"
#include "common/list.h"
#include "lock.h"
#include "irmap.h"
......
......@@ -20,71 +20,27 @@
#ifndef __CRIU_LOG_H__
#define __CRIU_LOG_H__
#ifndef CR_NOGLIBC
#include "log.h"
#include <string.h>
#include <errno.h>
extern int log_init(const char *output);
extern void log_fini(void);
extern int log_init_by_pid(void);
extern void log_closedir(void);
extern int log_keep_err(void);
extern char *log_first_err(void);
#endif /* CR_NOGLIBC */
extern void log_set_fd(int fd);
extern int log_get_fd(void);
#define LOG_UNSET (-1)
#define LOG_MSG (0) /* Print message regardless of log level */
#define LOG_ERROR (1) /* Errors only, when we're in trouble */
#define LOG_WARN (2) /* Warnings, dazen and confused but trying to continue */
#define LOG_INFO (3) /* Informative, everything is fine */
#define LOG_DEBUG (4) /* Debug only */
extern void log_set_loglevel(unsigned int loglevel);
extern unsigned int log_get_loglevel(void);
#define DEFAULT_LOGLEVEL LOG_WARN
extern int write_pidfile(int pid);
extern void print_on_level(unsigned int loglevel, const char *format, ...)
__attribute__ ((__format__ (__printf__, 2, 3)));
#ifndef LOG_PREFIX
# define LOG_PREFIX
#endif
#define print_once(loglevel, fmt, ...) \
do { \
static bool __printed; \
if (!__printed) { \
print_on_level(loglevel, fmt, ##__VA_ARGS__); \
__printed = 1; \
} \
} while (0)
#define pr_msg(fmt, ...) \
print_on_level(LOG_MSG, \
fmt, ##__VA_ARGS__)
#define pr_info(fmt, ...) \
print_on_level(LOG_INFO, \
LOG_PREFIX fmt, ##__VA_ARGS__)
#define pr_err(fmt, ...) \
print_on_level(LOG_ERROR, \
"Error (%s:%d): " LOG_PREFIX fmt, \
__FILE__, __LINE__, ##__VA_ARGS__)
#define pr_err_once(fmt, ...) \
print_once(LOG_ERROR, fmt, ##__VA_ARGS__)
#define pr_warn(fmt, ...) \
print_on_level(LOG_WARN, \
"Warn (%s:%d): " LOG_PREFIX fmt, \
__FILE__, __LINE__, ##__VA_ARGS__)
#define pr_warn_once(fmt, ...) \
print_once(LOG_WARN, fmt, ##__VA_ARGS__)
#define pr_debug(fmt, ...) \
print_on_level(LOG_DEBUG, \
LOG_PREFIX fmt, ##__VA_ARGS__)
#ifndef CR_NOGLIBC
#define pr_perror(fmt, ...) \
pr_err(fmt ": %s\n", ##__VA_ARGS__, strerror(errno))
#endif /* CR_NOGLIBC */
#define DEFAULT_LOG_FILENAME "criu.log"
static inline int pr_quelled(unsigned int loglevel)
{
return log_get_loglevel() < loglevel && loglevel != LOG_MSG;
}
#endif /* __CR_LOG_LEVELS_H__ */
......@@ -3,20 +3,72 @@
#include <inttypes.h>
#include "criu-log.h"
#ifndef CR_NOGLIBC
extern int log_init(const char *output);
extern void log_fini(void);
extern int log_init_by_pid(void);
extern void log_closedir(void);
extern int log_keep_err(void);
extern char *log_first_err(void);
#include <string.h>
#include <errno.h>
extern void log_set_fd(int fd);
extern int log_get_fd(void);
#endif /* CR_NOGLIBC */
extern void log_set_loglevel(unsigned int loglevel);
extern unsigned int log_get_loglevel(void);
#define LOG_UNSET (-1)
#define LOG_MSG (0) /* Print message regardless of log level */
#define LOG_ERROR (1) /* Errors only, when we're in trouble */
#define LOG_WARN (2) /* Warnings, dazen and confused but trying to continue */
#define LOG_INFO (3) /* Informative, everything is fine */
#define LOG_DEBUG (4) /* Debug only */
#define DEFAULT_LOGLEVEL LOG_WARN
extern void print_on_level(unsigned int loglevel, const char *format, ...)
__attribute__ ((__format__ (__printf__, 2, 3)));
#ifndef LOG_PREFIX
# define LOG_PREFIX
#endif
#define print_once(loglevel, fmt, ...) \
do { \
static bool __printed; \
if (!__printed) { \
print_on_level(loglevel, fmt, ##__VA_ARGS__); \
__printed = 1; \
} \
} while (0)
#define pr_msg(fmt, ...) \
print_on_level(LOG_MSG, \
fmt, ##__VA_ARGS__)
#define pr_info(fmt, ...) \
print_on_level(LOG_INFO, \
LOG_PREFIX fmt, ##__VA_ARGS__)
#define pr_err(fmt, ...) \
print_on_level(LOG_ERROR, \
"Error (%s:%d): " LOG_PREFIX fmt, \
__FILE__, __LINE__, ##__VA_ARGS__)
#define pr_err_once(fmt, ...) \
print_once(LOG_ERROR, fmt, ##__VA_ARGS__)
#define pr_warn(fmt, ...) \
print_on_level(LOG_WARN, \
"Warn (%s:%d): " LOG_PREFIX fmt, \
__FILE__, __LINE__, ##__VA_ARGS__)
#define pr_warn_once(fmt, ...) \
print_once(LOG_WARN, fmt, ##__VA_ARGS__)
#define pr_debug(fmt, ...) \
print_on_level(LOG_DEBUG, \
LOG_PREFIX fmt, ##__VA_ARGS__)
#ifndef CR_NOGLIBC
#define pr_perror(fmt, ...) \
pr_err(fmt ": %s\n", ##__VA_ARGS__, strerror(errno))
#else
#define LOG_SIMPLE_CHUNK 72
......@@ -24,13 +76,7 @@ extern int vprint_num(char *buf, int blen, int num, char **ps);
extern void simple_sprintf(char output[LOG_SIMPLE_CHUNK], const char *format, ...)
__attribute__ ((__format__ (__printf__, 2, 3)));
extern int write_pidfile(int pid);
#define DEFAULT_LOG_FILENAME "criu.log"
#endif /* CR_NOGLIBC */
static inline int pr_quelled(unsigned int loglevel)
{
return log_get_loglevel() < loglevel && loglevel != LOG_MSG;
}
#endif /* __CR_LOG_H__ */
......@@ -7,6 +7,7 @@
#include "page.h"
#include "config.h"
#include "util.h"
#include "criu-log.h"
#include "page-pipe.h"
/* can existing iov accumulate the page? */
......
......@@ -25,6 +25,7 @@
#include "pstree.h"
#include "posix-timer.h"
#include "mem.h"
#include "criu-log.h"
#include "vma.h"
#include "proc_parse.h"
#include "aio.h"
......
......@@ -15,7 +15,7 @@
#include "prctl.h"
#include "lock.h"
#include "parasite-vdso.h"
#include "log.h"
#include "criu-log.h"
#include "tty.h"
#include "aio.h"
......
......@@ -23,7 +23,7 @@
#include "signal.h"
#include "config.h"
#include "prctl.h"
#include "log.h"
#include "criu-log.h"
#include "util.h"
#include "image.h"
#include "sk-inet.h"
......
......@@ -14,6 +14,7 @@
#include "cr_options.h"
#include "cr-errno.h"
#include "pstree.h"
#include "criu-log.h"
#include "ptrace.h"
#include "seize.h"
#include "stats.h"
......
......@@ -45,7 +45,7 @@
#include "vma.h"
#include "mem.h"
#include "namespaces.h"
#include "log.h"
#include "criu-log.h"
#include "cr_options.h"
#include "servicefd.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment