13165

Configure module logger to flask app logger

Question:

My flask application uses a module which gets a logger like this:

import logging logger = logging.getLogger("XYZ") ... logger.debug("stuff")

Without having to modify anything in the module, can I configure flask such that the module will get flask's app.logger when it makes the getLogger("XYZ") call?

Answer1:

Yes, you can configure it.

By default flask logger's name is your app name, but flask has setting <a href="http://flask.pocoo.org/docs/config/#builtin-configuration-values" rel="nofollow">LOGGER_NAME</a>.

Answer2:

<a href="https://stackoverflow.com/a/18379764/747872" rel="nofollow">This</a> solution worked to me:

import logging logger = logging.getLogger('werkzeug') logger.debug('stuff')

The default Flask configuration seems to use the logger name werkzeug. Adding or changing handlers for this logger changes the way Flask logs.

PS.: Python 3.5, Flask 0.12.2

Recommend

  • Android Studio appengine endpoint does not include builder
  • Serialize Date, Instant to ISO 8601 when using JSR310 java.time in spring
  • python logging with multiprocessing, root logger different in windows
  • How to search a string in inner array using mongodb?
  • logging static methods in a parent class
  • Modifying files nested in tar archive
  • Replace and retrieve placeholder value
  • auth.provider is not set to 'password' when user signs-in with email and password
  • How do I retrieve the user information of a user authenticated with Apache's mod_ldap?
  • Possible to “watch” both HAML and SASS at the same time?
  • How to autopopulate a field in SugarCRM form
  • How to specify input and output paths from cmd.exe for a PowerShell script?
  • How do I configure context broker accept post requests from my remote sensor?
  • OOP Javascript - Is “get property” method necessary?
  • How do I exclude a dependency in provided scope when running in Maven test scope?
  • Alternative To body {overflow:scroll;} That Will Prevent Page Jostling/Wriggling?
  • Is there a perl module to validate passwords stored in “{crypt}hashedpassword” “{ssha}hashedpassword
  • Setting up SourceTree to merge unity3d scenes with UnityYAMLMerge
  • Meteor helpers not available in Angular template
  • Can I check if a recipient has an automatic reply before I send an email?
  • Master page gives error
  • Getting last autonumber in access
  • req.body is undefined - nodejs
  • C# - Serializing and deserializing static member
  • swift auto completion not working in Xcode6-Beta
  • Sending data from AppleScript to FileMaker records
  • Symfony2: How to get request parameter
  • Redux, normalised entities and lodash merge
  • Akka Routing: Reply's send to router ends up as dead letters
  • Is there a mandatory requirement to switch app.yaml?
  • How to include full .NET prerequisite for Wix Burn installer
  • using HTMLImports.whenReady not working in chrome
  • -fvisibility=hidden not passed by compiler for Debug builds
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Change div Background jquery
  • How does Linux kernel interrupt the application?
  • Is it possible to post an object from jquery to bottle.py?
  • Busy indicator not showing up in wpf window [duplicate]
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • Why do underscore prefixed variables exist?