Skip to content
Snippets Groups Projects
Commit 07734295 authored by Tamas Gal's avatar Tamas Gal :speech_balloon:
Browse files

Add log cycle for MSG dumps

parent bba4d917
No related branches found
No related tags found
No related merge requests found
......@@ -13,25 +13,49 @@ Usage:
Options:
-l LIGIER_IP The IP of the ligier [default: 127.0.0.1].
-p LIGIER_PORT The port of the ligier [default: 5553].
-f LOG_FILE Log file to dump the messages [default: MSG.log].
-o LOG_DIR Directory to dump the messages [default: logs].
-x PREFIX Prefix for the log files [default: MSG].
-h --help Show this screen.
"""
import datetime
import os
import time
from shutil import copyfile
from km3pipe import Pipeline, Module
from km3pipe.io import CHPump
def current_date_str(fmt="%Y-%m-%d"):
"""Return the current datetime string"""
return datetime.datetime.now().strftime(fmt)
class MSGDumper(Module):
def configure(self):
self.filename = self.get('filename', default='MSG.log')
self.fobj = open(os.path.abspath(self.filename), 'a')
self.path = os.path.abspath(self.require('path'))
self.prefix = self.require('prefix')
self.current_date = current_date_str()
self.filename = self.prefix + ".log"
self.filepath = os.path.join(self.path, self.filename)
self.fobj = open(self.filepath, 'a')
def update_file_descriptor(self):
current_date = current_date_str()
if self.current_date != current_date:
archived_name = "{}_{}.log".format(self.prefix, self.current_date)
self.print("Cycling the log file: {} -> {}".format(
self.filename, archived_name))
copyfile(self.filepath, os.path.join(self.path, archived_name))
self.fobj.close()
self.fobj = open(self.filepath, 'w')
self.current_date = current_date
def process(self, blob):
data = blob['CHData'].decode()
source = "Other"
if " A0" in data:
source = "AcousticDataFilter"
if " F0" in data:
source = "DataFilter"
if " Q0" in data:
......@@ -39,14 +63,15 @@ class MSGDumper(Module):
if " W0" in data:
source = "DataWriter"
entry = "{} [{}]: {}\n".format(
os.path.basename(self.filename), source, data)
entry = "{} [{}]: {}\n".format(self.filename, source, data)
self.update_file_descriptor()
self.fobj.write(entry)
self.fobj.flush()
return blob
def finish(self):
self.fobj.close()
if self.fobj is not None:
self.fobj.close()
def main():
......@@ -55,17 +80,17 @@ def main():
ligier_ip = args['-l']
ligier_port = int(args['-p'])
filename = args['-f']
path = args['-o']
prefix = args['-x']
pipe = Pipeline()
pipe.attach(
CHPump,
host=ligier_ip,
port=ligier_port,
tags='MSG',
timeout=7 * 60 * 60 * 24,
max_queue=500)
pipe.attach(MSGDumper, filename=filename)
pipe.attach(CHPump,
host=ligier_ip,
port=ligier_port,
tags='MSG',
timeout=7 * 60 * 60 * 24,
max_queue=500)
pipe.attach(MSGDumper, prefix=prefix, path=path)
pipe.drain()
......
......@@ -146,7 +146,7 @@ stderr_logfile=logs/%(program_name)s.err.log
;stderr_logfile=logs/%(program_name)s.err.log
[program:msg_dumper]
command=python -u scripts/msg_dumper.py -l %(ENV_LOG_LIGIER_IP)s -p %(ENV_LOG_LIGIER_PORT)s -f logs/MSG.log
command=python -u scripts/msg_dumper.py -l %(ENV_LOG_LIGIER_IP)s -p %(ENV_LOG_LIGIER_PORT)s -o logs
priority=200
stdout_logfile=logs/%(program_name)s.out.log
stderr_logfile=logs/%(program_name)s.err.log
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment