src/libloc.pc
dist_pkgpython_PYTHON = \
- src/python/__init__.py
+ src/python/__init__.py \
+ src/python/logger.py
pyexec_LTLIBRARIES = \
src/python/_location.la
# Import everything from the C module
from _location import *
+
+# Initialise logging
+from . import logger
import datetime
import gettext
import logging
-import logging.handlers
import lzma
import os
import random
"https://people.ipfire.org/~ms/location/",
)
-def setup_logging(level=logging.INFO):
- l = logging.getLogger("location-downloader")
- l.setLevel(level)
-
- # Log to console
- h = logging.StreamHandler()
- h.setLevel(logging.DEBUG)
- l.addHandler(h)
-
- # Log to syslog
- h = logging.handlers.SysLogHandler(address="/dev/log",
- facility=logging.handlers.SysLogHandler.LOG_DAEMON)
- h.setLevel(logging.INFO)
- l.addHandler(h)
-
- # Format syslog messages
- formatter = logging.Formatter("location-downloader[%(process)d]: %(message)s")
- h.setFormatter(formatter)
-
- return l
-
# Initialise logging
-log = setup_logging()
+log = logging.getLogger("location.downloader")
+log.propagate = 1
# i18n
def _(singular, plural=None, n=None):
import io
import ipaddress
import logging
-import logging.handlers
import os.path
import socket
import sys
# Load our location module
import location
-def setup_logging(level=logging.INFO):
- l = logging.getLogger("location-exporter")
- l.setLevel(level)
-
- # Log to console
- h = logging.StreamHandler()
- h.setLevel(logging.DEBUG)
- l.addHandler(h)
-
- # Log to syslog
- h = logging.handlers.SysLogHandler(address="/dev/log",
- facility=logging.handlers.SysLogHandler.LOG_DAEMON)
- h.setLevel(logging.INFO)
- l.addHandler(h)
-
- # Format syslog messages
- formatter = logging.Formatter("location-exporter[%(process)d]: %(message)s")
- h.setFormatter(formatter)
-
- return l
-
# Initialise logging
-log = setup_logging()
+log = logging.getLogger("location.exporter")
+log.propagate = 1
# i18n
def _(singular, plural=None, n=None):
import os
import socket
import sys
-import syslog
# Load our location module
import location
--- /dev/null
+#!/usr/bin/python3
+###############################################################################
+# #
+# libloc - A library to determine the location of someone on the Internet #
+# #
+# Copyright (C) 2020 IPFire Development Team <info@ipfire.org> #
+# #
+# This library is free software; you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public #
+# License as published by the Free Software Foundation; either #
+# version 2.1 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 #
+# Lesser General Public License for more details. #
+# #
+###############################################################################
+
+import logging
+import logging.handlers
+
+# Initialise root logger
+log = logging.getLogger("location")
+log.setLevel(logging.INFO)
+
+# Log to console
+handler = logging.StreamHandler()
+handler.setLevel(logging.DEBUG)
+log.addHandler(handler)
+
+# Log to syslog
+handler = logging.handlers.SysLogHandler(address="/dev/log",
+ facility=logging.handlers.SysLogHandler.LOG_DAEMON)
+handler.setLevel(logging.INFO)
+log.addHandler(handler)
+
+# Format syslog messages
+formatter = logging.Formatter("%(message)s")
+handler.setFormatter(formatter)