-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhaystack_logging.py
More file actions
27 lines (19 loc) · 948 Bytes
/
haystack_logging.py
File metadata and controls
27 lines (19 loc) · 948 Bytes
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
import logging
import logging.handlers
import sys
import fcntl
import os
def init_logger(appname, level):
root_logger = logging.getLogger('')
strm_out = logging.StreamHandler(sys.__stdout__)
strm_out.setFormatter(logging.Formatter('%(name)s %(asctime)s %(filename)s %(lineno)s %(levelname)s:%(message)s'))
root_logger.addHandler(strm_out)
handler = logging.handlers.RotatingFileHandler(appname + "err.log", "ab", 50*1024*1024, 5)
handler.setLevel(logging.ERROR)
handler.setFormatter(logging.Formatter('%(asctime)s %(filename)s %(lineno)s %(levelname)s:%(message)s'))
root_logger.addHandler(handler)
handler = logging.handlers.RotatingFileHandler(appname + ".log", "ab", 50*1024*1024, 5)
handler.setLevel(logging.DEBUG)
handler.setFormatter(logging.Formatter('%(asctime)s %(filename)s %(lineno)s %(levelname)s:%(message)s'))
root_logger.addHandler(handler)
root_logger.setLevel(level)