]> git.ipfire.org Git - location/debian/libloc.git/blame - src/python/location/logger.py
Update upstream source from tag 'upstream/0.9.16'
[location/debian/libloc.git] / src / python / location / logger.py
CommitLineData
1f2c3ccb
JS
1###############################################################################
2# #
3# libloc - A library to determine the location of someone on the Internet #
4# #
5# Copyright (C) 2020 IPFire Development Team <info@ipfire.org> #
6# #
7# This library is free software; you can redistribute it and/or #
8# modify it under the terms of the GNU Lesser General Public #
9# License as published by the Free Software Foundation; either #
10# version 2.1 of the License, or (at your option) any later version. #
11# #
12# This library is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
15# Lesser General Public License for more details. #
16# #
17###############################################################################
18
19import logging
20import logging.handlers
21
22# Initialise root logger
23log = logging.getLogger("location")
24log.setLevel(logging.INFO)
25
26# Log to console
27handler = logging.StreamHandler()
28handler.setLevel(logging.DEBUG)
29log.addHandler(handler)
30
31# Log to syslog
32handler = logging.handlers.SysLogHandler(address="/dev/log",
33 facility=logging.handlers.SysLogHandler.LOG_DAEMON)
34handler.setLevel(logging.INFO)
35log.addHandler(handler)
36
37# Format syslog messages
38formatter = logging.Formatter("%(message)s")
39handler.setFormatter(formatter)
40
41def set_level(level):
42 """
43 Sets the log level for the root logger
44 """
45 log.setLevel(level)