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-log-collector

A log rotation was introduced in order to compress old logs.

Bug-Url: https://bugzilla.redhat.com/1009116
Change-Id: If180bb3c425d94449236147cddc17c504bf602b7
Signed-off-by: Sandro Bonazzola <sbona...@redhat.com>
---
M .gitignore
M configure.ac
M ovirt-log-collector.spec.in
M src/Makefile.am
M src/__main__.py
M src/config.py.in.in
A src/logrotate.d/Makefile.am
A src/logrotate.d/ovirt-log-collector.in
8 files changed, 85 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-log-collector 
refs/changes/05/19405/1

diff --git a/.gitignore b/.gitignore
index 159972c..be191f4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,3 +20,5 @@
 *.pyc
 *.pyo
 *~
+src/config.py.in
+src/logrotate.d/ovirt-log-collector
diff --git a/configure.ac b/configure.ac
index 612f346..25f3897 100644
--- a/configure.ac
+++ b/configure.ac
@@ -82,6 +82,7 @@
        src/sos/plugins/Makefile
        src/helper/Makefile
        intl/Makefile
+       src/logrotate.d/Makefile
        po/Makefile.in
 ])
 AC_OUTPUT
diff --git a/ovirt-log-collector.spec.in b/ovirt-log-collector.spec.in
index 004ca56..124760b 100644
--- a/ovirt-log-collector.spec.in
+++ b/ovirt-log-collector.spec.in
@@ -32,6 +32,7 @@
 Requires:      python-dateutil
 Requires:      python-lxml
 Requires:      ovirt-engine-sdk
+Requires:      logrotate
 Requires:      sos
 BuildRequires: python2-devel
 
@@ -54,7 +55,9 @@
 %files
 %doc AUTHORS
 %doc COPYING
+%dir %{_localstatedir}/log/ovirt-engine/%{package_name}
 %config(noreplace) %{_sysconfdir}/ovirt-engine/logcollector.conf
+%config(noreplace) %{_sysconfdir}/logrotate.d/%{package_name}
 %{python_sitelib}/ovirt_log_collector/*.py*
 %{python_sitelib}/ovirt_log_collector/helper/*.py*
 %{python_sitelib}/sos/plugins/*.py*
diff --git a/src/Makefile.am b/src/Makefile.am
index 5ace643..b73a690 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -32,7 +32,11 @@
        $(top_srcdir)/configure.ac \
        $(NULL)
 
-SUBDIRS = sos helper
+SUBDIRS = \
+       sos \
+       helper \
+       logrotate.d \
+       $(NULL)
 
 ovirtlogcollectorlib_PYTHON = \
        config.py\
@@ -61,6 +65,7 @@
 
 install-data-hook:
        $(MKDIR_P) "$(DESTDIR)$(bindir)"
+       $(MKDIR_P) "$(DESTDIR)$(localstatedir)/log/ovirt-engine/$(PACKAGE_NAME)"
        chmod a+x "$(DESTDIR)$(ovirtlogcollectorlibdir)/__main__.py"
        rm -f "$(DESTDIR)$(bindir)/engine-log-collector"
        $(LN_S) "$(ovirtlogcollectorlibdir)/__main__.py" 
"$(DESTDIR)$(bindir)/engine-log-collector"
diff --git a/src/__main__.py b/src/__main__.py
index 93e3a94..3b48561 100755
--- a/src/__main__.py
+++ b/src/__main__.py
@@ -39,10 +39,23 @@
 from ovirt_log_collector import config
 
 STREAM_LOG_FORMAT = '%(levelname)s: %(message)s'
-FILE_LOG_FORMAT = \
-    '%(asctime)s::%(levelname)s::%(module)s::%(lineno)d::%(name)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'),
+    )
+)
+
 DEFAULT_SSH_USER = 'root'
 DEFAULT_TIME_SHIFT_FILE = 'time_diff.txt'
 PGPASS_FILE_ADMIN_LINE = "DB ADMIN credentials"
@@ -1193,11 +1206,9 @@
     parser.add_option(
         "", "--log-file",
         dest="log_file",
-        help="path to log file (default=%s)" % (
-            config.DEFAULT_LOG_FILE
-        ),
+        help="path to log file (default=%s)" % DEFAULT_LOG_FILE,
         metavar="PATH",
-        default=config.DEFAULT_LOG_FILE
+        default=DEFAULT_LOG_FILE
     )
 
     parser.add_option(
diff --git a/src/config.py.in.in b/src/config.py.in.in
index 39a1704..5e06237 100644
--- a/src/config.py.in.in
+++ b/src/config.py.in.in
@@ -2,6 +2,8 @@
 Paths and version constants for @PACKAGE_NAME@
 """
 
+import os
+
 PACKAGE_NAME = "@PACKAGE_NAME@"
 PACKAGE_VERSION = "@PACKAGE_VERSION@"
 
@@ -10,5 +12,10 @@
 DEFAULT_CA_PEM = "@sysconfdir_POST@/pki/ovirt-engine/ca.pem"
 DEFAULT_SSH_KEY = "@sysconfdir_POST@/pki/ovirt-engine/keys/engine_id_rsa"
 DEFAULT_CONFIGURATION_FILE = "@engineconfigdir_POST@/logcollector.conf"
-DEFAULT_LOG_FILE = \
-    "@localstatedir_POST@/log/ovirt-engine/engine-log-collector.log"
+DEFAULT_LOG_DIR =  os.path.join(
+    '@localstatedir_POST@',
+    '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..89c16f2
--- /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-log-collector.in \
+       $(NULL)
+
+CLEANFILES = \
+       ovirt-log-collector \
+       $(NULL)
+
+nodist_logrotate_DATA= \
+       ovirt-log-collector \
+       $(NULL)
+
+logrotatedir=$(sysconfdir)/logrotate.d
+
+ovirt-log-collector: ovirt-log-collector.in
+       $(SED) \
+       -e 's|@localstatedir[@]|$(localstatedir)|g' \
+       -e 's|@PACKAGE_NAME[@]|$(PACKAGE_NAME)|g' < $< > $@
diff --git a/src/logrotate.d/ovirt-log-collector.in 
b/src/logrotate.d/ovirt-log-collector.in
new file mode 100644
index 0000000..74b2708
--- /dev/null
+++ b/src/logrotate.d/ovirt-log-collector.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/19405
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If180bb3c425d94449236147cddc17c504bf602b7
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-log-collector
Gerrit-Branch: ovirt-log-collector-3.2
Gerrit-Owner: Sandro Bonazzola <sbona...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to