Mbed Host Tests
ht_logger.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 """
3 mbed SDK
4 Copyright (c) 2011-2016 ARM Limited
5 
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 """
18 
19 
20 import sys
21 import logging
22 from functools import partial
23 
24 
26  """! Yet another logger flavour """
27  def __init__(self, name):
28  logging.basicConfig(stream=sys.stdout,format='[%(created).2f][%(name)s]%(message)s', level=logging.DEBUG)
29  self.loggerlogger = logging.getLogger(name)
30  self.format_strformat_str = '[%(logger_level)s] %(message)s'
31 
32  def __prn_log(self, logger_level, text, timestamp=None):
33  self.loggerlogger.debug(self.format_strformat_str% {
34  'logger_level' : logger_level,
35  'message' : text,
36  })
37 
38  self.prn_dbgprn_dbg = partial(__prn_log, self, 'DBG')
39  self.prn_wrnprn_wrn = partial(__prn_log, self, 'WRN')
40  self.prn_errprn_err = partial(__prn_log, self, 'ERR')
41  self.prn_infprn_inf = partial(__prn_log, self, 'INF')
42  self.prn_txtprn_txt = partial(__prn_log, self, 'TXT')
43  self.prn_txdprn_txd = partial(__prn_log, self, 'TXD')
44  self.prn_rxdprn_rxd = partial(__prn_log, self, 'RXD')