forked from kernelci/kernelci-pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.py
48 lines (35 loc) · 1.25 KB
/
logger.py
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
#!/usr/bin/env python3
#
# SPDX-License-Identifier: LGPL-2.1-or-later
#
# Copyright (C) 2022 Collabora Limited
# Author: Jeny Sadadia <[email protected]>
"""Logger module"""
import logging
import logging.config
import traceback
class Logger:
"""Logging utility class
This class accepts name and path of the configuration file of the logger
in its contructor, by default `root` will be used as name of the logger
if not provided.
"""
def __init__(self, config_path, name='root'):
"""Returns logger object using configurations and logger name"""
logging.config.fileConfig(config_path)
self._logger = logging.getLogger(name)
def log_message(self, log_level, msg):
"""Creates a log record with provided log level and message"""
self._logger.log(log_level, msg)
def debug(self, msg):
self.log_message(logging.DEBUG, msg)
def info(self, msg):
self.log_message(logging.INFO, msg)
def warning(self, msg):
self.log_message(logging.WARNING, msg)
def error(self, msg):
self.log_message(logging.ERROR, msg)
def critical(self, msg):
self.log_message(logging.CRITICAL, msg)
def traceback(self):
self.error(traceback.format_exc())