"Fossies" - the Fresh Open Source Software Archive

Member "storlets-7.0.0/storlets/agent/common/utils.py" (14 Apr 2021, 1901 Bytes) of package /linux/misc/openstack/storlets-7.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "utils.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 6.0.0_vs_7.0.0.

    1 # Copyright (c) 2015-2016 OpenStack 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
   12 # implied.
   13 # See the License for the specific language governing permissions and
   14 # limitations under the License.
   15 import logging
   16 from logging.handlers import SysLogHandler
   17 
   18 # TODO(takashi): Make the following parameters configurable
   19 DEFAULT_PY2 = 2.7
   20 DEFAULT_PY3 = 3.8
   21 
   22 
   23 def get_logger(logger_name, log_level, container_id):
   24     """
   25     Initialize logging of this process and set logger format
   26 
   27     :param logger_name: The name to report with
   28     :param log_level: The verbosity level. This should be selected
   29     :param container_id: container id
   30     """
   31     log_level = log_level.upper()
   32 
   33     # NOTE(takashi): currently logging.WARNING is defined as the same value
   34     #                as logging.WARN, so we can properly handle WARNING here
   35     try:
   36         level = getattr(logging, log_level)
   37     except AttributeError:
   38         level = logging.ERROR
   39 
   40     logger = logging.getLogger("CONT #" + container_id + ": " + logger_name)
   41 
   42     if log_level == 'OFF':
   43         logging.disable(logging.CRITICAL)
   44     else:
   45         logger.setLevel(level)
   46 
   47     log_handler = SysLogHandler('/dev/log')
   48     str_format = '%(name)-12s: %(levelname)-8s %(funcName)s' + \
   49                  ' %(lineno)s [%(process)d, %(threadName)s]' + \
   50                  ' %(message)s'
   51     formatter = logging.Formatter(str_format)
   52     log_handler.setFormatter(formatter)
   53     log_handler.setLevel(level)
   54     logger.addHandler(log_handler)
   55     return logger