Blame view

src/device_controller/logs_nomoreused.py 2.16 KB
ac0e5c70   Etienne Pallier   nouveau devices_c...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env python3

"""LOGGER

"""


# Standard library imports
import logging

# Third party imports
# None

# Local application imports
# None




logger = None
# Aliases for logger:
57621753   Etienne Pallier   NOUVELLE ARCHI un...
22
23
24
25
26
27
#def log_d(msg:str): logger.debug(msg)
def log_d(msg:str, *args, **kwargs): logger.debug(msg, *args, **kwargs)
def log_i(msg:str, *args, **kwargs): logger.info(msg, *args, **kwargs)
def log_w(msg:str, *args, **kwargs): logger.warning(msg, *args, **kwargs)
def log_e(msg:str, *args, **kwargs): logger.error(msg, *args, **kwargs)
def log_c(msg:str, *args, **kwargs): logger.critical(msg, *args, **kwargs)
ac0e5c70   Etienne Pallier   nouveau devices_c...
28

ac0e5c70   Etienne Pallier   nouveau devices_c...
29
30

#def set_logger(self):
1cf4a67f   Etienne Pallier   Affichage console...
31
def set_logger(DEBUG_MODE:bool=False):
ac0e5c70   Etienne Pallier   nouveau devices_c...
32
33
34
35
36
37
38
39
40
41
42
43
    global logger
    '''
    # Logger configuration
    # Log all events, starting from DEBUG level
    '''
    
    # Basic configuration
    '''
    #logging.basicConfig(level=logging.DEBUG)
    logging.basicConfig(level=logging.DEBUG, filename='client.log', filemode='a', format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    logging.debug("Client instanciated")
    '''
1cf4a67f   Etienne Pallier   Affichage console...
44

ac0e5c70   Etienne Pallier   nouveau devices_c...
45
46
    # Advanced configuration
    logger = logging.getLogger(__name__)
1cf4a67f   Etienne Pallier   Affichage console...
47
48
49
    log_level = logging.DEBUG if DEBUG_MODE else logging.WARNING
    logger.setLevel(log_level)

ac0e5c70   Etienne Pallier   nouveau devices_c...
50
51
52
    # Create handlers for writing to console and file
    c_handler = logging.StreamHandler()
    f_handler = logging.FileHandler('client.log')
1cf4a67f   Etienne Pallier   Affichage console...
53

ac0e5c70   Etienne Pallier   nouveau devices_c...
54
55
    # Set level for each handler
    # DEBUG < INFO < WARNING < ERROR < CRITICAL
1cf4a67f   Etienne Pallier   Affichage console...
56
57
58
59
    c_handler.setLevel(logging.DEBUG)
    f_handler.setLevel(logging.WARNING)
    '''
    if DEBUG_MODE:
ac0e5c70   Etienne Pallier   nouveau devices_c...
60
61
62
63
64
        c_handler.setLevel(logging.DEBUG)
        f_handler.setLevel(logging.DEBUG)
    else:
        c_handler.setLevel(logging.INFO)
        f_handler.setLevel(logging.INFO)
1cf4a67f   Etienne Pallier   Affichage console...
65
66
    '''

ac0e5c70   Etienne Pallier   nouveau devices_c...
67
68
    # Set format for each handler
    #c_format = logging.Formatter('%(name)s - %(levelname)s - %(message)s')
57621753   Etienne Pallier   NOUVELLE ARCHI un...
69
    c_format = logging.Formatter('(%(name)s): %(message)s')
ac0e5c70   Etienne Pallier   nouveau devices_c...
70
71
72
73
74
75
76
77
78
79
80
    f_format = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    c_handler.setFormatter(c_format)
    f_handler.setFormatter(f_format)
    
    # Set handlers (for console and file)
    logger.addHandler(c_handler)
    logger.addHandler(f_handler)
    
    #return logger