Allow logging over UDP
This commit is contained in:
parent
11c900c2e5
commit
d708d1eb21
|
@ -23,6 +23,7 @@ def main():
|
||||||
parser.add_argument("--control_socket", default="/tmp/nfc.sock")
|
parser.add_argument("--control_socket", default="/tmp/nfc.sock")
|
||||||
parser.add_argument("--valid_tokens", default="/etc/door_tokens")
|
parser.add_argument("--valid_tokens", default="/etc/door_tokens")
|
||||||
parser.add_argument("--log_file", default="/tmp/nfc.log")
|
parser.add_argument("--log_file", default="/tmp/nfc.log")
|
||||||
|
parser.add_argument("--log_host", default=None)
|
||||||
parser.add_argument("--log_level", default="INFO")
|
parser.add_argument("--log_level", default="INFO")
|
||||||
parser.add_argument("--mqtt_host", default="10.10.21.2")
|
parser.add_argument("--mqtt_host", default="10.10.21.2")
|
||||||
|
|
||||||
|
@ -32,7 +33,12 @@ def main():
|
||||||
mqttc.connect_async("10.10.21.2", keepalive=60)
|
mqttc.connect_async("10.10.21.2", keepalive=60)
|
||||||
mqttc.loop_start()
|
mqttc.loop_start()
|
||||||
|
|
||||||
init_logging(level=config.log_level, output_file=config.log_file)
|
log_host = None
|
||||||
|
if config.log_host != None:
|
||||||
|
log_host = config.log_host.split(':')
|
||||||
|
log_host = (log_host[0], int(log_host[1]))
|
||||||
|
|
||||||
|
init_logging(level=config.log_level, output_file=config.log_file, output_host=log_host)
|
||||||
|
|
||||||
logger().info("Starting control")
|
logger().info("Starting control")
|
||||||
control = Control(config, mqttc)
|
control = Control(config, mqttc)
|
||||||
|
|
|
@ -4,6 +4,7 @@ from threading import RLock, Condition
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
|
import logging.handlers
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
_log_handlers: List[logging.Handler] = []
|
_log_handlers: List[logging.Handler] = []
|
||||||
|
@ -27,19 +28,19 @@ def init_logging(*,
|
||||||
if output_file != None:
|
if output_file != None:
|
||||||
# Create a file handler
|
# Create a file handler
|
||||||
file_handler = logging.FileHandler(output_file)
|
file_handler = logging.FileHandler(output_file)
|
||||||
|
file_handler.setLevel(level)
|
||||||
_log_handlers.append(file_handler)
|
_log_handlers.append(file_handler)
|
||||||
|
|
||||||
if output_host != None:
|
if output_host != None:
|
||||||
dgram_handler = logging.DatagramHandler(*output_host)
|
dgram_handler = logging.handlers.DatagramHandler(*output_host)
|
||||||
|
dgram_handler.setLevel(logging.DEBUG)
|
||||||
_log_handlers.append(dgram_handler)
|
_log_handlers.append(dgram_handler)
|
||||||
|
|
||||||
if output_stream != None:
|
if output_stream != None:
|
||||||
console_handler = logging.StreamHandler(output_stream)
|
console_handler = logging.StreamHandler(output_stream)
|
||||||
|
console_handler.setLevel(logging.DEBUG)
|
||||||
_log_handlers.append(console_handler)
|
_log_handlers.append(console_handler)
|
||||||
|
|
||||||
for h in _log_handlers:
|
|
||||||
h.setLevel(level)
|
|
||||||
|
|
||||||
# Default log output
|
# Default log output
|
||||||
logging.basicConfig(force=True, level=level, format=_log_format, handlers=_log_handlers)
|
logging.basicConfig(force=True, level=level, format=_log_format, handlers=_log_handlers)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user