log日志实现

实例

file.h

#ifndef _FILE_H
#define _FILE_H

#include <stdio.h>
#include <stdlib.h>

#define LOG_LEVEL_FATAL  0
#define LOG_LEVEL_ERROR  1
#define LOG_LEVEL_WARN  2
#define LOG_LEVEL_INFO  3
#define LOG_LEVEL_DEBUG  4
#define LOG_LEVEL_MAX   5

#define self_dbg printf
#define self_err printf
#define self_warn printf
#define self_info printf

typedef enum {
​    LOG_OFF = 0,
​    LOG_ON
} LOG_SWITCH;

struct log_config{
​    unsigned int global_log_level;
​    unsigned int log_buf_size;
​    LOG_SWITCH logfile_log_to_file_switch;
​    char logfile_log_files_dir[256];
​    unsigned int logfile_nr_rolling_files;
​    unsigned long long logfile_max_file_size;
​    unsigned int logfile_flush_to_disk_period;
};

struct log_config* get_log_configs(void);
static int get_exec_name(char *name);
static int log_files_dir_init(char* dir);
LOG_SWITCH get_log_file_switch_status(void);
void output_log_to_file(char *log, un
上一篇:Redhat6更改yum源 (转)


下一篇:常用的日志配置代码