I'm trying to set up a logger that will log to the console (I want this because I'm using Heroku with Papertrails (Heroku's logging addon) and stuff written to the console will show up in Papertrails, making it filterable and all the nice Papertrail features.)
In settings I was first trying the following:
LOGGING = {
'handlers' = {
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': 'mysite.log',
'formatter': 'verbose'
},
'console':{
'level': 'DEBUG',
'class': 'logging.StreamHandler',
},
},
(...)
'loggers'={
(...)
'page_processors': {
'handlers': ['console','file'],
'level': 'DEBUG',
}
}
(...)
}
as per the Django's logging page (for those who don't use Mezzanine, page_processors are what Mezzanine runs whenever you open a page; you can think of them as being like Django's views, but they only do the context, not the rendering).
On page_processors.py I have
import logging
logger = logging.getLogger(__name__)
@process_for(MyPage):
def myfunc(request, Page):
logger.info('page_processor logging test')
print 'my page_processor print'
(...)
When I refresh the page I don't see the logger but I see the print AND the log to the file:
[02/Mar/2014 23:07:10] INFO [myApp.page_processors:13] page_progessor logging test
and so I know the logic is working. After googling a bit, I found this and this page that addresses precisely this issue. He says that by default logging.StreamHandler logs to STDERR. If we want to log to STDOUT you should add the keyword argument 'stream' to the logging.StreamHandler construct, and so configure the handler as such:
'handlers':{
(...)
'console':{
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'stream': sys.stdout
},
}
Turns out this still doesn't work, and I don't get any error or anything, and I still see the print and the file log. Just not the console logger.
What's going on?
EDIT: I tried this, doesn't make a difference.