summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@gmail.com> 2013-11-16 21:51:12 +0100
committerGravatar Walter Purcaro <vuolter@gmail.com> 2013-11-16 21:51:12 +0100
commit73a1a2ff63cd3a2372b8c5c7cb959f51babe9222 (patch)
tree157c3546d60b4a7dbe9dbc04645da82d2fee1016
parentWhite foreground instead black for the colored log level labels (diff)
downloadpyload-73a1a2ff63cd3a2372b8c5c7cb959f51babe9222.tar.xz
Fixed logfile color codes (colorize console only) + settable color log type + cleaned pyload init_logger code
-rw-r--r--pyload/Core.py56
-rw-r--r--pyload/config/default.py1
2 files changed, 39 insertions, 18 deletions
diff --git a/pyload/Core.py b/pyload/Core.py
index bdf8af35f..52e2a4045 100644
--- a/pyload/Core.py
+++ b/pyload/Core.py
@@ -503,7 +503,7 @@ class Core(object):
console = logging.StreamHandler(sys.stdout)
# try to get a time formatting depending on system locale
- tfrm = None
+ datefmt = None
try: # change current locale to default if it is not set
current_locale = locale.getlocale()
if current_locale == (None, None):
@@ -511,26 +511,45 @@ class Core(object):
# We use timeformat provided by locale when available
if current_locale != (None, None):
- tfrm = locale.nl_langinfo(locale.D_FMT) + " " + locale.nl_langinfo(locale.T_FMT)
+ datefmt = locale.nl_langinfo(locale.D_FMT) + " " + locale.nl_langinfo(locale.T_FMT)
except: # something did go wrong, locale is heavily platform dependant
pass
# default formatting when no one was obtained (ex.: 2013-10-22 18:27:46)
- if not tfrm:
- tfrm = "%Y-%m-%d %H:%M:%S"
-
- frm = ColoredFormatter(
- format="%(asctime)s %(log_color)s%(bold)s%(white)s %(levelname)+8s %(reset)s %(message)s",
- datefmt=tfrm,
- log_colors={
- 'DEBUG': 'bg_cyan',
- 'INFO': 'bg_green',
- 'WARNING': 'bg_yellow',
- 'ERROR': 'bg_red',
- 'CRITICAL': 'bg_purple',
- }
- )
- console.setFormatter(frm)
+ if not datefmt:
+ datefmt = "%Y-%m-%d %H:%M:%S"
+
+ # file handler formatter
+ fhfmt = "%(asctime)s %(levelname)-8s %(message)s"
+ fh_frm = logging.Formatter(fhfmt, datefmt)
+
+ # console formatter
+ if self.config['log']['console_color'] == "No":
+ console_frm = fh_frm
+ else:
+ if self.config['log']['console_color'] == "Light":
+ cfmt = "%(asctime)s %(log_color)s%(bold)s%(white)s %(levelname)+8s %(reset)s %(message)s"
+ clr = {
+ 'DEBUG': 'bg_cyan',
+ 'INFO': 'bg_green',
+ 'WARNING': 'bg_yellow',
+ 'ERROR': 'bg_red',
+ 'CRITICAL': 'bg_purple',
+ }
+ elif self.config['log']['console_color'] == "Full":
+ cfmt = "%(asctime)s %(log_color)s[%(levelname)-8s] %(message)s"
+ clr = {
+ 'DEBUG': 'cyan',
+ 'INFO': 'green',
+ 'WARNING': 'yellow',
+ 'ERROR': 'red',
+ 'CRITICAL': 'purple',
+ }
+ console_frm = ColoredFormatter(cfmt, datefmt, clr)
+
+ #: set console formatter
+ console.setFormatter(console_frm)
+
self.log = logging.getLogger("log") # setable in config
if not exists(self.config['log']['log_folder']):
@@ -545,7 +564,8 @@ class Core(object):
else:
file_handler = logging.FileHandler(join(self.config['log']['log_folder'], 'log.txt'), encoding="utf8")
- file_handler.setFormatter(frm)
+ #: set file handler formatter
+ file_handler.setFormatter(fh_frm)
self.log.addHandler(file_handler)
self.log.addHandler(console) #if console logging
diff --git a/pyload/config/default.py b/pyload/config/default.py
index 0ae1a2649..8e2dcae74 100644
--- a/pyload/config/default.py
+++ b/pyload/config/default.py
@@ -25,6 +25,7 @@ def make_config(config):
("file_log", "bool", _("File Log"), True),
("log_count", "int", _("Count"), 5),
("log_rotate", "bool", _("Log Rotate"), True),
+ ("console_color", "No;Light;Full", _("Colorize Console"), "Light"),
])
config.addConfigSection("permission", _("Permissions"), _("Description"), _("Long description"),