[graphite-web] Disable internal log rotation and use system logrotate

Jamie Nguyen jamielinux at fedoraproject.org
Wed Oct 1 13:56:11 UTC 2014


commit 0ac86517aabfc84366a18c77b3c03201156af64d
Author: Jamie Nguyen <j at jamielinux.com>
Date:   Wed Oct 1 13:19:46 2014 +0100

    Disable internal log rotation and use system logrotate

 ...-web-0.9.12-Disable-internal-log-rotation.patch |   53 ++++++++++++++++++++
 graphite-web.logrotate                             |    9 +++
 graphite-web.spec                                  |   37 +++++++++++++-
 3 files changed, 96 insertions(+), 3 deletions(-)
---
diff --git a/graphite-web-0.9.12-Disable-internal-log-rotation.patch b/graphite-web-0.9.12-Disable-internal-log-rotation.patch
new file mode 100644
index 0000000..d13e01c
--- /dev/null
+++ b/graphite-web-0.9.12-Disable-internal-log-rotation.patch
@@ -0,0 +1,53 @@
+From cf80c6dc8f8f70d542d140703e49b704e718e685 Mon Sep 17 00:00:00 2001
+From: Jamie Nguyen <j at jamielinux.com>
+Date: Tue, 30 Sep 2014 11:46:14 +0100
+Subject: [PATCH] Disable internal log rotation
+
+---
+ webapp/graphite/logger.py | 12 ++++++------
+ 1 file changed, 6 insertions(+), 6 deletions(-)
+
+diff --git a/webapp/graphite/logger.py b/webapp/graphite/logger.py
+index afa43f4..d617520 100644
+--- a/webapp/graphite/logger.py
++++ b/webapp/graphite/logger.py
+@@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
+ limitations under the License."""
+ 
+ import os, logging
+-from logging.handlers import TimedRotatingFileHandler as Rotater
++from logging import FileHandler
+ from django.conf import settings
+ 
+ logging.addLevelName(30,"rendering")
+@@ -37,22 +37,22 @@ class GraphiteLogger:
+     self.metricAccessLogger = logging.getLogger("metric_access")
+     #Setup formatter & handlers
+     self.formatter = logging.Formatter("%(asctime)s :: %(message)s","%a %b %d %H:%M:%S %Y")
+-    self.infoHandler = Rotater(self.infoLogFile,when="midnight",backupCount=1)
++    self.infoHandler = FileHandler(self.infoLogFile)
+     self.infoHandler.setFormatter(self.formatter)
+     self.infoLogger.addHandler(self.infoHandler)
+-    self.exceptionHandler = Rotater(self.exceptionLogFile,when="midnight",backupCount=1)
++    self.exceptionHandler = FileHandler(self.exceptionLogFile)
+     self.exceptionHandler.setFormatter(self.formatter)
+     self.exceptionLogger.addHandler(self.exceptionHandler)
+     if settings.LOG_CACHE_PERFORMANCE:
+-      self.cacheHandler = Rotater(self.cacheLogFile,when="midnight",backupCount=1)
++      self.cacheHandler = FileHandler(self.cacheLogFile)
+       self.cacheHandler.setFormatter(self.formatter)
+       self.cacheLogger.addHandler(self.cacheHandler)
+     if settings.LOG_RENDERING_PERFORMANCE:
+-      self.renderingHandler = Rotater(self.renderingLogFile,when="midnight",backupCount=1)
++      self.renderingHandler = FileHandler(self.renderingLogFile)
+       self.renderingHandler.setFormatter(self.formatter)
+       self.renderingLogger.addHandler(self.renderingHandler)
+     if settings.LOG_METRIC_ACCESS:
+-      self.metricAccessHandler = Rotater(self.metricAccessLogFile,when="midnight",backupCount=10)
++      self.metricAccessHandler = FileHandler(self.metricAccessLogFile)
+       self.metricAccessHandler.setFormatter(self.formatter)
+       self.metricAccessLogger.addHandler(self.metricAccessHandler)
+ 
+-- 
+1.9.3
+
diff --git a/graphite-web.logrotate b/graphite-web.logrotate
new file mode 100644
index 0000000..0642b1b
--- /dev/null
+++ b/graphite-web.logrotate
@@ -0,0 +1,9 @@
+/var/log/graphite-web/*.log {
+    notifempty
+    copytruncate
+    missingok
+    notifempty
+    daily
+    compress
+    delaycompress
+}
diff --git a/graphite-web.spec b/graphite-web.spec
index 2a027a1..79b7941 100644
--- a/graphite-web.spec
+++ b/graphite-web.spec
@@ -2,6 +2,13 @@
 
 %global commit 28cc7276784bcc4d8a1be6854a6add1145ec4109
 
+# Migrated to system log rotation on Fedora 21 and EPEL 7.
+%if 0%{?fedora} >= 21 || 0%{?rhel} >= 7
+%global with_system_logrotate 1
+%else
+%global with_system_logrotate 0
+%endif
+
 Name:           graphite-web
 Version:        0.9.12
 Release:        7%{?dist}
@@ -15,6 +22,7 @@ Source0:        https://github.com/graphite-project/graphite-web/archive/%{commi
 Source1:        graphite-web-vhost.conf
 Source2:        graphite-web-README.fedora
 Source3:        graphite-web-README.selinux
+Source10:       %{name}.logrotate
 Patch0:         %{name}-0.9.12-Amend-default-filesystem-locations.patch
 Patch1:         %{name}-0.9.12-Force-use-of-system-libraries.patch
 Patch2:         %{name}-0.9.12-carbonlink-exception-log.patch
@@ -22,14 +30,23 @@ Patch3:         %{name}-0.9.12-dashboard-load.patch
 Patch4:         %{name}-0.9.12-safe-unpickle-deque-addition.patch
 Patch5:         %{name}-0.9.12-Fix-build-index.sh-variables.patch
 Patch6:         %{name}-0.9.12-Changes-for-django-1.5.patch
+Patch7:         %{name}-0.9.12-Disable-internal-log-rotation.patch
 
 BuildRoot:      %{_tmppath}/graphite-web-%{version}-%{release}-root-%(%{__id_u} -n)
 BuildArch:      noarch
 BuildRequires:  python-devel
-Requires:       python-whisper >= %{version}, mod_wsgi, pytz, pyparsing, python-simplejson
-Requires:       dejavu-sans-fonts, dejavu-serif-fonts, pycairo, django-tagging
 
-%if 0%{?fedora} >= 18
+Requires:       dejavu-sans-fonts
+Requires:       dejavu-serif-fonts
+Requires:       django-tagging
+Requires:       mod_wsgi
+Requires:       pycairo
+Requires:       pyparsing
+Requires:       python-simplejson
+Requires:       python-whisper >= %{version}
+Requires:       pytz
+
+%if 0%{?fedora} >= 18 || 0%{?rhel} >= 7
 Requires:       python-django >= 1.3
 %else
 Requires:       Django >= 1.3
@@ -104,6 +121,11 @@ install -m0644 %{SOURCE3} README.selinux
 %patch6 -p1
 %endif
 
+%if %{with_system_logrotate}
+# Disable internal log rotation.
+%patch7 -p1
+%endif
+
 
 %build
 %{__python} setup.py build
@@ -135,6 +157,11 @@ install -Dp -m0644 conf/graphite.wsgi.example \
 sed -i 's|##PYTHON_SITELIB##|%{python_sitelib}|' \
     %{buildroot}%{_sysconfdir}/httpd/conf.d/graphite-web.conf
 
+%if %{with_system_logrotate}
+# Log rotation.
+install -D -p -m0644 %{SOURCE3} %{buildroot}%{_sysconfdir}/logrotate.d/%{name}
+%endif
+
 # Remove unneeded binaries.
 rm -f %{buildroot}%{_bindir}/run-graphite-devel-server.py
 
@@ -172,6 +199,10 @@ fi
 %config(noreplace) %{_sysconfdir}/graphite-web/dashboard.conf
 %config(noreplace) %{_sysconfdir}/graphite-web/local_settings.py*
 
+%if %{with_system_logrotate}
+%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
+%endif
+
 %{_bindir}/graphite-build-index
 %{_bindir}/graphite-manage
 %{_datadir}/graphite


More information about the scm-commits mailing list