~ubuntu-branches/ubuntu/oneiric/ubuntuone-client/oneiric

« back to all changes in this revision

Viewing changes to ubuntuone/oauthdesktop/logger.py

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Moya
  • Date: 2010-06-23 23:08:15 UTC
  • mto: This revision was merged to the branch mainline in revision 34.
  • Revision ID: james.westby@ubuntu.com-20100623230815-4m3ugh10u9x9xzw5
Tags: upstream-1.3.2
ImportĀ upstreamĀ versionĀ 1.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# ubuntuone.oauthdesktop.logger - logging miscellany
2
 
#
3
 
# Author: Stuart Langridge <stuart.langridge@canonical.com>
4
 
#
5
 
# Copyright 2009 Canonical Ltd.
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
 
"""Miscellaneous logging functions."""
19
 
import os
20
 
import logging
21
 
import xdg.BaseDirectory
22
 
 
23
 
from logging.handlers import RotatingFileHandler
24
 
 
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)
30
 
 
31
 
LOGFILENAME = os.path.join(LOGFOLDER, 'oauth-login.log')
32
 
 
33
 
# Only log this level and above
34
 
LOG_LEVEL = logging.INFO
35
 
 
36
 
root_formatter = logging.Formatter(
37
 
    fmt="%(asctime)s:%(msecs)s %(name)s %(message)s")
38
 
root_handler = RotatingFileHandler(LOGFILENAME, maxBytes=1048576,
39
 
                                   backupCount=1)
40
 
root_handler.setLevel(LOG_LEVEL)
41
 
root_handler.setFormatter(root_formatter)
42
 
 
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)
49
 
    return logger