Skip to content

Commit

Permalink
Update code_style.rst
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulcollenteur committed Apr 9, 2024
1 parent 60dc397 commit 1199278
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions doc/developers/code_style.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,34 @@ Private methods in Pastas are identified by a leading underscore. For example:
This basically means that these methods may be removed or their behaviour may
be changed without DeprecationWarning or any other form of notice.

Logger Calls
------------
Logger Calls and Errors
-----------------------

A logger is used to provide information to the user and log info, warning, error
messages. The logger is created using the `logging <https://docs.python.org/3/library/logging.html>`_
module. The logger is created at the top of each file and can be imported in any module
using:

>>> import logging
>>> logger = logging.getLogger(__name__)

Info messages are logged using:

>>> msg = "Message here, %s"
>>> logger.info(msg, value)

When a message to the logger is provided, it is important to use the
s-string format (no f-strings) to prevent performance issues:
s-string format (no f-strings) to prevent performance issues.

Warning messages are logged using:

>>> logger.warning(msg, value)

Error messages are logged, and raised using the appropriate error using:

>>> logger.info("Message here: %s", value)
>>> logger.error(msg, value)
>>> raise ValueError(msg % value)

When raising an error, the error message should be provided in the logger.error method,
and the error should be raised immediately after. This is to ensure that the error
message is logged before the error is raised.

0 comments on commit 1199278

Please sign in to comment.