-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogs.py
executable file
·53 lines (36 loc) · 1.48 KB
/
logs.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#import library
import os
import logging,logging.handlers
from datetime import datetime
#app logs
def app_logs(logggername):
#create log file
log_file = './logs/app.log'
#create logger console
logger = logging.getLogger(logggername)
if not logger.hasHandlers():
logger.setLevel(logging.DEBUG)
# create console handler and set level to debug
handler = logging.handlers.RotatingFileHandler(filename=log_file,maxBytes=12000000,backupCount=10)
# create formatter
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s","%Y-%m-%d %H:%M:%S")
handler.setFormatter(formatter)
#add handler
logger.addHandler(handler)
return logger
#file logs
def file_logs(logggername):
#create log file
log_file = './logs/SFTP_'+datetime.now().strftime('%Y%m%d')+'.log'
#create logger console
logger = logging.getLogger(logggername)
if not logger.hasHandlers():
logger.setLevel(logging.DEBUG)
# create console handler and set level to debug
handler = logging.handlers.RotatingFileHandler(filename=log_file,maxBytes=12000000,backupCount=10)
# create formatter
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s","%Y-%m-%d %H:%M:%S")
handler.setFormatter(formatter)
#add handler
logger.addHandler(handler)
return logger