~sandy-walsh/nova/zones

« back to all changes in this revision

Viewing changes to nova/log.py

  • Committer: Sandy Walsh
  • Date: 2011-02-17 21:39:03 UTC
  • mfrom: (635.1.60 nova)
  • Revision ID: sandy.walsh@rackspace.com-20110217213903-swehe88wea8inxow
changed from 003-004 migration

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
 
30
30
import cStringIO
 
31
import inspect
31
32
import json
32
33
import logging
33
34
import logging.handlers
 
35
import os
34
36
import sys
35
37
import traceback
36
38
 
92
94
log = logging.log
93
95
# handlers
94
96
StreamHandler = logging.StreamHandler
95
 
FileHandler = logging.FileHandler
 
97
RotatingFileHandler = logging.handlers.RotatingFileHandler
96
98
# logging.SysLogHandler is nicer than logging.logging.handler.SysLogHandler.
97
99
SysLogHandler = logging.handlers.SysLogHandler
98
100
 
111
113
    return context
112
114
 
113
115
 
 
116
def _get_binary_name():
 
117
    return os.path.basename(inspect.stack()[-1][1])
 
118
 
 
119
 
 
120
def get_log_file_path(binary=None):
 
121
    if FLAGS.logfile:
 
122
        return FLAGS.logfile
 
123
    if FLAGS.logdir:
 
124
        binary = binary or _get_binary_name()
 
125
        return '%s.log' % (os.path.join(FLAGS.logdir, binary),)
 
126
 
 
127
 
114
128
def basicConfig():
115
129
    logging.basicConfig()
116
130
    for handler in logging.root.handlers:
123
137
        syslog = SysLogHandler(address='/dev/log')
124
138
        syslog.setFormatter(_formatter)
125
139
        logging.root.addHandler(syslog)
126
 
    if FLAGS.logfile:
127
 
        logfile = FileHandler(FLAGS.logfile)
 
140
    logpath = get_log_file_path()
 
141
    if logpath:
 
142
        logfile = RotatingFileHandler(logpath)
128
143
        logfile.setFormatter(_formatter)
129
144
        logging.root.addHandler(logfile)
130
145