__init__.py revision 2828
45312f52ff3a3d4c137447be4c7556500c2f8bf2Timo Sirainen#!/usr/bin/python
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen# CDDL HEADER START
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen# The contents of this file are subject to the terms of the
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen# Common Development and Distribution License (the "License").
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen# You may not use this file except in compliance with the License.
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen# or http://www.opensolaris.org/os/licensing.
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen# See the License for the specific language governing permissions
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen# and limitations under the License.
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen# When distributing Covered Code, include this CDDL HEADER in each
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen# If applicable, add the following below this CDDL HEADER, with the
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen# fields enclosed by brackets "[]" replaced with your own identifying
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen# information: Portions Copyright [yyyy] [name of copyright owner]
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen#
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen# CDDL HEADER END
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen#
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen#
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen# Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen#
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen# Missing docstring; pylint: disable=C0111
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainenimport logging
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainenimport os
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainenimport sys
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen__all__ = ["global_settings"]
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainenclass _LogFilter(logging.Filter):
16f816d3f3c32ae3351834253f52ddd0212bcbf3Timo Sirainen def __init__(self, max_level=logging.CRITICAL):
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen logging.Filter.__init__(self)
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen self.max_level = max_level
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen def filter(self, record):
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen return record.levelno <= self.max_level
84e1634acc701d14e358e27f1beff5ad74f5004aTimo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainenclass _StreamHandler(logging.StreamHandler):
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen """Simple subclass to ignore exceptions raised during logging output."""
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen
022412398e56a8f31ef111cfd7271498d64af9a9Timo Sirainen def handleError(self, record):
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen # Ignore exceptions raised during output to stdout/stderr.
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen return
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenclass GlobalSettings(object):
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainen """ This class defines settings which are global
7a6b45405fb1544ac476e6eb1402a70cc1ddcdcfTimo Sirainen to the client instance """
e05ea8311ae16687295048e88ca205dfe29fbcbfTimo Sirainen
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen def __init__(self):
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen object.__init__(self)
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen self.__info_log_handler = None
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen self.__error_log_handler = None
f7d43647acc6dc80064c8c4cacf5bf86f754c530Timo Sirainen self.__verbose = False
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen #
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen # These properties allow the client to describe how it
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen # has been asked to behave with respect to output. This
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen # allows subprocess invocations (e.g. for linked images) to
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen # discover from the global settings how they are expected
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen # to behave.
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen #
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen self.client_output_verbose = 0
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen self.client_output_quiet = False
b6d817f0effeff645aadc01fd468a7d4084ba1f2Timo Sirainen self.client_output_parsable_version = None
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen # runid, used by the pkg.1 client and the linked image
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen # subsystem when when generating temporary files.
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen self.client_runid = os.getpid()
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen # file descriptor used by ProgressTracker classes when running
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen # "pkg remote" to indicate progress back to the parent/client
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen # process.
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen self.client_output_progfd = None
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen # concurrency value used for linked image recursion
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen self.client_concurrency_default = 1
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen self.client_concurrency = self.client_concurrency_default
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen try:
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen self.client_concurrency = int(os.environ.get(
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen "PKG_CONCURRENCY",
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen self.client_concurrency_default))
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen # remove PKG_CONCURRENCY from the environment so child
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen # processes don't inherit it.
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen os.environ.pop("PKG_CONCURRENCY", None)
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen except ValueError:
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen pass
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen self.client_name = None
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen self.client_args = sys.argv[:]
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen # Default maximum number of redirects received before
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen # aborting a connection.
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen self.pkg_client_max_redirect_default = 5
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen # Default number of retries per-host
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen self.pkg_client_max_timeout_default = 4
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen # Default number of seconds to give up if not connected
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen self.pkg_client_connect_timeout_default = 60
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen # Default number of seconds beneath low-speed limit before
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen # giving up.
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen self.pkg_client_lowspeed_timeout_default = 30
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen # Minimum bytes/sec before client thinks about giving up
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen # on connection.
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen self.pkg_client_lowspeed_limit = 1024
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen # Maximum number of transient errors before we abort an
6288d3611eda14a017dae9927b73f46afb646c96Timo Sirainen # endpoint.
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen self.pkg_client_max_consecutive_error_default = 4
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen # The location within the image of the cache for pkg.sysrepo(1M)
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen self.sysrepo_pub_cache_path = \
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen "var/cache/pkg/sysrepo_pub_cache.dat"
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen try:
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen # Maximum number of timeouts before client gives up.
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen self.PKG_CLIENT_MAX_TIMEOUT = int(os.environ.get(
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen "PKG_CLIENT_MAX_TIMEOUT",
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen self.pkg_client_max_timeout_default))
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen except ValueError:
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen self.PKG_CLIENT_MAX_TIMEOUT = \
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen self.pkg_client_max_timeout_default
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen try:
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen # Number of seconds trying to connect before client
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen # aborts.
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen self.PKG_CLIENT_CONNECT_TIMEOUT = int(os.environ.get(
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen "PKG_CLIENT_CONNECT_TIMEOUT",
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen self.pkg_client_connect_timeout_default))
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen except ValueError:
9e59a1f3f095b3099478562cf3f3970a24736970Timo Sirainen self.PKG_CLIENT_CONNECT_TIMEOUT = \
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen self.pkg_client_connect_timeout_default
178511b57faa7c3f8203dd8b7e4059d00cbfc23aTimo Sirainen try:
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen # Number of seconds below lowspeed limit before
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen # transaction is aborted.
2e937ed8585299b2e879a28314902a5f644813d2Timo Sirainen self.PKG_CLIENT_LOWSPEED_TIMEOUT = int(os.environ.get(
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen "PKG_CLIENT_LOWSPEED_TIMEOUT",
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen self.pkg_client_lowspeed_timeout_default))
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen except ValueError:
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen self.PKG_CLIENT_LOWSPEED_TIMEOUT = \
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen self.pkg_client_lowspeed_timeout_default
4d25408732be27e91f0430f71e87242760c2517cTimo Sirainen try:
e68309fcfa2eaa88217fd51e7b4900fc9c20ef5dTimo Sirainen # Number of transient errors before transaction
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen # is aborted.
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen self.PKG_CLIENT_MAX_CONSECUTIVE_ERROR = int(
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen os.environ.get("PKG_CLIENT_MAX_CONSECUTIVE_ERROR",
e5c08648676d1989f6e70b95e5990c26b3e8b96bTimo Sirainen self.pkg_client_max_consecutive_error_default))
4d25408732be27e91f0430f71e87242760c2517cTimo Sirainen except ValueError:
c3412ddeb9abc13f99d3caf50faf76cd99f7e9d2Timo Sirainen self.PKG_CLIENT_MAX_CONSECUTIVE_ERROR = \
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen self.pkg_client_max_consecutive_error_default
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen try:
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen # Number of redirects before a connection is
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen # aborted.
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen self.PKG_CLIENT_MAX_REDIRECT = int(
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen os.environ.get("PKG_CLIENT_MAX_REDIRECT",
1e76a5b92f9d82d557f81f080f3dfad1c9d8f200Timo Sirainen self.pkg_client_max_redirect_default))
1e76a5b92f9d82d557f81f080f3dfad1c9d8f200Timo Sirainen except ValueError:
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen self.PKG_CLIENT_MAX_REDIRECT = \
9a06cabdfdf4d5e2f19a07e506c3c7d08a7e7038Timo Sirainen self.pkg_client_max_redirect_default
9a06cabdfdf4d5e2f19a07e506c3c7d08a7e7038Timo Sirainen self.reset_logging()
9a06cabdfdf4d5e2f19a07e506c3c7d08a7e7038Timo Sirainen
e8a35266a5ceacdfafeeffd6bddae77931ff97ebTimo Sirainen def __get_error_log_handler(self):
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen return self.__error_log_handler
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen def __get_info_log_handler(self):
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen return self.__info_log_handler
b08b33d1f5ce3721dc2d83586c9cb0ca141331fdTimo Sirainen
b08b33d1f5ce3721dc2d83586c9cb0ca141331fdTimo Sirainen def __get_verbose(self):
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen return self.__verbose
f6699a08521aacc4c2bb5b6175691dad5f715f8cTimo Sirainen
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen def __set_error_log_handler(self, val):
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen logger = logging.getLogger("pkg")
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen if self.__error_log_handler:
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen logger.removeHandler(self.__error_log_handler)
b08b33d1f5ce3721dc2d83586c9cb0ca141331fdTimo Sirainen self.__error_log_handler = val
42456ec33fe65feb411890f99d436071e0185ee3Timo Sirainen if val:
022412398e56a8f31ef111cfd7271498d64af9a9Timo Sirainen logger.addHandler(val)
022412398e56a8f31ef111cfd7271498d64af9a9Timo Sirainen
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen def __set_info_log_handler(self, val):
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen logger = logging.getLogger("pkg")
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen if self.__info_log_handler:
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen logger.removeHandler(self.__info_log_handler)
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen self.__info_log_handler = val
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen if val:
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen logger.addHandler(val)
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen def __set_verbose(self, val):
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen if self.__info_log_handler:
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen if val:
f6699a08521aacc4c2bb5b6175691dad5f715f8cTimo Sirainen level = logging.DEBUG
f6699a08521aacc4c2bb5b6175691dad5f715f8cTimo Sirainen else:
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen level = logging.INFO
f6699a08521aacc4c2bb5b6175691dad5f715f8cTimo Sirainen self.__info_log_handler.setLevel(level)
f6699a08521aacc4c2bb5b6175691dad5f715f8cTimo Sirainen self.__verbose = val
df4018ae2f0a95be602f724ca70df7e0e3bd6a7dTimo Sirainen
df4018ae2f0a95be602f724ca70df7e0e3bd6a7dTimo Sirainen @property
a393d9d6dabdc46cf724f8cb004a652b4036d53dTimo Sirainen def logger(self):
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen # Method could be a function; pylint: disable=R0201
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen return logging.getLogger("pkg")
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen def reset_logging(self):
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen """Resets client logging to its default state. This will cause
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen all logging.INFO entries to go to sys.stdout, and all entries of
a393d9d6dabdc46cf724f8cb004a652b4036d53dTimo Sirainen logging.WARNING or higher to go to sys.stderr."""
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen logger = logging.getLogger("pkg")
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen logger.setLevel(logging.DEBUG)
2bf7bb14894faf721518e2122a14a2389ef94078Timo Sirainen
9a06cabdfdf4d5e2f19a07e506c3c7d08a7e7038Timo Sirainen # Don't pass messages that are rejected to the root logger.
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen logger.propagate = 0
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen
2bf7bb14894faf721518e2122a14a2389ef94078Timo Sirainen # By default, log all informational messages, but not warnings
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen # and above to stdout.
2bf7bb14894faf721518e2122a14a2389ef94078Timo Sirainen info_h = _StreamHandler(sys.stdout)
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen
9a06cabdfdf4d5e2f19a07e506c3c7d08a7e7038Timo Sirainen # Minimum logging level for informational messages.
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen if self.verbose:
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen info_h.setLevel(logging.DEBUG)
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen else:
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen info_h.setLevel(logging.INFO)
2bf7bb14894faf721518e2122a14a2389ef94078Timo Sirainen
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen log_fmt = logging.Formatter()
9a06cabdfdf4d5e2f19a07e506c3c7d08a7e7038Timo Sirainen
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen # Enforce maximum logging level for informational messages.
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen info_f = _LogFilter(logging.INFO)
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen info_h.addFilter(info_f)
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen info_h.setFormatter(log_fmt)
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen logger.addHandler(info_h)
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen # By default, log all warnings and above to stderr.
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen error_h = _StreamHandler(sys.stderr)
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen error_h.setFormatter(log_fmt)
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen error_h.setLevel(logging.WARNING)
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainen logger.addHandler(error_h)
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainen
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainen # Stash the handles so they can be removed later.
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainen self.info_log_handler = info_h
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainen self.error_log_handler = error_h
f6699a08521aacc4c2bb5b6175691dad5f715f8cTimo Sirainen
f6699a08521aacc4c2bb5b6175691dad5f715f8cTimo Sirainen error_log_handler = property(__get_error_log_handler,
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen __set_error_log_handler)
f6699a08521aacc4c2bb5b6175691dad5f715f8cTimo Sirainen
f6699a08521aacc4c2bb5b6175691dad5f715f8cTimo Sirainen info_log_handler = property(__get_info_log_handler,
df4018ae2f0a95be602f724ca70df7e0e3bd6a7dTimo Sirainen __set_info_log_handler)
df4018ae2f0a95be602f724ca70df7e0e3bd6a7dTimo Sirainen
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainen verbose = property(__get_verbose, __set_verbose)
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainenglobal_settings = GlobalSettings()
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen