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-image-uploader A log rotation was introduced in order to compress old logs. Bug-Url: https://bugzilla.redhat.com/1016651 Change-Id: I01957d865f437636c0f1bf794075ee6a3895b94e Signed-off-by: Sandro Bonazzola <[email protected]> --- M .gitignore M configure.ac M ovirt-image-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-image-uploader.in 8 files changed, 104 insertions(+), 6 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-image-uploader refs/changes/90/19990/1 diff --git a/.gitignore b/.gitignore index ae2e974..da6000f 100644 --- a/.gitignore +++ b/.gitignore @@ -15,8 +15,8 @@ ABOUT-NLS intl - tmp.* *.pyc *.pyo *~ +src/config.py diff --git a/configure.ac b/configure.ac index 6a4f4c6..c439f7e 100644 --- a/configure.ac +++ b/configure.ac @@ -75,6 +75,7 @@ Makefile ovirt-image-uploader.spec src/Makefile + src/logrotate.d/Makefile src/ovf/Makefile intl/Makefile po/Makefile.in diff --git a/ovirt-image-uploader.spec.in b/ovirt-image-uploader.spec.in index ff67686..76179a3 100644 --- a/ovirt-image-uploader.spec.in +++ b/ovirt-image-uploader.spec.in @@ -30,6 +30,7 @@ BuildArch: noarch Requires: python Requires: ovirt-engine-sdk +Requires: logrotate BuildRequires: python2-devel %description @@ -51,7 +52,9 @@ %files %doc AUTHORS %doc COPYING +%dir %{_localstatedir}/log/ovirt-engine/%{package_name} %config(noreplace) %{_sysconfdir}/ovirt-engine/imageuploader.conf +%config(noreplace) %{_sysconfdir}/logrotate.d/%{package_name} %{python_sitelib}/ovirt_image_uploader/*.py* %{python_sitelib}/ovirt_image_uploader/ovf/*.py* %{_bindir}/engine-image-uploader diff --git a/src/Makefile.am b/src/Makefile.am index 6274c48..af64be4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -22,14 +22,26 @@ $(NULL) EXTRA_DIST = \ + config.py.in \ sample.ovf \ $(NULL) -SUBDIRS = ovf +CLEANFILES = \ + config.py \ + $(NULL) + +SUBDIRS = \ + ovf \ + logrotate.d \ + $(NULL) dist_ovirtimageuploaderlib_PYTHON = \ __init__.py \ __main__.py \ + $(NULL) + +nodist_ovirtimageuploaderlib_PYTHON = \ + config.py \ $(NULL) dist_man_MANS = \ @@ -39,6 +51,11 @@ dist_engineconfig_DATA = \ imageuploader.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 \ @@ -50,6 +67,7 @@ install-data-hook: $(MKDIR_P) "$(DESTDIR)$(bindir)" + $(MKDIR_P) "$(DESTDIR)$(localstatedir)/log/ovirt-engine/$(PACKAGE_NAME)" chmod a+x "$(DESTDIR)$(ovirtimageuploaderlibdir)/__main__.py" rm -f "$(DESTDIR)$(bindir)/engine-image-uploader" $(LN_S) "$(ovirtimageuploaderlibdir)/__main__.py" "$(DESTDIR)$(bindir)/engine-image-uploader" diff --git a/src/__main__.py b/src/__main__.py index b4d4354..ce6d5ee 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -22,6 +22,7 @@ from pwd import getpwnam import getpass import tarfile +import time from lxml import etree from ovf import ovfenvelope from ovf.ovfenvelope import * @@ -29,12 +30,10 @@ from ovirtsdk.xml import params from ovirtsdk.infrastructure.errors import RequestError, ConnectionError, NoCertificatesError +from ovirt_image_uploader import config APP_NAME = "engine-image-uploader" -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' NFS_MOUNT_OPTS = '-t nfs -o rw,sync,soft' NFS_UMOUNT_OPTS = '-t nfs -f ' NFS_USER = 'vdsm' @@ -42,7 +41,24 @@ MOUNT='/bin/mount' UMOUNT='/bin/umount' DEFAULT_CONFIGURATION_FILE='/etc/ovirt-engine/imageuploader.conf' -DEFAULT_LOG_FILE='/var/log/ovirt-engine/engine-image-uploader.log' + +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..68fddf7 --- /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-image-uploader.in \ + $(NULL) + +CLEANFILES = \ + ovirt-image-uploader \ + $(NULL) + +nodist_logrotate_DATA= \ + ovirt-image-uploader \ + $(NULL) + +logrotatedir=$(sysconfdir)/logrotate.d + +ovirt-image-uploader: ovirt-image-uploader.in + $(SED) \ + -e 's|@localstatedir[@]|$(localstatedir)|g' \ + -e 's|@PACKAGE_NAME[@]|$(PACKAGE_NAME)|g' < $< > $@ diff --git a/src/logrotate.d/ovirt-image-uploader.in b/src/logrotate.d/ovirt-image-uploader.in new file mode 100644 index 0000000..74b2708 --- /dev/null +++ b/src/logrotate.d/ovirt-image-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/19990 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I01957d865f437636c0f1bf794075ee6a3895b94e Gerrit-PatchSet: 1 Gerrit-Project: ovirt-image-uploader Gerrit-Branch: ovirt-image-uploader-3.2 Gerrit-Owner: Sandro Bonazzola <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
