Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging Issues #11

Closed
HackToHell opened this issue Jan 17, 2016 · 3 comments
Closed

Logging Issues #11

HackToHell opened this issue Jan 17, 2016 · 3 comments

Comments

@HackToHell
Copy link

Essentially a continuation of issue #1, opening a separate issue as the old one is closed, get the message No handlers could be found for logger "apscheduler.executors.default". This happens when a error is present in the scheduler code. (The function that is called by the scheduler).
To test, please run this. It's modified off the one in the examples folder to throw an error.

https://gist.github.com/HackToHell/b8c73a2c6db53e9881ac
Output

 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
No handlers could be found for logger "apscheduler.executors.default"
No handlers could be found for logger "apscheduler.executors.default"

It seems to be an issue with APScheduler library itself, https://bitbucket.org/agronholm/apscheduler/issues/78/no-handlers-could-be-found-for-logger. So the suggested method to catch the errors is to have a basic logging setup ( http://stackoverflow.com/q/28724459/787563 ). I tried that and added it to the code. This resulted in flasks logging system's output being killed off.
I added

import logging
logging.basicConfig()

after the imports.

New Output - Shows the proper output. (Notice there's no message from flask present in the previous run)

F:\lalala>python balhbalh.py
ERROR:apscheduler.executors.default:Job "job1 (trigger: interval[0:00:10], next run at: 2016-01-17 14:55:04 IST)" raised an exception
Traceback (most recent call last):
  File "C:\Users\Gowtham\Miniconda\lib\site-packages\apscheduler\executors\base.py", line 112, in run_job
    retval = job.func(*job.args, **job.kwargs)
  File "balhbalh.py", line 21, in job1
    print(a + ' ' + b)
TypeError: unsupported operand type(s) for +: 'int' and 'str'
ERROR:apscheduler.executors.default:Job "job1 (trigger: interval[0:00:10], next run at: 2016-01-17 14:55:05 IST)" raised an exception
Traceback (most recent call last):
  File "C:\Users\Gowtham\Miniconda\lib\site-packages\apscheduler\executors\base.py", line 112, in run_job
    retval = job.func(*job.args, **job.kwargs)
  File "balhbalh.py", line 21, in job1
    print(a + ' ' + b)
TypeError: unsupported operand type(s) for +: 'int' and 'str'

This comment in the same SO thread says the very same to author of the library, however he says that it should not be the case. Unfortunately I am unable to debug the issue further due to my lack of experience with python's logging system(It's pretty weird).

Is there any way to resolve the issue by ideally having the output from flask and APScheduler in the same place ?

@viniciuschiele
Copy link
Owner

First of all, it only happens with Python 2.7, in Python 3.4 it works fine because the logging library has different behaviour between those versions.

Flask uses a logger called werkzeug with one handler StreamHandler attached into it that writes everything into the console. If you want you can check this out here: https://github.com/mitsuhiko/werkzeug/blob/master/werkzeug/_internal.py#L80

APScheduler uses another logger called apscheduler.executors, by default this logger doesn't have any handler attached for this reason you see this message No handlers could be found for logger.

Why does it work when calling basicConfig()?
Because this method attach a new StreamHandler to the logger called root, any unhandled log is handled by this root logger, it is a behaviour from logging library.

If you add manually a StreamHandler to the Root Logger it will works too.

logger = logging.getLogger()  # this returns the root logger 
logger.addHandler(logging.StreamHandler())

Usually I fix it just calling basicConfig() in the app startup

Any question let me know.

Cheers!

@HackToHell
Copy link
Author

Thanks, I switched to Python 3 and fixed the problem. I haven't got it working with python 2.7. I'll look into it when I have the time and post the code. Thanks again.

@viniciuschiele
Copy link
Owner

Ok, I will close it for now.
Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants