blob: a557ff45bcd6545eecb1ad37f8f3ffca6572a97f [file] [log] [blame]
Matteo Scandolod2044a42017-08-07 16:08:28 -07001# Copyright 2017-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Scott Baker7dddd512017-10-24 10:13:34 -070015from .config import Config
Zack Williams2d715ec2018-08-28 12:21:18 -070016
17# Custom TRACE logging level
18# ref: https://stackoverflow.com/questions/2183233/how-to-add-a-custom-loglevel-to-pythons-logging-facility/13638084#13638084
19
20import logging
21
22# Logging levels: https://docs.python.org/2/library/logging.html#logging-levels
23# Add a sub-DEBUG Trace level
24TRACE_LOGLVL = 5
25
26logging.addLevelName(TRACE_LOGLVL, "TRACE")
27
28
29def trace_loglevel(self, message, *args, **kws):
30 if self.isEnabledFor(TRACE_LOGLVL):
31 self._log(TRACE_LOGLVL, message, args, **kws)
32
33
34logging.Logger.trace = trace_loglevel