I dug around in logconfig and in the bokeh/commands/subcommands/serve.py and think I understand why logconfig.basicConfig and logging.basicConfig do not affect the format that gets sent to the terminal
There is this line in the logging documentation for Python 3:
This function does nothing if the root logger already has handlers configured for it.
But the invoke function inside of serve.py has already called logconfig.basicConfig once, which configured a handler for the root. The logconfig.basicConfig function checks if the bokeh_logger has handlers and removes them before calling logging.basicConfig, but it does not remove the root logger handler, so it also does nothing when called in an app.
The workaround I’ve found from from inside of the app is:
FORMAT = '%(asctime)-15s %(levelname)s:%(name)s: %(message)s" #just a simple format string
formatter = logging.Formatter(FORMAT) #create a formatter
root_logger = logging.getLogger() #get a handle to the root logger
for h in root_logger.handlers:
h.setFormatter(formatter) #loop over all the handlers assigned to the root and set the formatter
Or one can use the --log-format argument when calling bokeh serve.
This seems like a mild documentation bug in the bokeh server. I’ll go to github and try to open an issue.
On Thursday, April 18, 2019 at 3:04:13 PM UTC-4, Bryan Van de Ven wrote:
Unfortunately I am not an expert about Python logging at all. All the Bokeh logger configuration is here:
That code was mostly contributed by other people, with the aim of making Deprecation warnings visible by default. Perhaps setting one of the logger instances in that module (bokeh, root, or default) will provide the result you want. If there are improvements we can make to that code, please open an issue/PR to share your expertise.
On Apr 18, 2019, at 8:18 AM, ‘Steve Maxwell’ via Bokeh Discussion - Public [email protected] wrote:
I am running an app in bokeh server that uses an instance of an object defined in a module separate from the app. The object logs various debug messages using a format string FORMAT that is fed into the logging module via logging.basicConfig(format=FORMAT)
In non-bokeh apps, this works fine. When I run a bokeh app, the messages that appear in the windows 10 console from which I launch the server and app have been stripped of the custom formatting.
I have tried the following things:
– run logging.basicConfig(format=FORMAT) within the main app. This does not fix the problem
– import logconfig from bokeh.util and then run logconfig.basicConfig(format=FORMAT). This also does not fix the problem
– add a StreamHandler to the object in the init function with the correct formatting specified. This results in duplicate log outputs in the console, half of which have the desired formatting.
My question is this: how can I get access to the handler that is formatting output to the console and modify the format string?
You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/1b0ca219-9c75-4cba-b991-07f9dfba973d%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.