Mbed Host Tests
ht_logger.py
Go to the documentation of this file.
1#!/usr/bin/env python
2"""
3mbed SDK
4Copyright (c) 2011-2016 ARM Limited
5
6Licensed under the Apache License, Version 2.0 (the "License");
7you may not use this file except in compliance with the License.
8You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12Unless required by applicable law or agreed to in writing, software
13distributed under the License is distributed on an "AS IS" BASIS,
14WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15See the License for the specific language governing permissions and
16limitations under the License.
17"""
18
19
20import sys
21import logging
22from functools import partial
23
24
25class HtrunLogger(object):
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.logger = logging.getLogger(name)
30 self.format_str = '[%(logger_level)s] %(message)s'
31
32 def __prn_log(self, logger_level, text, timestamp=None):
33 self.logger.debug(self.format_str% {
34 'logger_level' : logger_level,
35 'message' : text,
36 })
37
38 self.prn_dbg = partial(__prn_log, self, 'DBG')
39 self.prn_wrn = partial(__prn_log, self, 'WRN')
40 self.prn_err = partial(__prn_log, self, 'ERR')
41 self.prn_inf = partial(__prn_log, self, 'INF')
42 self.prn_txt = partial(__prn_log, self, 'TXT')
43 self.prn_txd = partial(__prn_log, self, 'TXD')
44 self.prn_rxd = partial(__prn_log, self, 'RXD')