~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/trace.py

  • Committer: Marius Kruger
  • Date: 2008-09-06 20:17:56 UTC
  • mto: This revision was merged to the branch mainline in revision 219.
  • Revision ID: amanic@gmail.com-20080906201756-ocqnga9vu1uj425t
Add alternative insallation notes and mention the --prefix option in README.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
# Copyright (C) 2008  Canonical Ltd.
3
 
#                     (Authored by Martin Albisetti <argentina@gmail.com)
4
 
# Copyright (C) 2008  Guillermo Gonzalez <guillo.gonzo@gmail.com>
5
 
# Copyright (C) 2006  Robey Pointer <robey@lag.net>
6
 
# Copyright (C) 2006  Goffredo Baroncelli <kreijack@inwind.it>
7
 
#
8
 
# This program is free software; you can redistribute it and/or modify
9
 
# it under the terms of the GNU General Public License as published by
10
 
# the Free Software Foundation; either version 2 of the License, or
11
 
# (at your option) any later version.
12
 
#
13
 
# This program is distributed in the hope that it will be useful,
14
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
# GNU General Public License for more details.
17
 
#
18
 
# You should have received a copy of the GNU General Public License
19
 
# along with this program; if not, write to the Free Software
20
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21
 
#
22
 
 
23
 
import os
24
 
import logging
25
 
import sys
26
 
 
27
 
def make_handler(config, filename):
28
 
    roll = config.get('log.roll', 'never')
29
 
    if roll == 'daily':
30
 
        h = logging.handlers.TimedRotatingFileHandler(filename, 'midnight', 1, 100)
31
 
    elif roll == 'weekly':
32
 
        h = logging.handlers.TimedRotatingFileHandler(filename, 'W0', 1, 100)
33
 
    else:
34
 
        h = logging.FileHandler(filename)
35
 
    return h
36
 
 
37
 
 
38
 
def setup_logging(log_folder, config, foreground):
39
 
    # i hate that stupid logging config format, so just set up logging here.
40
 
 
41
 
    if not os.path.exists(log_folder):
42
 
        os.mkdir(log_folder)
43
 
 
44
 
    f = logging.Formatter('%(levelname)-.3s [%(asctime)s.%(msecs)03d]'
45
 
                          ' %(name)s: %(message)s','%Y%m%d-%H:%M:%S')
46
 
    debug_log = make_handler(config, os.path.join(log_folder, 'debug.log'))
47
 
    debug_log.setLevel(logging.DEBUG)
48
 
    debug_log.setFormatter(f)
49
 
    if foreground:
50
 
        stdout_log = logging.StreamHandler(sys.stdout)
51
 
        stdout_log.setLevel(logging.DEBUG)
52
 
        stdout_log.setFormatter(f)
53
 
    f = logging.Formatter('[%(asctime)s.%(msecs)03d] %(message)s',
54
 
                          '%Y%m%d-%H:%M:%S')
55
 
    access_log = make_handler(config, os.path.join(log_folder, 'access.log'))
56
 
    access_log.setLevel(logging.INFO)
57
 
    access_log.setFormatter(f)
58
 
    
59
 
    error_log = make_handler(config, os.path.join(log_folder, 'error.log'))
60
 
    error_log.setLevel(logging.ERROR)
61
 
    error_log.setFormatter(f)
62
 
 
63
 
    logging.getLogger('').setLevel(logging.DEBUG)
64
 
    logging.getLogger('').addHandler(debug_log)
65
 
    logging.getLogger('loggerhead.access').addHandler(access_log)
66
 
    logging.getLogger('loggerhead').setLevel(logging.ERROR)
67
 
    logging.getLogger('loggerhead').addHandler(error_log)
68
 
 
69
 
    if foreground:
70
 
        logging.getLogger('').addHandler(stdout_log)