#180 Get logging to work.
Closed 5 years ago by ralph. Opened 5 years ago by ralph.
ralph/waiverdb get-logging-working  into  master

file modified
+2
@@ -14,6 +14,8 @@ 

          sh 'sudo dnf -y install dnf-utils'

          /* Unit tests need local Postgres */

          sh """

+         sudo dnf -y remove postgresql-server || true

+         sudo rm -rf /var/lib/pgsql/ || true

          sudo dnf -y install postgresql-server

          sudo postgresql-setup --initdb

          sudo systemctl enable --now postgresql

file modified
+5
@@ -141,6 +141,7 @@ 

      conf/client.conf.example \

      %{buildroot}%{_sysconfdir}/waiverdb/client.conf

  

+ %if 0%{?fedora} || 0%{?rhel} > 7

  install -D -m0644 \

      docs/_build/man/waiverdb-cli.1 \

      %{buildroot}%{_mandir}/man1/waiverdb-cli.1
@@ -148,6 +149,7 @@ 

  install -D -m0644 \

      docs/_build/man/waiverdb.7 \

      %{buildroot}%{_mandir}/man7/waiverdb.7

+ %endif

  

  # Tests don't make sense here now that we require postgres to run them.

  #%%check
@@ -184,8 +186,11 @@ 

  %endif

  %attr(755,root,root) %{_bindir}/waiverdb-cli

  %config(noreplace) %{_sysconfdir}/waiverdb/client.conf

+ 

+ %if 0%{?fedora} || 0%{?rhel} > 7

  %{_mandir}/man1/waiverdb-cli.1*

  %{_mandir}/man7/waiverdb.7*

+ %endif

  

  %post

  %systemd_post %{name}.service

file modified
+1 -1
@@ -41,7 +41,7 @@ 

          user = str(sc.initiator_name)

          return user, token

      except gssapi.exceptions.GSSError as e:

-         current_app.logger.error(

+         current_app.logger.exception(

              'Unable to authenticate: failed to %s: %s' %

              (stage, e.gen_message()))

          raise Forbidden("Authentication failed")

file modified
+9 -10
@@ -1,21 +1,20 @@ 

  # SPDX-License-Identifier: GPL-2.0+

  

  import logging

- import sys

  

  

- def log_to_stdout(level=logging.INFO):

-     fmt = '%(asctime)s [pid %(process)5d] %(name)s %(levelname)s %(message)s'

-     datefmt = '%Y-%m-%d %H:%M:%S'

-     stream_handler = logging.StreamHandler(sys.stdout)

-     stream_handler.setLevel(level)

-     stream_handler.setFormatter(logging.Formatter(fmt=fmt, datefmt=datefmt))

-     logging.getLogger().addHandler(stream_handler)

+ def log_to_gunicorn(app):

+     gunicorn_logger = logging.getLogger('gunicorn.error')

+     # Wire up the root logger to forward to gunicorn's handlers

+     logging.getLogger().handlers = gunicorn_logger.handlers

+     logging.getLogger().setLevel(gunicorn_logger.level)

+     # Wire up the flask logger to forward to gunicorn's handlers

+     app.logger.handlers = gunicorn_logger.handlers

+     app.logger.setLevel(gunicorn_logger.level)

  

  

  def init_logging(app):

-     log_level = logging.DEBUG if app.debug else logging.INFO

-     log_to_stdout(level=log_level)

+     log_to_gunicorn(app)

      # In general we want to see everything from our own code,

      # but not detailed debug messages from third-party libraries.

      # Note that the log level on the handler above controls what

Gunicorn has been swallowing all of our log output in openshift making it
impossible to know what's going on. Tested locally, this gets us output to
stdout from both the flask app and the root logger.

1 new commit added

  • Remove old database before starting.
5 years ago

3 new commits added

  • Don't build and install manpages on el7.
  • Remove old database before starting.
  • Get logging to work.
5 years ago

Hmmm. I thought I fixed this already :grimacing:

But I guess in dev we don't use gunicorn so the behaviour is different...

For one thing, you shouldn't need to treat the Flask app logger separately, I thought that was already turned off so that it would just propagate to the root logger (for simplicity).

I actually thought gunicorn removed all its settings which messed with Python logging many releases ago, to avoid this kind of problem, but maybe not...

Yeah, something up here. Without this change, I got zero information out of that kerberos authn issue. :/

OK. We figured out in channel that passing --enable-stdio-inheritance to gunicorn was the way to go.

Pull-Request has been closed by ralph

5 years ago