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/998592 Change-Id: I55f8d7061ea3a2f112ca602a954b87fec705baa8 Signed-off-by: Sandro Bonazzola <sbona...@redhat.com> --- 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/01/18301/1 diff --git a/.gitignore b/.gitignore index 5c336bf..d3225de 100644 --- a/.gitignore +++ b/.gitignore @@ -13,8 +13,8 @@ config.rpath config.sub ABOUT-NLS - tmp.* *.pyc *.pyo *~ +src/logrotate.d/ovirt-iso-uploader diff --git a/configure.ac b/configure.ac index 9e7525e..78f31e2 100644 --- a/configure.ac +++ b/configure.ac @@ -75,6 +75,7 @@ Makefile ovirt-iso-uploader.spec src/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 43bc97e..b6b43f0 100644 --- a/ovirt-iso-uploader.spec.in +++ b/ovirt-iso-uploader.spec.in @@ -30,6 +30,7 @@ BuildArch: noarch Requires: python Requires: ovirt-engine-sdk >= 3.2.0.10-1 +Requires: logrotate BuildRequires: gettext BuildRequires: python2-devel @@ -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} %{_sysconfdir}/ovirt-engine/isouploader.conf.d/.keep %{python_sitelib}/ovirt_iso_uploader/*.py* %{_bindir}/ovirt-iso-uploader diff --git a/src/Makefile.am b/src/Makefile.am index d74e52e..b6ea264 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 = \ @@ -44,6 +57,11 @@ .keep \ $(NULL) +config.py: config.py.in + $(SED) \ + -e 's|@localstatedir[@]|$(localstatedir)|g' \ + -e 's|@PACKAGE_NAME[@]|$(PACKAGE_NAME)|g' < $< > $@ + all-local: \ python-syntax-check \ $(NULL) @@ -54,6 +72,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)/ovirt-iso-uploader" rm -f "$(DESTDIR)$(bindir)/engine-iso-uploader" diff --git a/src/__main__.py b/src/__main__.py index 171120f..ca6275f 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 = "3.4.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/ovirt-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/18301 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: master Gerrit-Owner: Sandro Bonazzola <sbona...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches