-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathinit_logger.py
36 lines (31 loc) · 1.08 KB
/
init_logger.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
36
'''
Filename: init_logger.py
Project: image2katex
File Created: Sunday, 9th December 2018 6:11:11 pm
Author: xiaofeng ([email protected])
--------------------------
Last Modified: Sunday, 9th December 2018 6:11:15 pm
Modified By: xiaofeng ([email protected])
---------------------------
: 2018.06 - 2018 .
'''
import logging
import os
def get_logger(_loggerDir, log_path, logger_name):
_LogFile = os.path.join(_loggerDir, log_path)
logger = logging.getLogger(logger_name)
logger.setLevel(logging.INFO)
# ccreate file handler which logs even debug messages
fh = logging.FileHandler(_LogFile)
fh.setLevel(logging.INFO)
# create console handler with a higher log level
console = logging.StreamHandler()
console.setLevel(logging.INFO)
# create formatter and add it to the handlers
_LogFormat = logging.Formatter("%(asctime)2s -%(name)-12s: %(levelname)-10s - %(message)s")
fh.setFormatter(_LogFormat)
console.setFormatter(_LogFormat)
# add the handlers to logger
logger.addHandler(fh)
logger.addHandler(console)
return logger