-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.py
42 lines (32 loc) · 1.22 KB
/
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
37
38
39
40
41
42
import logging
import time
operf = logging.FileHandler(filename='operation.log', mode='a', encoding='utf-8')
operf.setLevel(logging.INFO)
fmt = logging.Formatter(fmt="%(levelname)s:%(name)s:%(module)s:%(message)s")
operf.setFormatter(fmt)
slogf = logging.FileHandler(filename='server.log', mode='a', encoding='utf-8')
slogf.setLevel(logging.INFO)
fmt1 = logging.Formatter(fmt="%(levelname)s:%(name)s:%(module)s:%(message)s")
slogf.setFormatter(fmt1)
oper = logging.Logger(name='operation', level=logging.INFO)
oper.addHandler(operf)
slog = logging.Logger(name='server', level=logging.INFO)
slog.addHandler(slogf)
class log:
def bot(msg):
global oper
print(
f'{time.asctime( time.localtime(time.time()) )}:[Telegram]: {msg}')
oper.info(
f'{time.asctime( time.localtime(time.time()) )}:[Telegram]: {msg} \n')
def server(msg):
global slog
print(
f'{time.asctime( time.localtime(time.time()) )}:[ Server ]: {msg}')
slog.info(
f'{time.asctime( time.localtime(time.time()) )}:[ Server ]: {msg}')
def error(msg):
global oper
oper.error(
f'{time.asctime( time.localtime(time.time()) )}:[ System ]: {msg}'
)