https://fedorahosted.org/freeipa/ticket/4501

Patch attached.
From ca3a3bd01e6990a42e2d7c809b1f698da53b04a4 Mon Sep 17 00:00:00 2001
From: Martin Basti <mba...@redhat.com>
Date: Fri, 4 Mar 2016 16:57:20 +0100
Subject: [PATCH] logging: add timestamps to log filenames

Originally installation logs were overwritten or new entries were appended.

Now logs are created with timestamp in filename, so it clear what
happens when, logs are not overwritten anymore.

https://fedorahosted.org/freeipa/ticket/4501
---
 ipaplatform/base/paths.py                | 27 +++++++++++++++------------
 ipapython/ipa_log_manager.py             |  8 ++++++++
 ipatests/test_integration/tasks.py       | 16 ++++++++--------
 ipatests/test_integration/test_caless.py |  8 ++++----
 4 files changed, 35 insertions(+), 24 deletions(-)

diff --git a/ipaplatform/base/paths.py b/ipaplatform/base/paths.py
index bdff4f3934f3250bdfef3f913631b98d55d759b6..d7a9219a098896b88f42d3a3680b4e39c389aabc 100644
--- a/ipaplatform/base/paths.py
+++ b/ipaplatform/base/paths.py
@@ -295,18 +295,21 @@ class BasePathNamespace(object):
     SLAPD_INSTANCE_ERROR_LOG_TEMPLATE = "/var/log/dirsrv/slapd-%s/errors"
     VAR_LOG_HTTPD_DIR = "/var/log/httpd"
     IPABACKUP_LOG = "/var/log/ipabackup.log"
-    IPACLIENT_INSTALL_LOG = "/var/log/ipaclient-install.log"
-    IPACLIENT_UNINSTALL_LOG = "/var/log/ipaclient-uninstall.log"
-    IPAREPLICA_CA_INSTALL_LOG = "/var/log/ipareplica-ca-install.log"
-    IPAREPLICA_CONNCHECK_LOG = "/var/log/ipareplica-conncheck.log"
-    IPAREPLICA_INSTALL_LOG = "/var/log/ipareplica-install.log"
-    IPARESTORE_LOG = "/var/log/iparestore.log"
-    IPASERVER_CA_INSTALL_LOG = "/var/log/ipaserver-ca-install.log"
-    IPASERVER_INSTALL_LOG = "/var/log/ipaserver-install.log"
-    IPASERVER_KRA_INSTALL_LOG = "/var/log/ipaserver-kra-install.log"
-    IPASERVER_KRA_UNINSTALL_LOG = "/var/log/ipaserver-kra-uninstall.log"
-    IPASERVER_UNINSTALL_LOG = "/var/log/ipaserver-uninstall.log"
-    IPAUPGRADE_LOG = "/var/log/ipaupgrade.log"
+    IPACLIENT_INSTALL_LOG = "/var/log/ipaclient-install-{timestamp}.log"
+    IPACLIENT_UNINSTALL_LOG = "/var/log/ipaclient-uninstall-{timestamp}.log"
+    IPAREPLICA_CA_INSTALL_LOG = (
+        "/var/log/ipareplica-ca-install-{timestamp}.log")
+    IPAREPLICA_CONNCHECK_LOG = "/var/log/ipareplica-conncheck-{timestamp}.log"
+    IPAREPLICA_INSTALL_LOG = "/var/log/ipareplica-install-{timestamp}.log"
+    IPARESTORE_LOG = "/var/log/iparestore-{timestamp}.log"
+    IPASERVER_CA_INSTALL_LOG = "/var/log/ipaserver-ca-install-{timestamp}.log"
+    IPASERVER_INSTALL_LOG = "/var/log/ipaserver-install-{timestamp}.log"
+    IPASERVER_KRA_INSTALL_LOG = (
+        "/var/log/ipaserver-kra-install-{timestamp}.log")
+    IPASERVER_KRA_UNINSTALL_LOG = (
+        "/var/log/ipaserver-kra-uninstall-{timestamp}.log")
+    IPASERVER_UNINSTALL_LOG = "/var/log/ipaserver-uninstall-{timestamp}.log"
+    IPAUPGRADE_LOG = "/var/log/ipaupgrade-{timestamp}.log"
     KADMIND_LOG = "/var/log/kadmind.log"
     MESSAGES = "/var/log/messages"
     VAR_LOG_PKI_DIR = "/var/log/pki/"
