OLD | NEW |
---|---|
(Empty) | |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 """Common library methods. | |
5 | |
6 These methods can be used by both the host and the client code. | |
7 """ | |
8 | |
9 import argparse | |
10 import logging | |
11 import socket | |
12 import sys | |
13 import xmlrpclib | |
14 import SimpleXMLRPCServer | |
15 | |
16 LOGGING_FORMAT = ('%(asctime)s %(filename)s:%(lineno)s %(levelname)s] ' | |
17 '%(message)s') | |
18 LOGGING_DATE_FORMAT = '%H:%M:%S' | |
19 MY_IP = socket.gethostbyname(socket.gethostname()) | |
20 | |
21 | |
22 def InitLogging(): | |
23 """Initialize the logging module.""" | |
24 parser = argparse.ArgumentParser() | |
25 parser.add_argument('--verbose', action='store_true') | |
26 args, _ = parser.parse_known_args() | |
27 level = logging.DEBUG if args.verbose else logging.INFO | |
Marc-Antoine Ruel (Google)
2015/01/30 21:58:40
(FYI) in generally we use ERROR as default.
Mike Meade
2015/02/03 01:18:09
Unfortunately setting logging to error results in
M-A Ruel
2015/02/03 01:48:40
Ah! I can fix that later in the client code. It's
| |
28 logging.basicConfig(format=LOGGING_FORMAT, datefmt=LOGGING_DATE_FORMAT, | |
29 level=level) | |
30 | |
31 | |
32 def LogCommandLine(): | |
33 """Log the command line used to run this program.""" | |
34 logging.debug(' '.join(sys.argv)) | |
OLD | NEW |