Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use rotating log files #437

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions ramp-engine/ramp_engine/aws/worker.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import logging
from logging.handlers import RotatingFileHandler
import os

from ..base import BaseWorker, _get_traceback
from . import api as aws


log_dir = "logs"
if not os.path.exists(log_dir):
os.makedirs(log_dir)

logger = logging.getLogger('RAMP-AWS')

log_file = 'aws_worker.log'
log_file = os.path.join(log_dir, 'aws_worker.log')
formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s %(message)s') # noqa
fileHandler = logging.FileHandler(log_file, mode='a')
fileHandler = RotatingFileHandler(log_file, maxBytes=1000, backupCount=2)
fileHandler.setFormatter(formatter)
streamHandler = logging.StreamHandler()
streamHandler.setFormatter(formatter)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

streamHandler -> stream_handler

Expand Down
10 changes: 8 additions & 2 deletions ramp-engine/ramp_engine/base.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import logging
from logging.handlers import RotatingFileHandler
import os
from abc import ABCMeta, abstractmethod

log_dir = "logs"
Copy link
Collaborator

@rth rth Oct 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we make this configurable somehow?
The issue is that this log folder will depend on the location from which we run a script as far as I understand (and also happens at import). It might be better to have a function that is called as necessary that takes as input a config object and returns this logger. Not sure how easy that would be though.

if not os.path.exists(log_dir):
os.makedirs(log_dir)

logger = logging.getLogger('RAMP-WORKER')

log_file = "worker.log"
log_file = os.path.join(log_dir, "worker.log")
formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s %(message)s') # noqa
fileHandler = logging.FileHandler(log_file, mode='a')
fileHandler = RotatingFileHandler(log_file, maxBytes=1000, backupCount=2)
fileHandler.setFormatter(formatter)
streamHandler = logging.StreamHandler()
streamHandler.setFormatter(formatter)
Expand Down
9 changes: 7 additions & 2 deletions ramp-engine/ramp_engine/dispatcher.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from logging.handlers import RotatingFileHandler
import multiprocessing
import numbers
import os
Expand Down Expand Up @@ -30,11 +31,15 @@

from .local import CondaEnvWorker

log_dir = "logs"
if not os.path.exists(log_dir):
os.makedirs(log_dir)

logger = logging.getLogger('RAMP-DISPATCHER')

log_file = 'dispatcher.log'
log_file = os.path.join(log_dir, 'dispatcher.log')
formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s %(message)s') # noqa
fileHandler = logging.FileHandler(log_file, mode='a')
fileHandler = RotatingFileHandler(log_file, maxBytes=1000, backupCount=2)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fileHandler = RotatingFileHandler(log_file, maxBytes=1000, backupCount=2)
file_handler = RotatingFileHandler(log_file, maxBytes=1000, backupCount=2)

fileHandler.setFormatter(formatter)
streamHandler = logging.StreamHandler()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
streamHandler = logging.StreamHandler()
stream_handler = logging.StreamHandler()

streamHandler.setFormatter(formatter)
Expand Down