~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/trace.py

  • Committer: John Arbash Meinel
  • Date: 2011-02-10 00:43:37 UTC
  • mto: This revision was merged to the branch mainline in revision 426.
  • Revision ID: john@arbash-meinel.com-20110210004337-8rwedln8fgg4un16
Add a <noop> command to the RequestWorker.

This allows us to push the workers to stop immediately, in case
they are currently blocked waiting on another item in the queue.
This makes the test suite integration tests faster, but also
makes the script runner exit in a timely manner as well.

Also creating a trivial load_test script, just for example
purposes.

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 logging.handlers
 
26
import sys
 
27
 
 
28
 
 
29
def make_handler(config, filename):
 
30
    roll = config.get('log.roll', 'never')
 
31
    if roll == 'daily':
 
32
        h = logging.handlers.TimedRotatingFileHandler(filename,
 
33
                                                      'midnight',
 
34
                                                      1,
 
35
                                                      100)
 
36
    elif roll == 'weekly':
 
37
        h = logging.handlers.TimedRotatingFileHandler(filename, 'W0', 1, 100)
 
38
    else:
 
39
        h = logging.FileHandler(filename)
 
40
    return h
 
41
 
 
42
 
 
43
def setup_logging(log_folder, config, foreground):
 
44
    # i hate that stupid logging config format, so just set up logging here.
 
45
 
 
46
    if not os.path.exists(log_folder):
 
47
        os.mkdir(log_folder)
 
48
 
 
49
    f = logging.Formatter('%(levelname)-.3s [%(asctime)s.%(msecs)03d]'
 
50
                          ' %(name)s: %(message)s',
 
51
                          '%Y%m%d-%H:%M:%S')
 
52
    debug_log = make_handler(config, os.path.join(log_folder, 'debug.log'))
 
53
    debug_log.setLevel(logging.DEBUG)
 
54
    debug_log.setFormatter(f)
 
55
    if foreground:
 
56
        stdout_log = logging.StreamHandler(sys.stdout)
 
57
        stdout_log.setLevel(logging.DEBUG)
 
58
        stdout_log.setFormatter(f)
 
59
    f = logging.Formatter('[%(asctime)s.%(msecs)03d] %(message)s',
 
60
                          '%Y%m%d-%H:%M:%S')
 
61
    access_log = make_handler(config, os.path.join(log_folder, 'access.log'))
 
62
    access_log.setLevel(logging.INFO)
 
63
    access_log.setFormatter(f)
 
64
 
 
65
    error_log = make_handler(config, os.path.join(log_folder, 'error.log'))
 
66
    error_log.setLevel(logging.ERROR)
 
67
    error_log.setFormatter(f)
 
68
 
 
69
    logging.getLogger('').setLevel(logging.DEBUG)
 
70
    logging.getLogger('').addHandler(debug_log)
 
71
    logging.getLogger('loggerhead.access').addHandler(access_log)
 
72
    logging.getLogger('loggerhead').setLevel(logging.ERROR)
 
73
    logging.getLogger('loggerhead').addHandler(error_log)
 
74
 
 
75
    if foreground:
 
76
        logging.getLogger('').addHandler(stdout_log)