2011-04-10 18:17:06 +02:00
|
|
|
# This file is part of Radicale Server - Calendar Server
|
2017-05-27 17:28:07 +02:00
|
|
|
# Copyright © 2011-2017 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 logging
|
2016-07-04 14:32:33 +02:00
|
|
|
import sys
|
2018-08-16 07:59:55 +02:00
|
|
|
import threading
|
2011-04-10 18:17:06 +02:00
|
|
|
|
|
|
|
|
2018-08-16 07:59:55 +02:00
|
|
|
LOGGER_NAME = "radicale"
|
|
|
|
LOGGER_FORMAT = "[%(processName)s/%(threadName)s] %(levelname)s: %(message)s"
|
|
|
|
|
|
|
|
root_logger = logging.getLogger()
|
|
|
|
logger = logging.getLogger(LOGGER_NAME)
|
2014-07-28 12:07:55 -07:00
|
|
|
|
|
|
|
|
2017-05-31 11:08:32 +02:00
|
|
|
class RemoveTracebackFilter(logging.Filter):
|
|
|
|
def filter(self, record):
|
|
|
|
record.exc_info = None
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2018-08-16 07:59:55 +02:00
|
|
|
removeTracebackFilter = RemoveTracebackFilter()
|
|
|
|
|
|
|
|
|
|
|
|
def get_default_handler():
|
|
|
|
handler = logging.StreamHandler(sys.stderr)
|
|
|
|
return handler
|
|
|
|
|
|
|
|
|
|
|
|
def setup():
|
|
|
|
"""Set global logging up."""
|
|
|
|
global register_stream, unregister_stream
|
|
|
|
handler = get_default_handler()
|
|
|
|
logging.basicConfig(format=LOGGER_FORMAT, handlers=[handler])
|
|
|
|
set_debug(True)
|
|
|
|
|
|
|
|
|
|
|
|
def set_debug(debug):
|
|
|
|
"""Set debug mode for global logger."""
|
2017-06-02 12:43:03 +02:00
|
|
|
if debug:
|
2018-08-16 07:59:55 +02:00
|
|
|
root_logger.setLevel(logging.DEBUG)
|
2017-06-02 12:43:03 +02:00
|
|
|
logger.setLevel(logging.DEBUG)
|
2018-08-16 07:59:55 +02:00
|
|
|
logger.removeFilter(removeTracebackFilter)
|
2017-06-02 12:43:03 +02:00
|
|
|
else:
|
2018-08-16 07:59:55 +02:00
|
|
|
root_logger.setLevel(logging.WARNING)
|
|
|
|
logger.setLevel(logging.WARNING)
|
|
|
|
logger.addFilter(removeTracebackFilter)
|