diff --git a/ipapython/ipa_log_manager.py b/ipapython/ipa_log_manager.py
index 8a555ebda7919214c20d40ec45b9b5f7863f0298..c36265436b88a22786d0cb4ae8fb673c5be3a116 100644
--- a/ipapython/ipa_log_manager.py
+++ b/ipapython/ipa_log_manager.py
@@ -29,6 +29,8 @@ import sys
 import re
 import copy
 
+from datetime import datetime
+
 from ipapython.log_manager import LogManager, parse_log_level
 
 #-------------------------------------------------------------------------------
@@ -62,6 +64,8 @@ LOGGING_FORMAT_STANDARD_CONSOLE = '%(name)-12s: %(levelname)-8s %(message)s'
 # Used by standard_logging_setup() for file message
 LOGGING_FORMAT_STANDARD_FILE = '%(asctime)s %(levelname)s %(message)s'
 
+FILENAME_TIMESTAMP_FORMAT = '%Y%m%d%H%M'
+
 #-------------------------------------------------------------------------------
 
 class IPALogManager(LogManager):
@@ -175,6 +179,10 @@ def standard_logging_setup(filename=None, verbose=False, debug=False,
         filemode='w', console_format=LOGGING_FORMAT_STANDARD_CONSOLE):
     handlers = []
 
