forked from svalinn/parastell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.py
28 lines (25 loc) · 785 Bytes
/
log.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import logging
def init():
"""Creates and configures logger with separate stream and file handlers.
Returns:
logger (object): logger object.
"""
# Create logger
logger = logging.getLogger('log')
# Configure base logger message level
logger.setLevel(logging.INFO)
# Configure stream handler
s_handler = logging.StreamHandler()
# Configure file handler
f_handler = logging.FileHandler('stellarator.log')
# Define and set logging format
format = logging.Formatter(
fmt = '%(asctime)s: %(message)s',
datefmt = '%H:%M:%S'
)
s_handler.setFormatter(format)
f_handler.setFormatter(format)
# Add handlers to logger
logger.addHandler(s_handler)
logger.addHandler(f_handler)
return logger