Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make time format in log messages customizable
  • Loading branch information
iBug committed Sep 4, 2018
1 parent ba7e258 commit 98630e6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
3 changes: 2 additions & 1 deletion config.sample
Expand Up @@ -16,4 +16,5 @@ location=location_here
# github_username=username@domain.com
# github_password=p@55w0rd

# Miscellaneous stuff. Recommend leaving the default values for production Smokey
# Miscellaneous customization. Recommend leaving the default values for production Smokey
# log_time_format=%H:%M:%S
3 changes: 3 additions & 0 deletions globalvars.py
Expand Up @@ -142,6 +142,9 @@ class GlobalVars:
flovis_host = config.get("flovis_host")
flovis = None

# Miscellaneous
log_time_format = config.get("log_time_format", "%H:%M:%S")

@staticmethod
def reload():
commit = git_commit_info()
Expand Down
12 changes: 7 additions & 5 deletions helpers.py
Expand Up @@ -8,6 +8,7 @@
import requests
import regex
from glob import glob
from globalvars import GlobalVars


class Helpers:
Expand Down Expand Up @@ -46,10 +47,11 @@ def log(log_level, *args, f=False):
if level < Helpers.min_log_level:
return

color = (levels[log_level][1] if log_level in levels else 'white')
log_str = u"{} {}".format(colored("[{}]".format(datetime.now().isoformat()[11:-7]), color),
u" ".join([str(x) for x in args]))
print(log_str)
color = levels[log_level][1] if log_level in levels else 'white'
log_str = "{} {}".format(colored("[{}]".format(datetime.now().strftime(GlobalVars.log_time_format)),
color),
" ".join([str(x) for x in args]))
print(log_str, file=sys.stderr)

if f: # Also to file
log_file(log_level, *args)
Expand All @@ -65,7 +67,7 @@ def log_file(log_level, *args):
if levels[log_level][0] < Helpers.min_log_level:
return

log_str = "[{}] {}: {}".format(datetime.now().isoformat()[11:-3], log_level.upper(),
log_str = "[{}] {}: {}".format(datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S"), log_level.upper(),
" ".join([str(x) for x in args]))
with open("errorLogs.txt", "a", encoding="utf-8") as f:
print(log_str, file=f)
Expand Down

0 comments on commit 98630e6

Please sign in to comment.