Skip to content

Commit 94916f5

Browse files
committed
ENH: Replace log_path with log_dir
Log files are saved according to the port where qiita is running. Fixes qiita-spots#1982
1 parent dfe015b commit 94916f5

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

qiita_core/configuration_manager.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from .exceptions import MissingConfigSection
1818

1919
with standard_library.hooks():
20-
from configparser import ConfigParser
20+
from configparser import ConfigParser, Error, NoOptionError
2121

2222

2323
class ConfigurationManager(object):
@@ -35,7 +35,9 @@ class ConfigurationManager(object):
3535
base_url: str
3636
base URL for the website, in the form http://SOMETHING.com
3737
base_data_dir : str
38-
Path to the base directorys where all data file are stored
38+
Path to the base directory where all data files are stored.
39+
log_dir : str
40+
Path to the directory where the log files are saved.
3941
working_dir : str
4042
Path to the working directory
4143
max_upload_size : int
@@ -118,6 +120,11 @@ class ConfigurationManager(object):
118120
The script used to start the plugins
119121
plugin_dir : str
120122
The path to the directory containing the plugin configuration files
123+
124+
Raises
125+
------
126+
Error
127+
When an option is no longer available.
121128
"""
122129
def __init__(self):
123130
# If conf_fp is None, we default to the test configuration file
@@ -157,7 +164,21 @@ def _get_main(self, config):
157164
self.base_data_dir = config.get('main', 'BASE_DATA_DIR') or \
158165
default_base_data_dir
159166

160-
self.log_path = config.get('main', 'LOG_PATH')
167+
try:
168+
log_path = config.get('main', 'LOG_PATH')
169+
if log_path:
170+
raise Error('The option LOG_PATH in the main section is no '
171+
'longer supported, use LOG_DIR instead.')
172+
except NoOptionError:
173+
pass
174+
175+
self.log_dir = config.get('main', 'LOG_DIR')
176+
if self.log_dir:
177+
# if the option is a directory, it will exist
178+
if not isdir(self.log_dir):
179+
raise ValueError("The LOG_DIR (%s) option is required to be a "
180+
"directory." % self.log_dir)
181+
161182
self.base_url = config.get('main', 'BASE_URL')
162183

163184
if not isdir(self.base_data_dir):

qiita_core/support_files/config_test.cfg

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
# Change to FALSE in a production system
1616
TEST_ENVIRONMENT = TRUE
1717

18-
# Absolute path to write log file to. If not given, no log file will be created
19-
LOG_PATH =
18+
# Absolute path to the directory where log files are saved. If not given, no
19+
# log file will be created
20+
LOG_DIR =
2021

2122
# Whether studies require admin approval to be made available
2223
REQUIRE_APPROVAL = True

qiita_core/tests/test_configuration_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_init(self):
4444
self.assertEqual(obs.conf_fp, self.conf_fp)
4545
self.assertTrue(obs.test_environment)
4646
self.assertEqual(obs.base_data_dir, "/tmp/")
47-
self.assertEqual(obs.log_path, "/tmp/qiita.log")
47+
self.assertEqual(obs.log_dir, "/tmp/")
4848
self.assertEqual(obs.base_url, "https://localhost")
4949
self.assertEqual(obs.max_upload_size, 100)
5050
self.assertTrue(obs.require_approval)
@@ -201,7 +201,7 @@ def test_get_portal(self):
201201
TEST_ENVIRONMENT = TRUE
202202
203203
# Absolute path to write log file to. If not given, no log file will be created
204-
LOG_PATH = /tmp/qiita.log
204+
LOG_DIR = /tmp/
205205
206206
# Whether studies require admin approval to be made available
207207
REQUIRE_APPROVAL = True

scripts/qiita

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,9 @@ def start(port, master):
418418
r_client.delete('qiita-usernames')
419419
r_client.zadd('qiita-usernames', **{u: 0 for u in qdb.user.User.iter()})
420420

421-
if qiita_config.log_path:
422-
options.log_file_prefix = qiita_config.log_path
421+
if qiita_config.log_dir:
422+
options.log_file_prefix = join(qiita_config.log_dir,
423+
'qiita_%d.log' % port)
423424
options.logging = 'debug'
424425
parse_command_line()
425426
ssl_options = {"certfile": qiita_config.certificate_file,

0 commit comments

Comments
 (0)