]> git.ipfire.org Git - location/libloc.git/blobdiff - src/python/location-exporter.in
Revert "debian: Drop perl package"
[location/libloc.git] / src / python / location-exporter.in
index b2c0dcc01556966205787701d90a41949e228845..894bb4408272c03aca3ab3cba5ad4387bbd6e0d0 100644 (file)
 ###############################################################################
 
 import argparse
-import gettext
 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
+from location.i18n import _
 
 # Initialise logging
-log = setup_logging()
-
-# i18n
-def _(singular, plural=None, n=None):
-       if plural:
-               return gettext.dngettext("libloc", singular, plural, n)
-
-       return gettext.dgettext("libloc", singular)
+log = logging.getLogger("location.exporter")
+log.propagate = 1
 
 class OutputWriter(object):
        suffix = "networks"
@@ -225,10 +197,12 @@ class CLI(object):
                # Global configuration flags
                parser.add_argument("--debug", action="store_true",
                        help=_("Enable debug output"))
+               parser.add_argument("--quiet", action="store_true",
+                       help=_("Enable quiet mode"))
 
                # version
                parser.add_argument("--version", action="version",
-                       version="%%(prog)s %s" % location.__version__)
+                       version="%(prog)s @VERSION@")
 
                # database
                parser.add_argument("--database", "-d",
@@ -250,9 +224,11 @@ class CLI(object):
 
                args = parser.parse_args()
 
-               # Enable debug logging
+               # Configure logging
                if args.debug:
-                       log.setLevel(logging.DEBUG)
+                       location.logger.set_level(logging.DEBUG)
+               elif args.quiet:
+                       location.logger.set_level(logging.WARNING)
 
                return args