O2-DQ User Interface 1.0.0
Loading...
Searching...
No Matches
debugSettings.py
Go to the documentation of this file.
1#!/usr/bin/env python
2# PYTHON_ARGCOMPLETE_OK
3# -*- coding: utf-8 -*-
4
5# Copyright 2019-2020 CERN and copyright holders of ALICE O2.
6# See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
7# All rights not expressly granted are reserved.
8#
9# This software is distributed under the terms of the GNU General Public
10# License v3 (GPL Version 3), copied verbatim in the file "COPYING".
11#
12# In applying this license CERN does not waive the privileges and immunities
13# granted to it by virtue of its status as an Intergovernmental Organization
14# or submit itself to any jurisdiction.
15
16import logging
17from logging import handlers
18import sys
19import os
20
21
22def debugSettings(argDebug: bool, argLogFile: bool, fileName: str):
23 """Debug settings for CLI
24
25 Args:
26 argDebug (bool): Debug Level
27 argLogFile (bool): CLI argument as logFile
28 fileName (str): Output name of log file
29
30 Raises:
31 ValueError: If selected invalid log level
32 """
33
34 if argDebug and (not argLogFile):
35 DEBUG_SELECTION = argDebug
36 numeric_level = getattr(logging, DEBUG_SELECTION.upper(), None)
37 if not isinstance(numeric_level, int):
38 raise ValueError("Invalid log level: %s" % DEBUG_SELECTION)
39 logging.basicConfig(format = "[%(levelname)s] %(message)s", level = DEBUG_SELECTION)
40
41 if argLogFile and argDebug:
42 log = logging.getLogger("")
43 level = logging.getLevelName(argDebug)
44 log.setLevel(level)
45 format = logging.Formatter("[%(levelname)s] %(message)s")
46
47 ch = logging.StreamHandler(sys.stdout)
48 ch.setFormatter(format)
49 log.addHandler(ch)
50
51 loggerFile = "tableReader.log"
52 if os.path.isfile(loggerFile):
53 os.remove(loggerFile)
54
55 fh = handlers.RotatingFileHandler(loggerFile, maxBytes = (1048576 * 5), backupCount = 7, mode = "w")
56 fh.setFormatter(format)
57 log.addHandler(fh)