Skip to content
This repository was archived by the owner on Aug 28, 2021. It is now read-only.

Commit 3e48698

Browse files
committed
Allow the user to set the log format and make it consistent
This should solve some minor issues that I encountered with the logging format This might be outsourced into a configuration file someday, but in the meantime it stays a runtime argument Resolves #57
1 parent 0161b7b commit 3e48698

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

classes/mcPy/McPy.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ def main():
5555
if parser.debug:
5656
print('Debug mode enabled. Don\'t forget to remove debug flag for maximum performance !')
5757
logging_level = logging.DEBUG if parser.debug else logging.INFO
58-
logging.basicConfig(format="[%(asctime)s - %(levelname)s - %(threadName)s] %(message)s")
59-
logging.root.setLevel(logging_level)
58+
logging.basicConfig(level=logging_level, format=parser.format, force=True)
6059

6160
_launch(parser)

classes/mcPy/Parser.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@ def __init__(self):
1111
def initialize_arguments(self):
1212
self.parser.add_argument("--debug", # Command line flag to set logging in DEBUG mode
1313
action="store_true", # Syntactic sugar to say 'default:"false"'
14-
help="set logging to DEBUG level")
14+
help="Set logging to DEBUG level")
1515
self.parser.add_argument("--test", # Only launch tests
1616
action="store_true", # Syntactic sugar to say 'default:"false"'
1717
help="Do not launch the server, only launch tests")
18+
self.parser.add_argument("--format", # Command line flag to set the log format
19+
nargs='?', # We expect another argument after that
20+
default="[%(asctime)s - %(levelname)s - %(threadName)s] %(message)s",
21+
help="Set the logging format to the specified format. (Default: \"%(default)s\")")
1822

1923
def parse_arguments(self):
2024
self.args = self.parser.parse_args()
2125
self.debug = self.args.debug
2226
self.test = self.args.test
27+
self.format = self.args.format

dependencies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import json
55

66
# Set default logging level to INFO
7-
logging.basicConfig(level="INFO")
7+
logging.basicConfig(level="INFO", format="[%(asctime)s - %(levelname)s - %(threadName)s] %(message)s", force=True)
88

99
# Check if current python version is 3.8
1010
if sys.version_info < (3, 8):

0 commit comments

Comments
 (0)