Add logfile option that disables logging to screen in production.
BUG=chromium-os:32450
TEST=Ran with / without production
Change-Id: Iccabb169ba99f66c575f62f29c69297bd4fb5f80
Reviewed-on: https://gerrit.chromium.org/gerrit/27197
Tested-by: Chris Sosa <sosa@chromium.org>
Reviewed-by: Scott Zawalski <scottz@chromium.org>
Commit-Ready: Chris Sosa <sosa@chromium.org>
diff --git a/devserver.py b/devserver.py
index 5095f48..8c698ca 100755
--- a/devserver.py
+++ b/devserver.py
@@ -105,12 +105,6 @@
},
}
- if options.log_dir:
- base_config['global']['log.access_file'] = os.path.join(
- options.log_dir, 'devserver_access.log')
- base_config['global']['log.error_file'] = os.path.join(
- options.log_dir, 'devserver_error.log')
-
return base_config
@@ -463,6 +457,8 @@
help='Update is for a vm image.')
parser.add_option('--image', dest='image',
help='Force update using this image.')
+ parser.add_option('--logfile', dest='logfile',
+ help='Log output to this file instead of stdout.')
parser.add_option('-p', '--pregenerate_update', action='store_true',
default=False, help='Pre-generate update payload.')
parser.add_option('--payload', dest='payload',
@@ -483,9 +479,6 @@
parser.add_option('--validate_factory_config', action="store_true",
dest='validate_factory_config',
help='Validate factory config file, then exit.')
- parser.add_option('-l', '--log-dir', default=None,
- help=('Specify a directory for error and access logs. '
- 'Default None, i.e. no logging.'))
(options, _) = parser.parse_args()
devserver_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
@@ -495,10 +488,6 @@
static_dir = os.path.realpath('%s/static' % options.data_dir)
os.system('mkdir -p %s' % static_dir)
- if options.log_dir and not os.path.isdir(options.log_dir):
- parser.error('%s is not a valid dir, provide a valid dir to --log-dir' %
- options.log_dir)
-
if options.archive_dir:
# TODO(zbehan) Remove legacy support:
# archive_dir is the directory where static/archive will point.
@@ -581,9 +570,14 @@
# If the command line requested after setup, it's time to do it.
if not options.exit:
+ # Handle options that must be set globally in cherrypy.
if options.production:
- cherrypy.config.update({'environment': 'production',
- 'log.screen': True})
+ cherrypy.config.update({'environment': 'production'})
+ if not options.logfile:
+ cherrypy.config.update({'log.screen': True})
+ else:
+ cherrypy.config.update({'log.error_file': options.logfile,
+ 'log.access_file': options.logfile})
cherrypy.quickstart(DevServerRoot(), config=_GetConfig(options))