-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecho_logger.py
42 lines (34 loc) · 1.06 KB
/
echo_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
# -*- coding: utf-8 -*-
# pylint: disable-msg=C0103
"""
BURPG Echo
See LICENSE for MIT/X11 license info.
See README.md for all other help.
"""
import time
class Logger:
"""
Provides a logging "singleton" instance that can be passed around as needed
"""
LOG_PATH = None
VERBOSE_MODE = False
def __init__(self, verbose=False, path=None):
self.VERBOSE_MODE = verbose
self.LOG_PATH = path
def log(self, message):
"""
Logs a message to the console and (if log_path is set) a file
:param message: the message to be logged
"""
print(message)
if self.LOG_PATH != None:
with open(self.LOG_PATH, "a") as logfile:
logfile.write("[" + str(int(time.time())) + "] " + message + "\n")
def log_verbose(self, message):
"""
Logs a message to the console and (if log_path is set) a file, but only if
verbose_mode is enabled
:param message: the verbose message to be logged
"""
if self.VERBOSE_MODE:
self.log(message)