1
# ubuntuone.oauthdesktop.logger - logging miscellany
3
# Author: Stuart Langridge <stuart.langridge@canonical.com>
5
# Copyright 2009 Canonical Ltd.
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/>.
18
"""Miscellaneous logging functions."""
21
import xdg.BaseDirectory
23
from logging.handlers import RotatingFileHandler
25
home = xdg.BaseDirectory.xdg_cache_home
26
LOGFOLDER = os.path.join(home, 'ubuntuone', 'log')
27
# create log folder if it doesn't exists
28
if not os.path.exists(LOGFOLDER):
29
os.makedirs(LOGFOLDER)
31
LOGFILENAME = os.path.join(LOGFOLDER, 'oauth-login.log')
33
# Only log this level and above
34
LOG_LEVEL = logging.INFO
36
root_formatter = logging.Formatter(
37
fmt="%(asctime)s:%(msecs)s %(name)s %(message)s")
38
root_handler = RotatingFileHandler(LOGFILENAME, maxBytes=1048576,
40
root_handler.setLevel(LOG_LEVEL)
41
root_handler.setFormatter(root_formatter)
43
def setupLogging(log_domain):
44
"""Create basic logger to set filename"""
45
logger = logging.getLogger(log_domain)
46
logger.propagate = False
47
logger.setLevel(LOG_LEVEL)
48
logger.addHandler(root_handler)