+    if filename:
+        filename = filename.format(
+            timestamp=datetime.now().strftime(FILENAME_TIMESTAMP_FORMAT))
+
     # File output is always logged at debug level
     if filename is not None:
         file_handler = dict(name='file',
diff --git a/ipatests/test_integration/tasks.py b/ipatests/test_integration/tasks.py
index ad2eab218272cc19d208b788d518910821ce5a8a..ead038c8891e23bc8ce98a4447404ca27fef64a4 100644
--- a/ipatests/test_integration/tasks.py
+++ b/ipatests/test_integration/tasks.py
@@ -225,8 +225,8 @@ def enable_replication_debugging(host):
 
 
 def install_master(host, setup_dns=True, setup_kra=False):
-    host.collect_log(paths.IPASERVER_INSTALL_LOG)
-    host.collect_log(paths.IPACLIENT_INSTALL_LOG)
+    host.collect_log(paths.IPASERVER_INSTALL_LOG.format(timestamp='*'))
+    host.collect_log(paths.IPACLIENT_INSTALL_LOG.format(timestamp='*'))
     inst = host.domain.realm.replace('.', '-')
     host.collect_log(paths.SLAPD_INSTANCE_ERROR_LOG_TEMPLATE % inst)
     host.collect_log(paths.SLAPD_INSTANCE_ACCESS_LOG_TEMPLATE % inst)
@@ -308,8 +308,8 @@ def replica_prepare(master, replica):
 
 def install_replica(master, replica, setup_ca=True, setup_dns=False,
                     setup_kra=False):
-    replica.collect_log(paths.IPAREPLICA_INSTALL_LOG)
-    replica.collect_log(paths.IPAREPLICA_CONNCHECK_LOG)
+    replica.collect_log(paths.IPAREPLICA_INSTALL_LOG.format(timestamp='*'))
+    replica.collect_log(paths.IPAREPLICA_CONNCHECK_LOG.format(timestamp='*'))
     allow_sync_ptr(master)
     # Otherwise ipa-client-install would not create a PTR
     # and replica installation would fail
@@ -354,7 +354,7 @@ def install_replica(master, replica, setup_ca=True, setup_dns=False,
 
 
 def install_client(master, client, extra_args=()):
-    client.collect_log(paths.IPACLIENT_INSTALL_LOG)
+    client.collect_log(paths.IPACLIENT_INSTALL_LOG.format(timestamp='*'))
 
     apply_common_fixes(client)
     allow_sync_ptr(master)
@@ -385,7 +385,7 @@ def install_adtrust(host):
     """
 
     # ipa-adtrust-install appends to ipaserver-install.log
-    host.collect_log(paths.IPASERVER_INSTALL_LOG)
+    host.collect_log(paths.IPASERVER_INSTALL_LOG.format(timestamp='*'))
 
     inst = host.domain.realm.replace('.', '-')
     host.collect_log(paths.SLAPD_INSTANCE_ERROR_LOG_TEMPLATE % inst)
@@ -663,7 +663,7 @@ def kinit_admin(host):
 
 
 def uninstall_master(host, ignore_topology_disconnect=True):
-    host.collect_log(paths.IPASERVER_UNINSTALL_LOG)
+    host.collect_log(paths.IPASERVER_UNINSTALL_LOG.format(timestamp='*'))
     uninstall_cmd = ['ipa-server-install', '--uninstall', '-U']
 
     host_domain_level = domainlevel(host)
@@ -686,7 +686,7 @@ def uninstall_master(host, ignore_topology_disconnect=True):
 
 
 def uninstall_client(host):
-    host.collect_log(paths.IPACLIENT_UNINSTALL_LOG)
+    host.collect_log(paths.IPACLIENT_UNINSTALL_LOG.format(timestamp='*'))
 
     host.run_command(['ipa-client-install', '--uninstall', '-U'],
                      raiseonerr=False)
diff --git a/ipatests/test_integration/test_caless.py b/ipatests/test_integration/test_caless.py
index fdc4fc8efe73631e9ab03f3b9019444f7d7e09ec..a5dc135259d074ab766fd8718956949b951c1963 100644
--- a/ipatests/test_integration/test_caless.py
+++ b/ipatests/test_integration/test_caless.py
@@ -140,8 +140,8 @@ class CALessBase(IntegrationTest):
         for filename in set(files_to_copy):
             cls.copy_cert(host, filename)
 
-        host.collect_log(paths.IPASERVER_INSTALL_LOG)
-        host.collect_log(paths.IPACLIENT_INSTALL_LOG)
+        host.collect_log(paths.IPASERVER_INSTALL_LOG.format(timestamp='*'))
+        host.collect_log(paths.IPACLIENT_INSTALL_LOG.format(timestamp='*'))
         inst = host.domain.realm.replace('.', '-')
         host.collect_log(paths.SLAPD_INSTANCE_ERROR_LOG_TEMPLATE % inst)
         host.collect_log(paths.SLAPD_INSTANCE_ACCESS_LOG_TEMPLATE % inst)
@@ -211,8 +211,8 @@ class CALessBase(IntegrationTest):
                 os.path.join(self.cert_dir, filename),
                 os.path.join(master.config.test_dir, filename))
 
-        replica.collect_log(paths.IPAREPLICA_INSTALL_LOG)
-        replica.collect_log(paths.IPACLIENT_INSTALL_LOG)
+        replica.collect_log(paths.IPAREPLICA_INSTALL_LOG.format(timestamp='*'))
+        replica.collect_log(paths.IPACLIENT_INSTALL_LOG.format(timestamp='*'))
         inst = replica.domain.realm.replace('.', '-')
         replica.collect_log(paths.SLAPD_INSTANCE_ERROR_LOG_TEMPLATE % inst)
         replica.collect_log(paths.SLAPD_INSTANCE_ACCESS_LOG_TEMPLATE % inst)
-- 
2.5.0

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to