logging rotation and in pgroup

This commit is contained in:
2023-10-16 19:02:49 +02:00
parent f88409954a
commit 2b61757705

View File

@ -1,11 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
import os import os
import time
from time import sleep
import numpy as np
# at the moment this allows us to group the subdirectories as modules easily # at the moment this allows us to group the subdirectories as modules easily
# TODO: a more general way would be to have this cristallina as a installed package # TODO: a more general way would be to have this cristallina as a installed package
@ -14,7 +9,6 @@ os.chdir("/sf/cristallina/applications/slic/cristallina")
# setup logging # setup logging
from loguru import logger from loguru import logger
def setup_logging(): def setup_logging():
logger.remove() logger.remove()
logger.add( logger.add(
@ -25,24 +19,36 @@ def setup_logging():
logger.info("Loading started.") logger.info("Loading started.")
# create file handler which logs # create file handler which logs
# TODO: better directory for log files? should not be pgroup specific so that this always works # TODO: better directory for general log files?
try: try:
logger.add( logger.add(
"/sf/cristallina/applications/slic/cristallina/log/cristallina.log", "/sf/cristallina/applications/slic/cristallina/log/cristallina.log",
format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}", format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}",
level="DEBUG", level="DEBUG",
rotation="1 week",
) )
except PermissionError as e: except PermissionError as e:
logger.warning("Cannot write log file.") logger.warning("Cannot write log file.")
logger.warning(e) logger.warning(e)
def setup_logging_pgroup(pgroup, level="INFO"):
try:
logger.add(
f"/sf/cristallina/data/{pgroup}/scratch/slic.log",
format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}",
level=level,
rotation="1 week",
)
except PermissionError as e:
logger.warning(f"Cannot write log file to pgroup {pgroup}.")
# We setup the logging before going further so that # We setup the logging before going further so that
# other modules can write startup messages into the log file. # other modules can write startup messages into the log file.
setup_logging() setup_logging()
# TODO: this is later overwritten, probably not intended that way? # TODO: this is later overwritten, probably not intended that way?
from epics import PV # from epics import PV
from devices.alignment_laser import AlignmentLaser from devices.alignment_laser import AlignmentLaser
from slic.gui import GUI from slic.gui import GUI
@ -85,7 +91,7 @@ try:
logger.info("Connected to stand server") logger.info("Connected to stand server")
except Exception as error: except Exception as error:
# catching with a broad net because different connection errors can occur. # catching with a broad net because different connection errors can occur.
logger.warning(f"Cannot connect to stand server on {stand_host}. Caught {error}.") logger.warning(f"Cannot connect to stand server on {stand_host}.")
# spreadsheet = Spreadsheet(adjs, placeholders=PLACEHOLDERS, host="127.0.0.1", port=8080)) # spreadsheet = Spreadsheet(adjs, placeholders=PLACEHOLDERS, host="127.0.0.1", port=8080))
@ -204,6 +210,9 @@ instrument = "cristallina"
# pgroup = "p21528" # Cr-MX Colletier 2023-09-05 # pgroup = "p21528" # Cr-MX Colletier 2023-09-05
pgroup = "p21516" # Beamline commissioning September 26-27, 2023 pgroup = "p21516" # Beamline commissioning September 26-27, 2023
# setup pgroup specific logger
setup_logging_pgroup(pgroup)
daq = SFAcquisition( daq = SFAcquisition(
instrument, instrument,
pgroup, pgroup,