[Kimchi-devel] [PATCH v2] Disabling screen log in production environment

Aline Manera alinefm at linux.vnet.ibm.com
Thu Oct 16 17:49:26 UTC 2014


Reviewed-by: Aline Manera <alinefm at linux.vnet.ibm.com>

On 10/15/2014 04:36 PM, Daniel Henrique Barboza wrote:
> When building kimchi's RPM, some messages are getting
> logged in /var/log/messages because cherrypy is logging
> in the standard output. This happens because a function
> in FeatureTests is enabling log.screen regardless of the
> current environment. This patch makes a verification that
> prevents the screen log to be enabled in the production
> environment.
>
> Signed-off-by: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>
> ---
>   src/kimchi/featuretests.py | 31 ++++++++++++++++---------------
>   src/kimchi/server.py       |  6 +++++-
>   2 files changed, 21 insertions(+), 16 deletions(-)
>
> diff --git a/src/kimchi/featuretests.py b/src/kimchi/featuretests.py
> index c6f4687..f1eb8ae 100644
> --- a/src/kimchi/featuretests.py
> +++ b/src/kimchi/featuretests.py
> @@ -80,30 +80,31 @@ SCSI_FC_XML = """
>   class FeatureTests(object):
>
>       @staticmethod
> -    def disable_screen_error_logging():
> +    def disable_libvirt_error_logging():
>           def libvirt_errorhandler(userdata, error):
>               # A libvirt error handler to ignore annoying messages in stderr
>               pass
>
> +        # Filter functions are enable only in production env
> +        if cherrypy.config.get('environment') != 'production':
> +            return
>           # Register the error handler to hide libvirt error in stderr
>           libvirt.registerErrorHandler(f=libvirt_errorhandler, ctx=None)
> -        # Disable cherrypy screen logging, in order to log errors on kimchi
> -        # file without displaying them on screen
> -        cherrypy.log.screen = False
>
>       @staticmethod
> -    def enable_screen_error_logging():
> +    def enable_libvirt_error_logging():
> +        # Filter functions are enable only in production env
> +        if cherrypy.config.get('environment') != 'production':
> +            return
>           # Unregister the error handler
>           libvirt.registerErrorHandler(f=None, ctx=None)
> -        # Enable cherrypy screen logging
> -        cherrypy.log.screen = True
>
>       @staticmethod
>       def libvirt_supports_iso_stream(protocol):
>           xml = ISO_STREAM_XML % {'protocol': protocol}
>           conn = None
>           try:
> -            FeatureTests.disable_screen_error_logging()
> +            FeatureTests.disable_libvirt_error_logging()
>               conn = libvirt.open(None)
>               dom = conn.defineXML(xml)
>               dom.undefine()
> @@ -112,7 +113,7 @@ class FeatureTests(object):
>               kimchi_log.error(e.message)
>               return False
>           finally:
> -            FeatureTests.enable_screen_error_logging()
> +            FeatureTests.enable_libvirt_error_logging()
>               conn is None or conn.close()
>
>       @staticmethod
> @@ -123,7 +124,7 @@ class FeatureTests(object):
>               return xml
>           try:
>               conn = libvirt.open(None)
> -            FeatureTests.disable_screen_error_logging()
> +            FeatureTests.disable_libvirt_error_logging()
>               conn.findStoragePoolSources('netfs', _get_xml(), 0)
>           except libvirt.libvirtError as e:
>               kimchi_log.error(e.message)
> @@ -132,7 +133,7 @@ class FeatureTests(object):
>                   # it returns 38--general system call failure
>                   return False
>           finally:
> -            FeatureTests.enable_screen_error_logging()
> +            FeatureTests.enable_libvirt_error_logging()
>               conn is None or conn.close()
>
>           return True
> @@ -173,7 +174,7 @@ class FeatureTests(object):
>       @staticmethod
>       def libvirt_support_fc_host():
>           try:
> -            FeatureTests.disable_screen_error_logging()
> +            FeatureTests.disable_libvirt_error_logging()
>               conn = libvirt.open(None)
>               pool = None
>               pool = conn.storagePoolDefineXML(SCSI_FC_XML, 0)
> @@ -182,7 +183,7 @@ class FeatureTests(object):
>                   # Libvirt requires adapter name, not needed when supports to FC
>                   return False
>           finally:
> -            FeatureTests.enable_screen_error_logging()
> +            FeatureTests.enable_libvirt_error_logging()
>               pool is None or pool.undefine()
>               conn is None or conn.close()
>           return True
> @@ -192,8 +193,8 @@ class FeatureTests(object):
>           KIMCHI_META_URL = "https://github.com/kimchi-project/kimchi/"
>           KIMCHI_NAMESPACE = "kimchi"
>           with RollbackContext() as rollback:
> -            FeatureTests.disable_screen_error_logging()
> -            rollback.prependDefer(FeatureTests.enable_screen_error_logging)
> +            FeatureTests.disable_libvirt_error_logging()
> +            rollback.prependDefer(FeatureTests.enable_libvirt_error_logging)
>               conn = libvirt.open(None)
>               rollback.prependDefer(conn.close)
>               dom = conn.defineXML(SIMPLE_VM_XML)
> diff --git a/src/kimchi/server.py b/src/kimchi/server.py
> index 8d166e5..6cc7143 100644
> --- a/src/kimchi/server.py
> +++ b/src/kimchi/server.py
> @@ -91,13 +91,17 @@ class Server(object):
>           max_body_size_in_bytes = eval(options.max_body_size) * 1024
>           cherrypy.server.max_request_body_size = max_body_size_in_bytes
>
> -        cherrypy.log.screen = True
>           cherrypy.log.access_file = options.access_log
>           cherrypy.log.error_file = options.error_log
>
>           logLevel = LOGGING_LEVEL.get(options.log_level, logging.DEBUG)
>           dev_env = options.environment != 'production'
>
> +        # Enable cherrypy screen logging if running environment
> +        # is not 'production'
> +        if dev_env:
> +            cherrypy.log.screen = True
> +
>           # Create handler to rotate access log file
>           h = logging.handlers.RotatingFileHandler(options.access_log, 'a',
>                                                    10000000, 1000)




More information about the Kimchi-devel mailing list