Skip to content

Commit

Permalink
minor changes & optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Fiers committed Sep 3, 2012
1 parent 3be8de5 commit 11f397b
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions lib/python/moa/logger.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,60 @@
#!/usr/bin/env python
# Copyright 2009-2011 Mark Fiers
# The New Zealand Institute for Plant & Food Research
#
#
# This file is part of Moa - http://github.com/mfiers/Moa
#
#
# Licensed under the GPL license (see 'COPYING')
#
#
import os
import sys
import time
import logging
from logging import DEBUG, INFO, WARNING, CRITICAL

import traceback
LOGGER = logging.getLogger('moa')
LOGGER = logging.getLogger('moa')

handler = logging.StreamHandler()

logmark = chr(27) + '[0;45mMOA' + \
chr(27) + '[0m '
logmark = chr(27) + '[0;45mMOA' + chr(27) + '[0m'

logging.basicConfig(format=logmark +
' %(name)s - %(message)s',
datefmt='%y/%m/%d %H:%M:%S')

logging.basicConfig(format=logmark + '%(levelname)s|%(asctime)s|%(name)s # %(message)s', datefmt='%y/%m/%d %H:%M:%S')

def exitError(message=""):
l.critical("Deprecated function call - do not use logger.exitError, but moa.ui.exitError")
l.critical("Deprecated function call - do not " +
"use logger.exitError, but moa.ui.exitError")
if message:
LOGGER.fatal(message)
sys.exit(-1)


def setLevel(level):
if level == logging.DEBUG:
LOGGER.setLevel(logging.DEBUG)
LOGGER.setLevel(logging.DEBUG)
else:
LOGGER.setLevel(level)



def setVerbose():
LOGGER.setLevel(logging.DEBUG)


def setSilent():
LOGGER.setLevel(logging.CRITICAL)


def setWarning():
LOGGER.setLevel(logging.WARNING)


def setInfo():
LOGGER.setLevel(logging.INFO)


def _callLogger(logFunc, args, kwargs):
if len(args) == 1:
logFunc(args[0])
Expand All @@ -55,23 +64,26 @@ def _callLogger(logFunc, args, kwargs):
for k in kwargs.keys():
logFunc(" - %s : %s" % (k, kwargs[k]))


def getLogger(name):
return logging.getLogger(name)



def debug(*args, **kwargs):
_callLogger(LOGGER.debug, args, kwargs)


def info(*args, **kwargs):
_callLogger(LOGGER.info, args, kwargs)


def warning(*args, **kwargs):
_callLogger(LOGGER.warning, args, kwargs)


def error(*args, **kwargs):
_callLogger(LOGGER.error, args, kwargs)


def critical(*args, **kwargs):
_callLogger(LOGGER.critical, args, kwargs)


0 comments on commit 11f397b

Please sign in to comment.