Test Failed
Push — dev ( 3a28f6...0451e7 )
by Konstantinos
05:08
created

music_album_creation._logging   A

Complexity

Total Complexity 0

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 52
rs 10
c 0
b 0
f 0
wmc 0
1
"""Set up Application Logs
2
3
This module defines how the emitted application logs are handled and where
4
they are written/streamed.
5
The application logs are written in full details (ie with timestamps) to a file
6
and also streamed to the console in a more concise format.
7
8
Console:
9
    Stream Logs of INFO (and above) Level on Console's stderr
10
    The rendered Log format is: <logger name>: <log level> <log message>
11
12
Disk File:
13
    Write Logs of ALL Levels on a Disk File (see DCR_LOGS_FILE variable below)
14
    The rendered Log format is: <timestamp> <logger name>: <log level> <log message>
15
16
Log Levels:
17
- CRITICAL
18
- ERROR
19
- WARNING
20
- INFO
21
- DEBUG
22
23
Usage:
24
    Do a 'from . import _logging' in the root __init__.py of your package and
25
    all submodules 'inherit' the logging configuration
26
"""
27
import logging
28
29
DCR_LOGS_FILE = 'dcr.log'
30
31
#### FILE LOGGING
32
# set up logging to file for DEBUG Level and above
33
logging.basicConfig(
34
    level=logging.DEBUG,
35
    format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
36
    datefmt='%m-%d %H:%M',
37
    filename=DCR_LOGS_FILE,
38
    filemode='w',
39
)
40
41
#### CONSOLE LOGGING
42
# define a Handler which writes INFO messages or higher to the sys.stderr
43
console = logging.StreamHandler()
44
# console.setLevel(logging.INFO)
45
console.setLevel(logging.DEBUG)
46
# set a format which is simpler for console use
47
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
48
# tell the handler to use this format
49
console.setFormatter(formatter)
50
# add the handler to the root logger
51
logging.getLogger('').addHandler(console)
52
53
54
# Now, we can log to the root logger, or any other logger. First the root...
55
# logging.info('Blah blah')
56
57
# Now, define a couple of other loggers which might represent areas in your
58
# application:
59
60
# logger1 = logging.getLogger('myapp.area1')
61
# logger2 = logging.getLogger('myapp.area2')
62
# logger3 = logging.getLogger(__name__)
63
64
# logger1.debug('balh blah')
65
# logger1.info('balh blah')
66
# logger2.warning('balh blah')
67
# logger3.error('balh blah')
68