18 from typing
import List, Optional
19 from pathlib
import Path
24 from .formatter
import CTXFormatter
25 from .severity
import LogSeverity
26 from ..utils
import createFileHandler
30 includeTime: bool =
True,
31 includeLevel: bool =
True,
32 includeColor: bool =
True,
33 jsonOutput: bool =
True
34 ) -> logging.Formatter:
39 fmt.append(
"%(asctime)s")
42 fmt.append(
"%(levelname)s")
45 fmt[-1] = fmt[-1] +
":"
47 fmt.append(
"%(message)s")
51 datefmt=
"%Y-%m-%d %H:%M:%S",
54 jsonOutput = jsonOutput
59 severity: LogSeverity,
61 streamHandler: Optional[logging.StreamHandler] =
None,
62 jsonOutput: bool =
False
66 Initializes python logging module
70 severity : LogSeverity
71 Severity level of the logger
73 File path where logs will be stored
74 streamHandler: Optional[logging.StreamHandler] : bool
75 Stream handler which will be used for logging
76 If None default one will be used
79 if streamHandler
is None:
80 streamHandler = logging.StreamHandler(sys.stdout)
81 streamHandler.setLevel(severity.getLevel())
83 streamHandler.setFormatter(createFormatter(
85 jsonOutput = jsonOutput
88 fileHandler = createFileHandler(logPath)
89 fileHandler.setLevel(logging.DEBUG)
90 fileHandler.setFormatter(createFormatter(includeColor =
False, jsonOutput =
False))
93 level = logging.NOTSET,