vswitchperf: Update merge and verify jobs
[releng.git] / utils / installer-adapter / RelengLogger.py
1 #!/usr/bin/env python
2 #
3 # jose.lausuch@ericsson.com
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Logging levels:
10 #  Level     Numeric value
11 #  CRITICAL  50
12 #  ERROR     40
13 #  WARNING   30
14 #  INFO      20
15 #  DEBUG     10
16 #  NOTSET    0
17 #
18 # Usage:
19 #  import RelengLogger as rl
20 #  logger = fl.Logger("script_name").getLogger()
21 #  logger.info("message to be shown with - INFO - ")
22 #  logger.debug("message to be shown with - DEBUG -")
23
24 import logging
25 import os
26
27
28 class Logger:
29
30     def __init__(self, logger_name, level="INFO"):
31
32         self.logger = logging.getLogger(logger_name)
33         self.logger.propagate = 0
34         self.logger.setLevel(logging.DEBUG)
35
36         ch = logging.StreamHandler()
37         formatter = logging.Formatter('%(asctime)s - %(name)s - '
38                                       '%(levelname)s - %(message)s')
39         ch.setFormatter(formatter)
40         if level.lower() == "debug":
41             ch.setLevel(logging.DEBUG)
42         else:
43             ch.setLevel(logging.INFO)
44         self.logger.addHandler(ch)
45
46         hdlr = logging.FileHandler('/tmp/releng.log')
47         hdlr.setFormatter(formatter)
48         hdlr.setLevel(logging.DEBUG)
49         self.logger.addHandler(hdlr)
50
51     def getLogger(self):
52         return self.logger