Configurable logrotate in agent

Story: 2000997
Task: 4179

Change-Id: I2e38b1f0a94209c4d38b50e192b35a141b582424
This commit is contained in:
Michael Worley 2017-04-19 16:48:31 -07:00
parent 41f71b63eb
commit 730b77a637
4 changed files with 12 additions and 5 deletions

View File

@ -140,6 +140,7 @@ Logging:
collector_log_file: {args.log_dir}/collector.log
forwarder_log_file: {args.log_dir}/forwarder.log
statsd_log_file: {args.log_dir}/statsd.log
enable_logrotate: {args.enable_logrotate}
# if syslog is enabled but a host and port are not set, a local domain socket
# connection will be attempted

View File

@ -1,4 +1,4 @@
# (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
# (C) Copyright 2015-2017 Hewlett Packard Enterprise Development LP
import logging
import os
@ -82,6 +82,7 @@ class Config(object):
'forwarder_log_file': DEFAULT_LOG_DIR + '/forwarder.log',
'statsd_log_file': DEFAULT_LOG_DIR + '/statsd.log',
'jmxfetch_log_file': DEFAULT_LOG_DIR + '/jmxfetch.log',
'enable_logrotate': True,
'log_to_event_viewer': False,
'log_to_syslog': False,
'syslog_host': None,

View File

@ -1,4 +1,4 @@
# (C) Copyright 2015-2016 Hewlett Packard Enterprise Development Company LP
# (C) Copyright 2015-2017 Hewlett Packard Enterprise Development LP
import glob
import hashlib
@ -613,8 +613,12 @@ def initialize_logging(logger_name):
# make sure the log directory is writable
# NOTE: the entire directory needs to be writable so that rotation works
if os.access(os.path.dirname(log_file), os.R_OK | os.W_OK):
file_handler = logging.handlers.RotatingFileHandler(
log_file, maxBytes=LOGGING_MAX_BYTES, backupCount=1)
if logging_config['enable_logrotate']:
file_handler = logging.handlers.RotatingFileHandler(
log_file, maxBytes=LOGGING_MAX_BYTES, backupCount=1)
else:
file_handler = logging.FileHandler(log_file)
formatter = logging.Formatter(log_format, log_date_format)
file_handler.setFormatter(formatter)

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python
# (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
# (C) Copyright 2015-2017 Hewlett Packard Enterprise Development LP
""" Detect running daemons then configure and start the agent.
"""
@ -296,6 +296,7 @@ def parse_arguments(parser):
help="agent's systemd/sysv service name",
required=False,
default='monasca-agent')
parser.add_argument('--enable_logrotate', help="Controls log file rotation", default=True)
return parser.parse_args()