Skip to content

Commit

Permalink
Merge pull request sopel-irc#2419 from sopel-irc/logging-channel-max-…
Browse files Browse the repository at this point in the history
…level

logging: disallow `DEBUG` channel logs & stop inheriting console log level
  • Loading branch information
dgw authored Mar 18, 2023
2 parents 4efc48e + bb4d5e8 commit 4bc3233
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
19 changes: 15 additions & 4 deletions docs/source/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -807,9 +807,10 @@ Log to a Channel
----------------

It is possible to send logs to an IRC channel, by configuring
:attr:`~CoreSection.logging_channel`. By default, it uses the same log level,
format, and date-format parameters as console logs. This can be overridden
with these settings:
:attr:`~CoreSection.logging_channel`. By default, it logs ``WARNING`` or higher
messages, using the same date and log-line format parameters as the console
logging output. The following settings can be used to customize output to the
logging channel:

* ``format`` with :attr:`~CoreSection.logging_channel_format`
* ``datefmt`` with :attr:`~CoreSection.logging_channel_datefmt`
Expand All @@ -825,12 +826,22 @@ Example of configuration to log errors only in the ``##bot_logs`` channel::
logging_channel_level = ERROR
logging_channel_format = %(message)s

.. note::

``DEBUG`` is not supported for ``logging_channel_level``. The bot would
either flood itself off the network or spend most of its time waiting for
flood protection delays (thus becoming unusable).

.. versionadded:: 7.0

Configuration options ``logging_channel_level``, ``logging_channel_format``
and ``logging_channel_datefmt`` has been added to extend logging
and ``logging_channel_datefmt`` have been added to extend logging
configuration.

.. versionchanged:: 8.0

Channel logging no longer inherits the console ``logging_level`` setting.

Raw Logs
--------

Expand Down
3 changes: 1 addition & 2 deletions sopel/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,12 @@ def setup(self) -> None:
def setup_logging(self) -> None:
"""Set up logging based on config options."""
logger.setup_logging(self.settings)
base_level = self.settings.core.logging_level or 'INFO'
base_format = self.settings.core.logging_format
base_datefmt = self.settings.core.logging_datefmt

# configure channel logging if required by configuration
if self.settings.core.logging_channel:
channel_level = self.settings.core.logging_channel_level or base_level
channel_level = self.settings.core.logging_channel_level
channel_format = self.settings.core.logging_channel_format or base_format
channel_datefmt = self.settings.core.logging_channel_datefmt or base_datefmt
channel_params = {}
Expand Down
10 changes: 7 additions & 3 deletions sopel/config/core_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,17 +868,21 @@ def homedir(self):

logging_channel_level = ChoiceAttribute('logging_channel_level',
['CRITICAL', 'ERROR', 'WARNING',
'INFO', 'DEBUG'],
'INFO'],
'WARNING')
"""The lowest severity of logs to display in IRC channel logs.
If not specified, this falls back to using :attr:`logging_level`.
.. seealso::
The :ref:`Log to a Channel` chapter.
.. versionadded:: 7.0
.. versionchanged:: 8.0
No longer uses the value of :attr:`logging_level` if not set. Removed
``DEBUG`` from the available choices; setting it caused the bot to get
caught in an ever-increasing flood prevention loop.
"""

logging_datefmt = ValidatedAttribute('logging_datefmt')
Expand Down

0 comments on commit 4bc3233

Please sign in to comment.