Skip to content

Commit

Permalink
Merge pull request #2167 from matham/logger
Browse files Browse the repository at this point in the history
Add config callback to change the log file when the config log_dir/log_name change.
  • Loading branch information
tito committed Jul 6, 2014
2 parents 1aa6473 + 975f41f commit 42b7424
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion kivy/logger.py
Expand Up @@ -140,7 +140,7 @@ def purge_logs(self, directory):

print('Purge finished!')

def _configure(self):
def _configure(self, *largs, **kwargs):
from time import strftime
from kivy.config import Config
log_dir = Config.get('kivy', 'log_dir')
Expand All @@ -167,7 +167,11 @@ def _configure(self):
if n > 10000: # prevent maybe flooding ?
raise Exception('Too many logfile, remove them')

if FileHandler.filename == filename and FileHandler.fd is not None:
return
FileHandler.filename = filename
if FileHandler.fd is not None:
FileHandler.fd.close()
FileHandler.fd = open(filename, 'w')

Logger.info('Logger: Record log in %s' % filename)
Expand Down Expand Up @@ -199,6 +203,9 @@ def emit(self, message):
if FileHandler.fd is None:
try:
self._configure()
from kivy.config import Config
Config.add_callback(self._configure, 'kivy', 'log_dir')
Config.add_callback(self._configure, 'kivy', 'log_name')
except Exception:
# deactivate filehandler...
FileHandler.fd = False
Expand Down

0 comments on commit 42b7424

Please sign in to comment.