-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhalogging.py
35 lines (27 loc) · 1000 Bytes
/
halogging.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
29
30
31
32
33
34
35
#!/usr/bin/python
# coding=utf-8
import logging
import coloredlogs
import os
from hasettings import BASE_DIR, LOGLEVEL
def InitLogging(filepath=None, loglevel=None):
if filepath is None:
print('Logging to: ' + BASE_DIR + os.sep + 'ha.log')
filepath = BASE_DIR + os.sep + 'ha.log'
if loglevel is None:
loglevel = LOGLEVEL
log_formatter = logging.Formatter("%(asctime)s [%(threadName)-12.12s] [%(levelname)-5.5s] %(message)s")
root_logger = logging.getLogger()
root_logger.setLevel(loglevel)
file_handler = logging.FileHandler(filepath)
file_handler.setFormatter(log_formatter)
root_logger.addHandler(file_handler)
# console_handler = logging.StreamHandler()
# console_handler.setFormatter(log_formatter)
# root_logger.addHandler(console_handler)
coloredlogs.install(level=LOGLEVEL)
def LogConcat(*args):
sl = []
for x in args:
sl.append(str(x))
return ' '.join(sl)