2011-04-10 18:17:06 +02:00
|
|
|
# This file is part of Radicale Server - Calendar Server
|
2016-03-31 19:57:40 +02:00
|
|
|
# Copyright © 2011-2016 Guillaume Ayoub
|
2011-04-10 18:17:06 +02:00
|
|
|
#
|
|
|
|
# This library is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Radicale. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
"""
|
|
|
|
Radicale logging module.
|
|
|
|
|
|
|
|
Manage logging from a configuration file. For more information, see:
|
|
|
|
http://docs.python.org/library/logging.config.html
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import logging
|
|
|
|
import logging.config
|
2014-07-28 12:07:55 -07:00
|
|
|
import signal
|
2011-04-10 18:17:06 +02:00
|
|
|
|
2012-08-09 17:31:36 +02:00
|
|
|
from . import config
|
2011-04-10 18:17:06 +02:00
|
|
|
|
|
|
|
|
2011-05-07 12:52:54 +02:00
|
|
|
LOGGER = logging.getLogger()
|
2011-07-26 09:02:21 +02:00
|
|
|
|
2013-07-12 15:12:07 +02:00
|
|
|
|
2014-07-28 12:07:55 -07:00
|
|
|
def configure_from_file(filename, debug):
|
|
|
|
logging.config.fileConfig(filename)
|
|
|
|
if debug:
|
|
|
|
LOGGER.setLevel(logging.DEBUG)
|
|
|
|
for handler in LOGGER.handlers:
|
|
|
|
handler.setLevel(logging.DEBUG)
|
|
|
|
|
|
|
|
|
2011-05-09 16:43:41 +02:00
|
|
|
def start():
|
2013-07-12 15:25:57 +02:00
|
|
|
"""Start the logging according to the configuration."""
|
2013-07-07 15:07:21 +02:00
|
|
|
filename = os.path.expanduser(config.get("logging", "config"))
|
2013-07-07 15:48:14 +02:00
|
|
|
debug = config.getboolean("logging", "debug")
|
2013-07-07 15:07:21 +02:00
|
|
|
|
|
|
|
if os.path.exists(filename):
|
2011-04-10 18:17:06 +02:00
|
|
|
# Configuration taken from file
|
2014-07-28 12:07:55 -07:00
|
|
|
configure_from_file(filename, debug)
|
2014-11-03 11:21:12 +01:00
|
|
|
# Reload config on SIGHUP (UNIX only)
|
|
|
|
if hasattr(signal, 'SIGHUP'):
|
|
|
|
def handler(signum, frame):
|
|
|
|
configure_from_file(filename, debug)
|
|
|
|
signal.signal(signal.SIGHUP, handler)
|
2011-04-10 18:17:06 +02:00
|
|
|
else:
|
|
|
|
# Default configuration, standard output
|
|
|
|
handler = logging.StreamHandler(sys.stdout)
|
2011-05-07 12:52:54 +02:00
|
|
|
handler.setFormatter(logging.Formatter("%(message)s"))
|
2011-04-10 18:17:06 +02:00
|
|
|
LOGGER.addHandler(handler)
|
2013-07-07 15:48:14 +02:00
|
|
|
if debug:
|
|
|
|
LOGGER.setLevel(logging.DEBUG)
|
2013-07-12 15:12:07 +02:00
|
|
|
LOGGER.debug(
|
2013-08-27 15:19:15 +02:00
|
|
|
"Logging configuration file '%s' not found, using stdout." %
|
2013-07-12 17:45:09 +02:00
|
|
|
filename)
|