Skip to content

Commit

Permalink
Merge pull request #1669 from york-stsci/celery_logging_fix
Browse files Browse the repository at this point in the history
Changing celery worker logs to be daily rather than per-task
  • Loading branch information
mfixstsci authored Jan 17, 2025
2 parents 3c7e1a4 + 69dd4eb commit ecec579
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
2 changes: 1 addition & 1 deletion jwql/shared_tasks/shared_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def _caller(*args, **kwargs):


def create_task_log_handler(logger, propagate):
log_file_name = configure_logging('shared_tasks')
log_file_name = configure_logging('shared_tasks', include_time=False)
working_dir = os.path.join(get_config()['working'], 'calibrated_data')
ensure_dir_exists(working_dir)
celery_log_file_handler = FileHandler(log_file_name)
Expand Down
26 changes: 11 additions & 15 deletions jwql/utils/logging_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def filter(record):
return filter


def configure_logging(module):
def configure_logging(module, include_time=True):
"""
Configure the log file with a standard logging format. The format in question is
set up as follows:
Expand All @@ -116,11 +116,8 @@ def configure_logging(module):
----------
module : str
The name of the module being logged.
production_mode : bool
Whether or not the output should be written to the production
environement.
path : str
Where to write the log if user-supplied path; default to working dir.
include_time : bool, default True
Whether or not the file name should include the time as well as the date.
Returns
-------
Expand All @@ -129,7 +126,7 @@ def configure_logging(module):
"""

# Determine log file location
log_file = make_log_file(module)
log_file = make_log_file(module, include_time=include_time)

# Get the logging configuration dictionary
logging_config = get_config()['logging']
Expand Down Expand Up @@ -171,7 +168,7 @@ def get_log_status(log_file):
return 'FAILURE'


def make_log_file(module):
def make_log_file(module, include_time=True):
"""Create the log file name based on the module name.
The name of the ``log_file`` is a combination of the name of the
Expand All @@ -181,12 +178,8 @@ def make_log_file(module):
----------
module : str
The name of the module being logged.
production_mode : bool
Whether or not the output should be written to the production
environment.
path : str
Where to write the log if user-supplied path; default to
working dir.
include_time : bool, default True
Whether or not the file name should include the time as well as the date.
Returns
-------
Expand All @@ -195,7 +188,10 @@ def make_log_file(module):
"""

# Build filename
timestamp = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M')
if include_time:
timestamp = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M')
else:
timestamp = datetime.datetime.now().strftime('%Y-%m-%d')
hostname = socket.gethostname()
filename = '{0}_{1}_{2}.log'.format(module, hostname, timestamp)

Expand Down

0 comments on commit ecec579

Please sign in to comment.