aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/utils/log.h
blob: 11b4897ac2034fc92a2085252ba75b70e5fd4e0e (plain)
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
#ifndef __LOG_H__ELPER_H__
#define __LOG_H__ELPER_H__

#include <string> 
#include <iostream>
#include <fstream>
#include <stdarg.h>

#include "../core/configuration.h"

class Loghelper
{
public:
    // logĿ
    enum Direction
    {
        DIR_CERR = 1 << 1, // ׼
        DIR_FILE = 1 << 2, // logļ
    };

    // ȼ
    enum Level
    {
        LV_NONE = 0,  // none   
        LV_ERROR = 1 << 1,  // error 
        LV_WARNING = 1 << 2,  // warn 
        LV_INFO = 1 << 3,  // info 
        LV_DEBUG = 1 << 4, // debug 
        LV_ALL = 0xffffffff
    };

    static void log(Level _level, const char* _fmt, ...);

    // ض
    static void redirect(unsigned int _dir, char* _path = nullptr);

    // ɸѡȼ
    static void restrict(unsigned int levels);

    static void close();

private:
    static unsigned int dir;    // Ŀ
    static unsigned int levels; // ȼ
    static std::ofstream fs;    // ļ 
};

typedef Loghelper::Level Loglevel;

#if defined(jin_debug)
    #define jin_log_error(f, ...) Loghelper::log(Loghelper::LV_ERROR, f, __VA_ARGS__)
    #define jin_log_info(f, ...) Loghelper::log(Loghelper::LV_INFO, f, __VA_ARGS__)
    #define jin_log_warning(f, ...) Loghelper::log(Loghelper::LV_WARNING, f, __VA_ARGS__)
    #define jin_log_debug(f, ...) Loghelper::log(Loghelper::LV_DEBUG, f, __VA_ARGS__)
#else 
    #define jin_log_error(f, ...) 
    #define jin_log_info(f, ...) 
    #define jin_log_warning(f, ...)
    #define jin_log_debug(f, ...) 
#endif 

#endif // __LOG_H__ELPER_H__