/usr/lib/python3/dist-packages/oslo_log/handlers.py is in python3-oslo.log 3.16.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | # Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import inspect
import logging
import logging.config
import logging.handlers
import os
try:
import syslog
except ImportError:
syslog = None
from oslo_utils import encodeutils
NullHandler = logging.NullHandler
def _get_binary_name():
return os.path.basename(inspect.stack()[-1][1])
_AUDIT = logging.INFO + 1
_TRACE = 5
if syslog is not None:
class OSSysLogHandler(logging.Handler):
"""Syslog based handler. Only available on UNIX-like platforms."""
severity_map = {
"CRITICAL": syslog.LOG_CRIT,
"DEBUG": syslog.LOG_DEBUG,
"ERROR": syslog.LOG_ERR,
"INFO": syslog.LOG_INFO,
"WARNING": syslog.LOG_WARNING,
"WARN": syslog.LOG_WARNING,
}
def __init__(self, facility=syslog.LOG_USER):
# Do not use super() unless type(logging.Handler) is 'type'
# (i.e. >= Python 2.7).
logging.Handler.__init__(self)
binary_name = _get_binary_name()
syslog.openlog(binary_name, 0, facility)
def emit(self, record):
priority = self.severity_map.get(record.levelname,
syslog.LOG_DEBUG)
message = encodeutils.safe_encode(self.format(record))
syslog.syslog(priority, message)
class ColorHandler(logging.StreamHandler):
LEVEL_COLORS = {
_TRACE: '\033[00;35m', # MAGENTA
logging.DEBUG: '\033[00;32m', # GREEN
logging.INFO: '\033[00;36m', # CYAN
_AUDIT: '\033[01;36m', # BOLD CYAN
logging.WARN: '\033[01;33m', # BOLD YELLOW
logging.ERROR: '\033[01;31m', # BOLD RED
logging.CRITICAL: '\033[01;31m', # BOLD RED
}
def format(self, record):
record.color = self.LEVEL_COLORS[record.levelno]
return logging.StreamHandler.format(self, record)
|