Sandro Bonazzola has uploaded a new change for review. Change subject: log: default logging to timestamped files ......................................................................
log: default logging to timestamped files Log messages to timestamped files as default, avoiding to overwrite existing ones. The default location of the logs was changed, to improve /var/log/ovirt-engine sanity. /var/log/ovirt-engine -> /var/log/ovirt-engine/ovirt-iso-uploader A log rotation was introduced in order to compress old logs. Bug-Url: https://bugzilla.redhat.com/1009115 Change-Id: I55f8d7061ea3a2f112ca602a954b87fec705baa8 Signed-off-by: Sandro Bonazzola <[email protected]> --- M .gitignore M configure.ac M ovirt-iso-uploader.spec.in M src/Makefile.am M src/__main__.py A src/config.py.in A src/logrotate.d/Makefile.am A src/logrotate.d/ovirt-iso-uploader.in 8 files changed, 104 insertions(+), 8 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-iso-uploader refs/changes/92/19392/1 diff --git a/.gitignore b/.gitignore index 80b19ea..f08ab1e 100644 --- a/.gitignore +++ b/.gitignore @@ -13,10 +13,10 @@ config.rpath config.sub ABOUT-NLS - intl tmp.* *.pyc *.pyo *~ +src/logrotate.d/ovirt-iso-uploader diff --git a/configure.ac b/configure.ac index 2c26224..ef2bec3 100644 --- a/configure.ac +++ b/configure.ac @@ -76,6 +76,7 @@ ovirt-iso-uploader.spec src/Makefile intl/Makefile + src/logrotate.d/Makefile po/Makefile.in ]) AC_OUTPUT diff --git a/ovirt-iso-uploader.spec.in b/ovirt-iso-uploader.spec.in index 86d5bd1..0e0d922 100644 --- a/ovirt-iso-uploader.spec.in +++ b/ovirt-iso-uploader.spec.in @@ -31,6 +31,7 @@ Requires: python Requires: ovirt-engine-sdk >= 3.2.0.10-1 BuildRequires: gettext-devel +Requires: logrotate BuildRequires: python2-devel %description @@ -53,7 +54,9 @@ %files %doc AUTHORS %doc COPYING +%dir %{_localstatedir}/log/ovirt-engine/%{package_name} %config(noreplace) %{_sysconfdir}/ovirt-engine/isouploader.conf +%config(noreplace) %{_sysconfdir}/logrotate.d/%{package_name} %{python_sitelib}/ovirt_iso_uploader/*.py* %{_bindir}/engine-iso-uploader %{_mandir}/man8/* diff --git a/src/Makefile.am b/src/Makefile.am index f8b225d..000dc1d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -22,12 +22,25 @@ $(NULL) EXTRA_DIST = \ + config.py.in \ isodomain.xml \ + $(NULL) + +CLEANFILES = \ + config.py \ + $(NULL) + +SUBDIRS = \ + logrotate.d \ $(NULL) dist_ovirtisouploaderlib_PYTHON = \ __init__.py \ __main__.py \ + $(NULL) + +nodist_ovirtisouploaderlib_PYTHON = \ + config.py \ $(NULL) dist_man_MANS = \ @@ -37,6 +50,11 @@ dist_engineconfig_DATA = \ isouploader.conf \ $(NULL) + +config.py: config.py.in + $(SED) \ + -e 's|@localstatedir[@]|$(localstatedir)|g' \ + -e 's|@PACKAGE_NAME[@]|$(PACKAGE_NAME)|g' < $< > $@ all-local: \ python-syntax-check \ @@ -48,6 +66,7 @@ install-data-hook: $(MKDIR_P) "$(DESTDIR)$(bindir)" + $(MKDIR_P) "$(DESTDIR)$(localstatedir)/log/ovirt-engine/$(PACKAGE_NAME)" chmod a+x "$(DESTDIR)$(ovirtisouploaderlibdir)/__main__.py" rm -f "$(DESTDIR)$(bindir)/engine-iso-uploader" $(LN_S) "$(ovirtisouploaderlibdir)/__main__.py" "$(DESTDIR)$(bindir)/engine-iso-uploader" diff --git a/src/__main__.py b/src/__main__.py index d530ca3..be444c3 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -25,6 +25,7 @@ import gettext import traceback import tempfile +import time import shutil from pwd import getpwnam import getpass @@ -33,15 +34,10 @@ from ovirtsdk.infrastructure.errors import ConnectionError from ovirtsdk.infrastructure.errors import NoCertificatesError +from ovirt_iso_uploader import config APP_NAME = "ovirt-iso-uploader" VERSION = "1.0.0" -STREAM_LOG_FORMAT = '%(levelname)s: %(message)s' -FILE_LOG_FORMAT = ( - '%(asctime)s::%(levelname)s::%(module)s::%(lineno)d::%(name)s:: ' - '%(message)s' -) -FILE_LOG_DSTMP = '%Y-%m-%d %H:%M:%S' DEFAULT_IMAGES_DIR = 'images/11111111-1111-1111-1111-111111111111' NFS_MOUNT_OPTS = '-t nfs -o rw,sync,soft' NFS_UMOUNT_OPTS = '-t nfs -f ' @@ -59,10 +55,27 @@ CHMOD = '/bin/chmod' TEST = '/usr/bin/test' DEFAULT_CONFIGURATION_FILE = '/etc/ovirt-engine/isouploader.conf' -DEFAULT_LOG_FILE = '/var/log/ovirt-engine/engine-iso-uploader.log' PERMS_MASK = '640' PYTHON = '/usr/bin/python' +STREAM_LOG_FORMAT = '%(levelname)s: %(message)s' +FILE_LOG_FORMAT = ( + '%(asctime)s::' + '%(levelname)s::' + '%(module)s::' + '%(lineno)d::' + '%(name)s::' + ' %(message)s' +) +FILE_LOG_DSTMP = '%Y-%m-%d %H:%M:%S' +DEFAULT_LOG_FILE = os.path.join( + config.DEFAULT_LOG_DIR, + '{prefix}-{timestamp}.log'.format( + prefix=config.LOG_PREFIX, + timestamp=time.strftime('%Y%m%d%H%M%S'), + ) +) + def multilog(logger, msg): for line in str(msg).splitlines(): diff --git a/src/config.py.in b/src/config.py.in new file mode 100644 index 0000000..c81ce88 --- /dev/null +++ b/src/config.py.in @@ -0,0 +1,14 @@ +""" +Configuration for @PACKAGE_NAME@ +""" + +import os + +PACKAGE_NAME = '@PACKAGE_NAME@' +DEFAULT_LOG_DIR = os.path.join( + '@localstatedir@', + 'log', + 'ovirt-engine', + PACKAGE_NAME, +) +LOG_PREFIX = PACKAGE_NAME diff --git a/src/logrotate.d/Makefile.am b/src/logrotate.d/Makefile.am new file mode 100644 index 0000000..7f818a9 --- /dev/null +++ b/src/logrotate.d/Makefile.am @@ -0,0 +1,39 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +MAINTAINERCLEANFILES = \ + $(srcdir)/Makefile.in \ + $(NULL) + +EXTRA_DIST = \ + ovirt-iso-uploader.in \ + $(NULL) + +CLEANFILES = \ + ovirt-iso-uploader \ + $(NULL) + +nodist_logrotate_DATA= \ + ovirt-iso-uploader \ + $(NULL) + +logrotatedir=$(sysconfdir)/logrotate.d + +ovirt-iso-uploader: ovirt-iso-uploader.in + $(SED) \ + -e 's|@localstatedir[@]|$(localstatedir)|g' \ + -e 's|@PACKAGE_NAME[@]|$(PACKAGE_NAME)|g' < $< > $@ diff --git a/src/logrotate.d/ovirt-iso-uploader.in b/src/logrotate.d/ovirt-iso-uploader.in new file mode 100644 index 0000000..74b2708 --- /dev/null +++ b/src/logrotate.d/ovirt-iso-uploader.in @@ -0,0 +1,7 @@ +@localstatedir@/log/ovirt-engine/@PACKAGE_NAME@/*.log { + monthly + missingok + compress + nocreate + rotate 1 +} -- To view, visit http://gerrit.ovirt.org/19392 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I55f8d7061ea3a2f112ca602a954b87fec705baa8 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-iso-uploader Gerrit-Branch: ovirt-iso-uploader-3.2 Gerrit-Owner: Sandro Bonazzola <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
