3
# Author: Facundo Batista <facundo@taniquetil.com.ar>
5
# Copyright 2010 Chicharreros
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.
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.
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/>.
25
from logging.handlers import RotatingFileHandler
27
import xdg.BaseDirectory
30
class CustomRotatingFH(RotatingFileHandler):
31
"""Rotating handler that starts a new file for every run."""
33
def __init__(self, *args, **kwargs):
34
RotatingFileHandler.__init__(self, *args, **kwargs)
39
"""Set up the logging."""
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')
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",
54
handler.setFormatter(formatter)
55
logger.setLevel(logging.DEBUG)