Skip to content

Commit

Permalink
less custom logfile location, documentation of logging in dev docs (#196
Browse files Browse the repository at this point in the history
)

* less custom logfile location, documentation of logging in dev docs

* add changelog entry
  • Loading branch information
nhoening committed Sep 28, 2021
1 parent a4dba7d commit e42fa6e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions documentation/changelog.rst
Expand Up @@ -22,6 +22,7 @@ Infrastructure / Support
* FlexMeasures plugins can be Python packages now. We provide `a cookie-cutter template <https://github.com/SeitaBV/flexmeasures-plugin-template>`_ for this approach. [see `PR #182 <http://www.github.com/SeitaBV/flexmeasures/pull/182>`_]
* Set default timezone for new users using the FLEXMEASURES_TIMEZONE config setting [see `PR #190 <http://www.github.com/SeitaBV/flexmeasures/pull/190>`_]
* Monitored CLI tasks can get better names for identification [see `PR #193 <http://www.github.com/SeitaBV/flexmeasures/pull/193>`_]
* Less custom logfile location, document logging for devs [see `PR #196 <http://www.github.com/SeitaBV/flexmeasures/pull/196>`_]


v0.6.1 | September XX, 2021
Expand Down
9 changes: 9 additions & 0 deletions documentation/dev/introduction.rst
Expand Up @@ -68,6 +68,15 @@ Or:
And access the server at http://localhost:5000


Logfile
--------

FlexMeasures logs to a file called ``flexmeasures.log``. You'll find this in the application's context folder, e.g. where you called ``flexmeasures run``.

A rolling log file handler is used, so if ``flexmeasures.log`` gets to a few megabytes in size, it is copied to `flexmeasures.log.1` and the original file starts over empty again.

The default logging level is ``WARNING``. To see more, you can update this with the config setting ``LOGGING_LEVEL``, e.g. to ``INFO`` or ``DEBUG``


Tests
-----
Expand Down
2 changes: 1 addition & 1 deletion flexmeasures/app.py
Expand Up @@ -31,7 +31,7 @@ def create(env: Optional[str] = None, path_to_config: Optional[str] = None) -> F

# Create app

configure_logging() # do this first, see http://flask.pocoo.org/docs/dev/logging/
configure_logging() # do this first, see https://flask.palletsprojects.com/en/2.0.x/logging
# we're loading dotenv files manually & early (can do Flask.run(load_dotenv=False)),
# as we need to know the ENV now (for it to be recognised by Flask()).
load_dotenv()
Expand Down
6 changes: 2 additions & 4 deletions flexmeasures/utils/config_utils.py
Expand Up @@ -16,14 +16,12 @@
)


basedir = os.path.abspath(os.path.dirname(__file__))

flexmeasures_logging_config = {
"version": 1,
"formatters": {
"default": {"format": "[FLEXMEASURES][%(asctime)s] %(levelname)s: %(message)s"},
"detail": {
"format": "[FLEXMEASURES][%(asctime)s] %(levelname)s: %(message)s [log made in %(pathname)s:%(lineno)d]"
"format": "[FLEXMEASURES][%(asctime)s] %(levelname)s: %(message)s [logged in %(pathname)s:%(lineno)d]"
},
},
"handlers": {
Expand All @@ -36,7 +34,7 @@
"class": "logging.handlers.RotatingFileHandler",
"level": "INFO",
"formatter": "detail",
"filename": basedir + "/../../flexmeasures.log",
"filename": "flexmeasures.log",
"maxBytes": 10_000_000,
"backupCount": 6,
},
Expand Down

0 comments on commit e42fa6e

Please sign in to comment.