-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove external dependencies to logger package
- Loading branch information
1 parent
b4454be
commit ec4c79d
Showing
7 changed files
with
105 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import sys | ||
|
||
CRITICAL = 50 | ||
ERROR = 40 | ||
WARNING = 30 | ||
INFO = 20 | ||
DEBUG = 10 | ||
NOTSET = 0 | ||
|
||
_level_dict = { | ||
CRITICAL: "CRIT", | ||
ERROR: "ERROR", | ||
WARNING: "WARN", | ||
INFO: "INFO", | ||
DEBUG: "DEBUG", | ||
} | ||
|
||
_stream = sys.stderr | ||
|
||
class Logger: | ||
|
||
level = NOTSET | ||
|
||
def __init__(self, name): | ||
self.name = name | ||
|
||
def _level_str(self, level): | ||
l = _level_dict.get(level) | ||
if l is not None: | ||
return l | ||
return "LVL%s" % level | ||
|
||
def setLevel(self, level): | ||
self.level = level | ||
|
||
def isEnabledFor(self, level): | ||
return level >= (self.level or _level) | ||
|
||
def log(self, level, msg, *args): | ||
if level >= (self.level or _level): | ||
_stream.write("%s:%s:" % (self._level_str(level), self.name)) | ||
if not args: | ||
print(msg, file=_stream) | ||
else: | ||
print(msg % args, file=_stream) | ||
|
||
def debug(self, msg, *args): | ||
self.log(DEBUG, msg, *args) | ||
|
||
def info(self, msg, *args): | ||
self.log(INFO, msg, *args) | ||
|
||
def warning(self, msg, *args): | ||
self.log(WARNING, msg, *args) | ||
|
||
def error(self, msg, *args): | ||
self.log(ERROR, msg, *args) | ||
|
||
def critical(self, msg, *args): | ||
self.log(CRITICAL, msg, *args) | ||
|
||
def exc(self, e, msg, *args): | ||
self.log(ERROR, msg, *args) | ||
sys.print_exception(e, _stream) | ||
|
||
def exception(self, msg, *args): | ||
self.exc(sys.exc_info()[1], msg, *args) | ||
|
||
|
||
_level = INFO | ||
_loggers = {} | ||
|
||
def getLogger(name): | ||
if name in _loggers: | ||
return _loggers[name] | ||
l = Logger(name) | ||
_loggers[name] = l | ||
return l | ||
|
||
def info(msg, *args): | ||
getLogger(None).info(msg, *args) | ||
|
||
def debug(msg, *args): | ||
getLogger(None).debug(msg, *args) | ||
|
||
def basicConfig(level=INFO, filename=None, stream=None, format=None): | ||
global _level, _stream | ||
_level = level | ||
if stream: | ||
_stream = stream | ||
if filename is not None: | ||
print("logging.basicConfig: filename arg is not supported") | ||
if format is not None: | ||
print("logging.basicConfig: format arg is not supported") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters