diff --git a/doc/source/admin/config_logging.rst b/doc/source/admin/config_logging.rst index faeba11ddc5..cd6e4460a9a 100644 --- a/doc/source/admin/config_logging.rst +++ b/doc/source/admin/config_logging.rst @@ -45,6 +45,20 @@ To change the log file name or location, use the ``$GALAXY_LOG`` environment var $ GALAXY_LOG=/path/to/galaxy/logfile sh run.sh --daemon +It is also possible to specify the path to the log file using the ``log_destination`` configuration option in +``galaxy.yml``. Additionally, it is possible to automatically rotate logs once the log file reaches a given size, using +the ``log_rotate_size`` and ``log_rotate_count`` options, which control the size at which the log is rotated, and the +number of rotated logs to keep, respectively: + +.. code-block:: yaml + + galaxy: + # Set log file path + log_destination: /srv/galaxy/log/galaxy.log + # Rotate once log reaches 100 MB + log_rotate_size: 100 MB + # Keep the 10 most recent log files + log_rotate_count: 10 Advanced Configuration ---------------------------- diff --git a/doc/source/admin/galaxy_options.rst b/doc/source/admin/galaxy_options.rst index b38797b620b..4e710bf3eba 100644 --- a/doc/source/admin/galaxy_options.rst +++ b/doc/source/admin/galaxy_options.rst @@ -2576,12 +2576,55 @@ :Type: bool +~~~~~~~~~~~~~~~~~~~ +``log_destination`` +~~~~~~~~~~~~~~~~~~~ + +:Description: + Log destination, defaults to special value "stdout" that logs to + standard output. If set to anything else, then it will be + interpreted as a path that will be used as the log file, and + logging to stdout will be disabled. +:Default: ``stdout`` +:Type: str + + +~~~~~~~~~~~~~~~~~~~ +``log_rotate_size`` +~~~~~~~~~~~~~~~~~~~ + +:Description: + Size of log file at which size it will be rotated as per the + documentation in + https://docs.python.org/library/logging.handlers.html#logging.handlers.RotatingFileHandler + If log_rotate_count is not also set, no log rotation will be + performed. A value of 0 (the default) means no rotation. Size can + be a number of bytes or a human-friendly representation like "100 + MB" or "1G". +:Default: ``0`` +:Type: str + + +~~~~~~~~~~~~~~~~~~~~ +``log_rotate_count`` +~~~~~~~~~~~~~~~~~~~~ + +:Description: + Number of log file backups to keep, per the documentation in + https://docs.python.org/library/logging.handlers.html#logging.handlers.RotatingFileHandler + Any additional rotated log files will automatically be pruned. If + log_rotate_size is not also set, no log rotation will be + performed. A value of 0 (the default) means no rotation. +:Default: ``0`` +:Type: int + + ~~~~~~~~~~~~~ ``log_level`` ~~~~~~~~~~~~~ :Description: - Verbosity of console log messages. Acceptable values can be found + Verbosity of console log messages. Acceptable values can be found here: https://docs.python.org/library/logging.html#logging-levels A custom debug level of "TRACE" is available for even more verbosity. @@ -2594,9 +2637,8 @@ ~~~~~~~~~~~ :Description: - Controls where and how the server logs messages. If unset, the - default is to log all messages to standard output at the level - defined by the `log_level` configuration option. Configuration is + Controls where and how the server logs messages. If set, overrides + all settings in the log_* configuration options. Configuration is described in the documentation at: https://docs.galaxyproject.org/en/master/admin/config_logging.html :Default: ``None`` diff --git a/lib/galaxy/config/__init__.py b/lib/galaxy/config/__init__.py index f8c1bf888ab..5a8aa0b82d9 100644 --- a/lib/galaxy/config/__init__.py +++ b/lib/galaxy/config/__init__.py @@ -35,6 +35,7 @@ from galaxy.config.schema import AppSchema from galaxy.exceptions import ConfigurationError from galaxy.util import ( listify, + size_to_bytes, string_as_bool, unicodify, ) @@ -1102,6 +1103,8 @@ class GalaxyAppConfiguration(BaseAppConfiguration, CommonConfigurationMixin): } log_destination = kwargs.get("log_destination") + log_rotate_size = size_to_bytes(unicodify(kwargs.get("log_rotate_size", 0))) + log_rotate_count = int(kwargs.get("log_rotate_count", 0)) galaxy_daemon_log_destination = os.environ.get("GALAXY_DAEMON_LOG") if log_destination == "stdout": LOGGING_CONFIG_DEFAULT["handlers"]["console"] = { @@ -1113,19 +1116,23 @@ class GalaxyAppConfiguration(BaseAppConfiguration, CommonConfigurationMixin): } elif log_destination: LOGGING_CONFIG_DEFAULT["handlers"]["console"] = { - "class": "logging.FileHandler", + "class": "logging.handlers.RotatingFileHandler", "formatter": "stack", "level": "DEBUG", "filename": log_destination, "filters": ["stack"], + "maxBytes": log_rotate_size, + "backupCount": log_rotate_count, } if galaxy_daemon_log_destination: LOGGING_CONFIG_DEFAULT["handlers"]["files"] = { - "class": "logging.FileHandler", + "class": "logging.handlers.RotatingFileHandler", "formatter": "stack", "level": "DEBUG", "filename": galaxy_daemon_log_destination, "filters": ["stack"], + "maxBytes": log_rotate_size, + "backupCount": log_rotate_count, } LOGGING_CONFIG_DEFAULT["root"]["handlers"].append("files") diff --git a/lib/galaxy/config/sample/galaxy.yml.sample b/lib/galaxy/config/sample/galaxy.yml.sample index ca1d45b86e2..af7aceedef2 100644 --- a/lib/galaxy/config/sample/galaxy.yml.sample +++ b/lib/galaxy/config/sample/galaxy.yml.sample @@ -1360,14 +1360,35 @@ galaxy: # "loggers" section does not appear in this configuration file. #auto_configure_logging: true - # Verbosity of console log messages. Acceptable values can be found + # Log destination, defaults to special value "stdout" that logs to + # standard output. If set to anything else, then it will be + # interpreted as a path that will be used as the log file, and logging + # to stdout will be disabled. + #log_destination: stdout + + # Size of log file at which size it will be rotated as per the + # documentation in + # https://docs.python.org/library/logging.handlers.html#logging.handlers.RotatingFileHandler + # If log_rotate_count is not also set, no log rotation will be + # performed. A value of 0 (the default) means no rotation. Size can be + # a number of bytes or a human-friendly representation like "100 MB" + # or "1G". + #log_rotate_size: '0' + + # Number of log file backups to keep, per the documentation in + # https://docs.python.org/library/logging.handlers.html#logging.handlers.RotatingFileHandler + # Any additional rotated log files will automatically be pruned. If + # log_rotate_size is not also set, no log rotation will be performed. + # A value of 0 (the default) means no rotation. + #log_rotate_count: 0 + + # Verbosity of console log messages. Acceptable values can be found # here: https://docs.python.org/library/logging.html#logging-levels A # custom debug level of "TRACE" is available for even more verbosity. #log_level: DEBUG - # Controls where and how the server logs messages. If unset, the - # default is to log all messages to standard output at the level - # defined by the `log_level` configuration option. Configuration is + # Controls where and how the server logs messages. If set, overrides + # all settings in the log_* configuration options. Configuration is # described in the documentation at: # https://docs.galaxyproject.org/en/master/admin/config_logging.html #logging: null diff --git a/lib/galaxy/config/schemas/config_schema.yml b/lib/galaxy/config/schemas/config_schema.yml index 97fc75b12c8..18efba8fa47 100644 --- a/lib/galaxy/config/schemas/config_schema.yml +++ b/lib/galaxy/config/schemas/config_schema.yml @@ -1871,12 +1871,41 @@ mapping: If true, Galaxy will attempt to configure a simple root logger if a "loggers" section does not appear in this configuration file. + log_destination: + type: str + default: stdout + required: false + desc: | + Log destination, defaults to special value "stdout" that logs to standard output. If set to anything else, + then it will be interpreted as a path that will be used as the log file, and logging to stdout will be + disabled. + + log_rotate_size: + type: str + default: "0" + required: false + desc: | + Size of log file at which size it will be rotated as per the documentation in + https://docs.python.org/library/logging.handlers.html#logging.handlers.RotatingFileHandler + If log_rotate_count is not also set, no log rotation will be performed. A value of 0 (the default) means no + rotation. Size can be a number of bytes or a human-friendly representation like "100 MB" or "1G". + + log_rotate_count: + type: int + default: 0 + required: false + desc: | + Number of log file backups to keep, per the documentation in + https://docs.python.org/library/logging.handlers.html#logging.handlers.RotatingFileHandler + Any additional rotated log files will automatically be pruned. If log_rotate_size is not also set, no log + rotation will be performed. A value of 0 (the default) means no rotation. + log_level: type: str default: DEBUG required: false desc: | - Verbosity of console log messages. Acceptable values can be found here: + Verbosity of console log messages. Acceptable values can be found here: https://docs.python.org/library/logging.html#logging-levels A custom debug level of "TRACE" is available for even more verbosity. @@ -1884,9 +1913,8 @@ mapping: type: map allowempty: true desc: | - Controls where and how the server logs messages. If unset, the default is to log all messages to standard - output at the level defined by the `log_level` configuration option. Configuration is described in the - documentation at: + Controls where and how the server logs messages. If set, overrides all settings in the log_* configuration + options. Configuration is described in the documentation at: https://docs.galaxyproject.org/en/master/admin/config_logging.html database_engine_option_echo: