{"action":"created","issue":{"url":"https://api.github.com/repos/jupyter/notebook/issues/1397","repository_url":"https://api.github.com/repos/jupyter/notebook","labels_url":"https://api.github.com/repos/jupyter/notebook/issues/1397/labels{/name}","comments_url":"https://api.github.com/repos/jupyter/notebook/issues/1397/comments","events_url":"https://api.github.com/repos/jupyter/notebook/issues/1397/events","html_url":"https://github.com/jupyter/notebook/issues/1397","id":151357875,"number":1397,"title":"The python logging module no longer seems to work properly inside a notebook","user":{"login":"tudorprodan","id":1012368,"avatar_url":"https://avatars.githubusercontent.com/u/1012368?v=3","gravatar_id":"","url":"https://api.github.com/users/tudorprodan","html_url":"https://github.com/tudorprodan","followers_url":"https://api.github.com/users/tudorprodan/followers","following_url":"https://api.github.com/users/tudorprodan/following{/other_user}","gists_url":"https://api.github.com/users/tudorprodan/gists{/gist_id}","starred_url":"https://api.github.com/users/tudorprodan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tudorprodan/subscriptions","organizations_url":"https://api.github.com/users/tudorprodan/orgs","repos_url":"https://api.github.com/users/tudorprodan/repos","events_url":"https://api.github.com/users/tudorprodan/events{/privacy}","received_events_url":"https://api.github.com/users/tudorprodan/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/jupyter/notebook/milestones/8","html_url":"https://github.com/jupyter/notebook/milestones/not%20notebook","labels_url":"https://api.github.com/repos/jupyter/notebook/milestones/8/labels","id":1350781,"number":8,"title":"not notebook","description":"","creator":{"login":"minrk","id":151929,"avatar_url":"https://avatars.githubusercontent.com/u/151929?v=3","gravatar_id":"","url":"https://api.github.com/users/minrk","html_url":"https://github.com/minrk","followers_url":"https://api.github.com/users/minrk/followers","following_url":"https://api.github.com/users/minrk/following{/other_user}","gists_url":"https://api.github.com/users/minrk/gists{/gist_id}","starred_url":"https://api.github.com/users/minrk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/minrk/subscriptions","organizations_url":"https://api.github.com/users/minrk/orgs","repos_url":"https://api.github.com/users/minrk/repos","events_url":"https://api.github.com/users/minrk/events{/privacy}","received_events_url":"https://api.github.com/users/minrk/received_events","type":"User","site_admin":false},"open_issues":10,"closed_issues":22,"state":"open","created_at":"2015-10-12T12:46:51Z","updated_at":"2016-04-27T11:12:02Z","due_on":null,"closed_at":null},"comments":6,"created_at":"2016-04-27T10:58:53Z","updated_at":"2016-04-27T12:58:51Z","closed_at":null,"body":"When running the example from the python logging documentation page in a jupyter notebook, the messages go to the notebook console as opposed to the notebook's webpage output via the capture mechanism. Just create an empty notebook, run the example below, you'll see what I mean.\r\n\r\n```python\r\nimport logging\r\nlogging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)\r\nlogging.debug('This message should appear on the console')\r\nlogging.info('So should this')\r\nlogging.warning('And this, too')\r\n```\r\n\r\nThe logging module by default creates a `StreamHandler` object which will `if not stream: stream = sys.stderr`. A lot of modules use the logging module as in the example.\r\n\r\nThe problem is that the notebook actually inits the logging module before the output capture mechanism is set, so the default created `StreamHandler` actually has a reference to the original `sys.stdout`, before the notebook replaces it with it's own `ipykernel.iostream.OutStream`.\r\n\r\nShouldn't the notebook reset the logging module?\r\n\r\nI've been looking into this because after an upgrade I noticed missing output from some stuff I was running often."},"comment":{"url":"https://api.github.com/repos/jupyter/notebook/issues/comments/215073833","html_url":"https://github.com/jupyter/notebook/issues/1397#issuecomment-215073833","issue_url":"https://api.github.com/repos/jupyter/notebook/issues/1397","id":215073833,"user":{"login":"tudorprodan","id":1012368,"avatar_url":"https://avatars.githubusercontent.com/u/1012368?v=3","gravatar_id":"","url":"https://api.github.com/users/tudorprodan","html_url":"https://github.com/tudorprodan","followers_url":"https://api.github.com/users/tudorprodan/followers","following_url":"https://api.github.com/users/tudorprodan/following{/other_user}","gists_url":"https://api.github.com/users/tudorprodan/gists{/gist_id}","starred_url":"https://api.github.com/users/tudorprodan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tudorprodan/subscriptions","organizations_url":"https://api.github.com/users/tudorprodan/orgs","repos_url":"https://api.github.com/users/tudorprodan/repos","events_url":"https://api.github.com/users/tudorprodan/events{/privacy}","received_events_url":"https://api.github.com/users/tudorprodan/received_events","type":"User","site_admin":false},"created_at":"2016-04-27T12:58:51Z","updated_at":"2016-04-27T12:58:51Z","body":"As far as I can tell, jupyter spawns a subprocess for each open notebook. This subprocess then spawns a thread for tornado.\r\nIs my understanding correct?\r\n\r\nIf so, then all we have to do is configure the root logger with the proper captured sys.stderr and all will be well."}}