Merge lp:~facundo/magicicada-gui/log-to-files into lp:magicicada-gui

Proposed by Facundo Batista
Status: Merged
Approved by: Natalia Bidart
Approved revision: 39
Merged at revision: 40
Proposed branch: lp:~facundo/magicicada-gui/log-to-files
Merge into: lp:magicicada-gui
Diff against target: 134 lines (+60/-18)
4 files modified
magicicada/__init__.py (+4/-1)
magicicada/dbusiface.py (+0/-9)
magicicada/logger.py (+56/-0)
magicicada/syncdaemon.py (+0/-8)
To merge this branch: bzr merge lp:~facundo/magicicada-gui/log-to-files
Reviewer Review Type Date Requested Status
Natalia Bidart Approve
Review via email: mp+26852@code.launchpad.net

Description of the change

Log to a file.

The file rotates when reachs 1MB, and everytime the program is started. After ten rotations, the oldest is removed.

To post a comment you must log in.
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

/me likes it

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'magicicada/__init__.py'
2--- magicicada/__init__.py 2010-06-04 02:07:15 +0000
3+++ magicicada/__init__.py 2010-06-05 04:02:21 +0000
4@@ -28,12 +28,15 @@
5 from twisted.internet import gtk2reactor # for gtk-2.0
6 gtk2reactor.install()
7
8-from magicicada import syncdaemon
9+from magicicada import syncdaemon, logger
10 from magicicada.helpers import humanize_bytes, get_data_file, get_builder, NO_OP
11
12 CONTENT_QUEUE = 'content'
13 META_QUEUE = 'meta'
14
15+# set up the logging for all the project
16+logger.set_up()
17+
18 class MagicicadaUI(object):
19
20 STATUS_JOINER = " - "
21
22=== modified file 'magicicada/dbusiface.py'
23--- magicicada/dbusiface.py 2010-05-31 16:45:45 +0000
24+++ magicicada/dbusiface.py 2010-06-05 04:02:21 +0000
25@@ -21,7 +21,6 @@
26 import collections
27 import logging
28 import re
29-import sys
30
31 import dbus
32 from dbus import SessionBus
33@@ -31,14 +30,6 @@
34
35 # log!
36 logger = logging.getLogger('magicicada.dbusiface')
37-handler = logging.StreamHandler(sys.stdout)
38-logger.addHandler(handler)
39-formatter = logging.Formatter("%(asctime)s %(name)s:%(lineno)-4d "
40- "%(levelname)-8s %(message)s",
41- '%Y-%m-%d %H:%M:%S')
42-handler.setFormatter(formatter)
43-logger.setLevel(logging.DEBUG)
44-
45
46 QueueData = collections.namedtuple('QueueData', 'operation path share node')
47 FolderData = collections.namedtuple('FolderData',
48
49=== added file 'magicicada/logger.py'
50--- magicicada/logger.py 1970-01-01 00:00:00 +0000
51+++ magicicada/logger.py 2010-06-05 04:02:21 +0000
52@@ -0,0 +1,56 @@
53+# logger.py
54+#
55+# Author: Facundo Batista <facundo@taniquetil.com.ar>
56+#
57+# Copyright 2010 Chicharreros
58+#
59+# This program is free software: you can redistribute it and/or modify it
60+# under the terms of the GNU General Public License version 3, as published
61+# by the Free Software Foundation.
62+#
63+# This program is distributed in the hope that it will be useful, but
64+# WITHOUT ANY WARRANTY; without even the implied warranties of
65+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
66+# PURPOSE. See the GNU General Public License for more details.
67+#
68+# You should have received a copy of the GNU General Public License along
69+# with this program. If not, see <http://www.gnu.org/licenses/>.
70+
71+"""Logging set up."""
72+
73+
74+import logging
75+import os
76+
77+from logging.handlers import RotatingFileHandler
78+
79+import xdg.BaseDirectory
80+
81+
82+class CustomRotatingFH(RotatingFileHandler):
83+ """Rotating handler that starts a new file for every run."""
84+
85+ def __init__(self, *args, **kwargs):
86+ RotatingFileHandler.__init__(self, *args, **kwargs)
87+ self.doRollover()
88+
89+
90+def set_up():
91+ """Set up the logging."""
92+
93+ # choose the folder to store the logs
94+ cache = xdg.BaseDirectory.xdg_cache_home
95+ logfolder = os.path.join(cache, 'magicicada')
96+ if not os.path.exists(logfolder):
97+ os.makedirs(logfolder)
98+ logfile = os.path.join(logfolder, 'magicicada.log')
99+
100+ logger = logging.getLogger('magicicada')
101+ handler = CustomRotatingFH(logfile, maxBytes=1e6, backupCount=10)
102+ logger.addHandler(handler)
103+ formatter = logging.Formatter("%(asctime)s %(name)-23s"
104+ "%(levelname)-8s %(message)s",
105+ '%Y-%m-%d %H:%M:%S')
106+ handler.setFormatter(formatter)
107+ logger.setLevel(logging.DEBUG)
108+
109
110=== modified file 'magicicada/syncdaemon.py'
111--- magicicada/syncdaemon.py 2010-05-31 00:31:17 +0000
112+++ magicicada/syncdaemon.py 2010-06-05 04:02:21 +0000
113@@ -19,7 +19,6 @@
114 """The backend that communicates Magicicada with the SyncDaemon."""
115
116 import logging
117-import sys
118
119 from twisted.internet import defer, reactor
120
121@@ -28,13 +27,6 @@
122
123 # log!
124 logger = logging.getLogger('magicicada.syncdaemon')
125-handler = logging.StreamHandler(sys.stdout)
126-logger.addHandler(handler)
127-formatter = logging.Formatter("%(asctime)s %(name)s:%(lineno)-4d "
128- "%(levelname)-8s %(message)s",
129- '%Y-%m-%d %H:%M:%S')
130-handler.setFormatter(formatter)
131-logger.setLevel(logging.DEBUG)
132
133
134 class State(object):

Subscribers

People subscribed via source and target branches