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
=== modified file 'magicicada/__init__.py'
--- magicicada/__init__.py 2010-06-04 02:07:15 +0000
+++ magicicada/__init__.py 2010-06-05 04:02:21 +0000
@@ -28,12 +28,15 @@
28from twisted.internet import gtk2reactor # for gtk-2.028from twisted.internet import gtk2reactor # for gtk-2.0
29gtk2reactor.install()29gtk2reactor.install()
3030
31from magicicada import syncdaemon31from magicicada import syncdaemon, logger
32from magicicada.helpers import humanize_bytes, get_data_file, get_builder, NO_OP32from magicicada.helpers import humanize_bytes, get_data_file, get_builder, NO_OP
3333
34CONTENT_QUEUE = 'content'34CONTENT_QUEUE = 'content'
35META_QUEUE = 'meta'35META_QUEUE = 'meta'
3636
37# set up the logging for all the project
38logger.set_up()
39
37class MagicicadaUI(object):40class MagicicadaUI(object):
3841
39 STATUS_JOINER = " - "42 STATUS_JOINER = " - "
4043
=== modified file 'magicicada/dbusiface.py'
--- magicicada/dbusiface.py 2010-05-31 16:45:45 +0000
+++ magicicada/dbusiface.py 2010-06-05 04:02:21 +0000
@@ -21,7 +21,6 @@
21import collections21import collections
22import logging22import logging
23import re23import re
24import sys
2524
26import dbus25import dbus
27from dbus import SessionBus26from dbus import SessionBus
@@ -31,14 +30,6 @@
3130
32# log!31# log!
33logger = logging.getLogger('magicicada.dbusiface')32logger = logging.getLogger('magicicada.dbusiface')
34handler = logging.StreamHandler(sys.stdout)
35logger.addHandler(handler)
36formatter = logging.Formatter("%(asctime)s %(name)s:%(lineno)-4d "
37 "%(levelname)-8s %(message)s",
38 '%Y-%m-%d %H:%M:%S')
39handler.setFormatter(formatter)
40logger.setLevel(logging.DEBUG)
41
4233
43QueueData = collections.namedtuple('QueueData', 'operation path share node')34QueueData = collections.namedtuple('QueueData', 'operation path share node')
44FolderData = collections.namedtuple('FolderData',35FolderData = collections.namedtuple('FolderData',
4536
=== added file 'magicicada/logger.py'
--- magicicada/logger.py 1970-01-01 00:00:00 +0000
+++ magicicada/logger.py 2010-06-05 04:02:21 +0000
@@ -0,0 +1,56 @@
1# logger.py
2#
3# Author: Facundo Batista <facundo@taniquetil.com.ar>
4#
5# Copyright 2010 Chicharreros
6#
7# This program is free software: you can redistribute it and/or modify it
8# under the terms of the GNU General Public License version 3, as published
9# by the Free Software Foundation.
10#
11# This program is distributed in the hope that it will be useful, but
12# WITHOUT ANY WARRANTY; without even the implied warranties of
13# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14# PURPOSE. See the GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License along
17# with this program. If not, see <http://www.gnu.org/licenses/>.
18
19"""Logging set up."""
20
21
22import logging
23import os
24
25from logging.handlers import RotatingFileHandler
26
27import xdg.BaseDirectory
28
29
30class CustomRotatingFH(RotatingFileHandler):
31 """Rotating handler that starts a new file for every run."""
32
33 def __init__(self, *args, **kwargs):
34 RotatingFileHandler.__init__(self, *args, **kwargs)
35 self.doRollover()
36
37
38def set_up():
39 """Set up the logging."""
40
41 # choose the folder to store the logs
42 cache = xdg.BaseDirectory.xdg_cache_home
43 logfolder = os.path.join(cache, 'magicicada')
44 if not os.path.exists(logfolder):
45 os.makedirs(logfolder)
46 logfile = os.path.join(logfolder, 'magicicada.log')
47
48 logger = logging.getLogger('magicicada')
49 handler = CustomRotatingFH(logfile, maxBytes=1e6, backupCount=10)
50 logger.addHandler(handler)
51 formatter = logging.Formatter("%(asctime)s %(name)-23s"
52 "%(levelname)-8s %(message)s",
53 '%Y-%m-%d %H:%M:%S')
54 handler.setFormatter(formatter)
55 logger.setLevel(logging.DEBUG)
56
057
=== modified file 'magicicada/syncdaemon.py'
--- magicicada/syncdaemon.py 2010-05-31 00:31:17 +0000
+++ magicicada/syncdaemon.py 2010-06-05 04:02:21 +0000
@@ -19,7 +19,6 @@
19"""The backend that communicates Magicicada with the SyncDaemon."""19"""The backend that communicates Magicicada with the SyncDaemon."""
2020
21import logging21import logging
22import sys
2322
24from twisted.internet import defer, reactor23from twisted.internet import defer, reactor
2524
@@ -28,13 +27,6 @@
2827
29# log!28# log!
30logger = logging.getLogger('magicicada.syncdaemon')29logger = logging.getLogger('magicicada.syncdaemon')
31handler = logging.StreamHandler(sys.stdout)
32logger.addHandler(handler)
33formatter = logging.Formatter("%(asctime)s %(name)s:%(lineno)-4d "
34 "%(levelname)-8s %(message)s",
35 '%Y-%m-%d %H:%M:%S')
36handler.setFormatter(formatter)
37logger.setLevel(logging.DEBUG)
3830
3931
40class State(object):32class State(object):

Subscribers

People subscribed via source and target branches