1414__author__ = 'Raido Pahtma'
1515__license__ = "MIT"
1616
17+ version = "0.2.0"
1718
1819DEFAULT_FORMAT_STRING = '%(asctime)s|%(levelname)8s|%(module)20s|%(lineno)4s| %(message)s'
1920COLORED_FORMAT_STRING = '%(log_color)s%(asctime)s%(reset)s|%(module)20s|%(lineno)4s| %(log_color)s%(message)s'
@@ -77,7 +78,7 @@ def setup_console(level=logging.NOTSET, fs=DEFAULT_FORMAT_STRING, settings=None,
7778 formatter = logging .Formatter (fs )
7879
7980 console .setFormatter (formatter )
80- console .setLevel (level )
81+ console .setLevel (logging . NOTSET )
8182
8283 rootlogger = logging .getLogger ("" )
8384 rootlogger .setLevel (min (level , rootlogger .getEffectiveLevel ()))
@@ -102,17 +103,19 @@ def setup_file(application_name, logdir="log", level=logging.NOTSET, fs=DEFAULT_
102103 loglatest = "log_{}_latest.txt" .format (application_name )
103104 logfilepath = os .path .join (logdir , logfilename )
104105 loglinkpath = os .path .join (logdir , loglatest )
105- logfile = logging . handlers . TimedRotatingFileHandler ( logfilepath , when = "W6" , backupCount = backups )
106-
107- if os . path . islink ( loglinkpath ) :
108- os . unlink ( loglinkpath )
106+ if backups :
107+ logfile = logging . handlers . TimedRotatingFileHandler ( logfilepath , when = "W6" , backupCount = backups )
108+ else :
109+ logfile = logging . FileHandler ( logfilepath )
109110
110111 if hasattr (os , "symlink" ):
112+ if os .path .islink (loglinkpath ):
113+ os .unlink (loglinkpath )
111114 os .symlink (logfilename , loglinkpath )
112115
113116 formatter = logging .Formatter (fs )
114117 logfile .setFormatter (formatter )
115- logfile .setLevel (level )
118+ logfile .setLevel (logging . NOTSET )
116119
117120 rootlogger = logging .getLogger ("" )
118121 rootlogger .setLevel (min (level , rootlogger .getEffectiveLevel ()))
0 commit comments