~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to serve-branches

  • Committer: Michael Hudson
  • Date: 2008-09-29 21:36:59 UTC
  • mfrom: (217.1.17 logging)
  • Revision ID: michael.hudson@canonical.com-20080929213659-gvxmf9s1e2zouetn
Guillermo Gonzalez's logging branch, which mostly cleans up how errors are
reported, both in terms of logging and in the browser.
Some clean ups by me.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
from loggerhead.apps.filesystem import (
30
30
    BranchesFromFileSystemRoot, UserBranchesFromFileSystemRoot)
31
31
from loggerhead.util import Reloader
 
32
from loggerhead.apps.error import ErrorHandlerApp
32
33
 
33
34
 
34
35
def command_line_parser():
36
37
    parser.set_defaults(
37
38
        user_dirs=False,
38
39
        show_version=False,
 
40
        log_folder=None,
39
41
        )
40
42
    parser.add_option("--user-dirs", action="store_true", dest="user_dirs",
41
43
                      help="Serve user directories as ~user.")
50
52
    parser.add_option("--reload", action="store_true", dest="reload",
51
53
                      help="Restarts the application when changing python"
52
54
                           " files. Only used for development purposes.")
 
55
    parser.add_option('--log-folder', dest="log_folder",
 
56
                      type=str, help="The directory to place log files in.")
53
57
    parser.add_option("--version", action="store_true", dest="show_version",
54
58
                      help="Print the software version and exit")
55
59
    return parser
56
60
 
57
61
 
58
62
def main(args):
59
 
    logging.basicConfig()
60
 
    logging.getLogger().setLevel(logging.DEBUG)
61
 
 
62
63
    parser = command_line_parser()
63
64
    (options, args) = parser.parse_args(sys.argv[1:])
64
65
 
81
82
    if options.trunk_dir and not options.user_dirs:
82
83
        print "--trunk-dir is only valid with --user-dirs"
83
84
        sys.exit(1)
84
 
        
 
85
 
85
86
    if options.reload:
86
87
        if Reloader.is_installed():
87
88
            Reloader.install()
95
96
        app = UserBranchesFromFileSystemRoot(path, options.trunk_dir)
96
97
    else:
97
98
        app = BranchesFromFileSystemRoot(path)
 
99
 
 
100
    # setup_logging()
 
101
    logging.basicConfig()
 
102
    logging.getLogger('').setLevel(logging.DEBUG)
 
103
    logger = getattr(app, 'log', logging.getLogger('loggerhead'))
 
104
    if options.log_folder:
 
105
        logfile_path = os.path.join(options.log_folder, 'serve-branches.log')
 
106
    else:
 
107
        logfile_path = 'serve-branches.log'
 
108
    logfile = logging.FileHandler(logfile_path, 'a')
 
109
    formatter = logging.Formatter('%(asctime)s %(levelname)-8s %(name)s:'
 
110
                                  ' %(message)s')
 
111
    logfile.setFormatter(formatter)
 
112
    logfile.setLevel(logging.DEBUG)
 
113
    logger.addHandler(logfile)
 
114
    # setup_logging() #end
 
115
    app = ErrorHandlerApp(app)
98
116
    app = HTTPExceptionHandler(app)
99
 
    app = TransLogger(app)
 
117
    app = TransLogger(app, logger=logger)
100
118
 
101
119
    if not options.user_prefix:
102
120
        prefix = '/'
109
127
        pass
110
128
    else:
111
129
        app = PrefixMiddleware(app, prefix=prefix)
112
 
    
 
130
 
113
131
    if not options.user_port:
114
132
        port = '8080'
115
133
    else: