Commit ac058f3d6b49c0a72cc3f0026809c11527e3704c

Authored by hitier
1 parent db7f51f7

Absolute paths for logs_dir and logs_file

Showing 1 changed file with 6 additions and 3 deletions   Show diff stats
app/__init__.py
@@ -70,6 +70,9 @@ def create_app(config_class=None): @@ -70,6 +70,9 @@ def create_app(config_class=None):
70 70
71 app.logger.removeHandler(default_handler) 71 app.logger.removeHandler(default_handler)
72 72
  73 + logs_dir = os.path.join(app_dir, 'logs')
  74 + logs_file = os.path.join(logs_dir, 'pdc.log')
  75 +
73 # Log to stdout 76 # Log to stdout
74 if app.debug or app.testing or app.config['LOG_TO_STDOUT']: 77 if app.debug or app.testing or app.config['LOG_TO_STDOUT']:
75 stream_handler = logging.StreamHandler() 78 stream_handler = logging.StreamHandler()
@@ -78,9 +81,9 @@ def create_app(config_class=None): @@ -78,9 +81,9 @@ def create_app(config_class=None):
78 # or log to file 81 # or log to file
79 # TODO: get filename from config 82 # TODO: get filename from config
80 else: 83 else:
81 - if not os.path.exists('logs'):  
82 - os.mkdir('logs')  
83 - file_handler = RotatingFileHandler('logs/pdc.log')#, maxBytes=10240, backupCount=10) 84 + if not os.path.exists(logs_dir):
  85 + os.mkdir(logs_dir)
  86 + file_handler = RotatingFileHandler(logs_file, maxBytes=10240, backupCount=10)
84 file_handler.setFormatter(logging.Formatter( 87 file_handler.setFormatter(logging.Formatter(
85 '%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]')) 88 '%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'))
86 file_handler.setLevel(logging.INFO) 89 file_handler.setLevel(logging.INFO)