Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -0700 | [diff] [blame] | 1 | # 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 Baker | 7dddd51 | 2017-10-24 10:13:34 -0700 | [diff] [blame] | 15 | from .config import Config |
Zack Williams | 2d715ec | 2018-08-28 12:21:18 -0700 | [diff] [blame] | 16 | |
| 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 | |
| 20 | import logging |
| 21 | |
| 22 | # Logging levels: https://docs.python.org/2/library/logging.html#logging-levels |
| 23 | # Add a sub-DEBUG Trace level |
| 24 | TRACE_LOGLVL = 5 |
| 25 | |
| 26 | logging.addLevelName(TRACE_LOGLVL, "TRACE") |
| 27 | |
| 28 | |
| 29 | def trace_loglevel(self, message, *args, **kws): |
| 30 | if self.isEnabledFor(TRACE_LOGLVL): |
| 31 | self._log(TRACE_LOGLVL, message, args, **kws) |
| 32 | |
| 33 | |
| 34 | logging.Logger.trace = trace_loglevel |