Commit 6f68e6f0 authored by Matthieu Dorier's avatar Matthieu Dorier


parent a41c528e
This diff is collapsed.
import logging
import sys
# Custom formatter
class FlameStoreFormatter(logging.Formatter):
err_fmt = "\033[91m[ERROR]\033[0m %(asctime)-15s %(msg)s"
dbg_fmt = "\033[94m[DEBUG]\033[0m %(asctime)-15s %(module)s: %(lineno)d: %(msg)s"
info_fmt = "\033[92m[INFO]\033[0m %(asctime)-15s %(msg)s"
critic_fmt = "\033[91m[FATAL]\033[0m %(asctime)-15s %(msg)s"
warn_fmt = "\033[93m[WARN]\033[0m %(asctime)-15s %(msg)s"
def __init__(self, fmt="%(levelno)s: %(msg)s"):
logging.Formatter.__init__(self, fmt)
def format(self, record):
# Save the original format configured by the user
# when the logger formatter was instantiated
format_orig = self._fmt
# Replace the original format with one customized by logging level
if record.levelno == logging.DEBUG:
self._fmt = FlameStoreFormatter.dbg_fmt
elif record.levelno == logging.INFO:
self._fmt = FlameStoreFormatter.info_fmt
elif record.levelno == logging.WARNING:
self._fmt = FlameStoreFormatter.warn_fmt
elif record.levelno == logging.ERROR:
self._fmt = FlameStoreFormatter.err_fmt
elif record.levelno == logging.CRITICAL:
self._fmt = FlameStoreFormatter.critic_fmt
# Call the original formatter class to do the grunt work
result = logging.Formatter.format(self, record)
# Restore the original format configured by the user
self._fmt = format_orig
return result
def static_vars(**kwargs):
def decorate(func):
for k in kwargs:
setattr(func, k, kwargs[k])
return func
return decorate
def init_logging(level):
if(init_logging.counter == 0) :
fmt = FlameStoreFormatter()
hdlr = logging.StreamHandler(sys.stdout)
init_logging.counter += 1
def get_logger():
return logging.getLogger('flamestore')
......@@ -2,5 +2,5 @@ import sys
import flamestore as fs
master = fs.FlameStoreMaster()
master = fs.FlameStoreMaster(path='abc')
......@@ -2,6 +2,6 @@ import sys
import flamestore as fs
worker = fs.FlameStoreWorker()
worker = fs.FlameStoreWorker(path='abc')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment