Where are python logs default stored when ran through IPython notebook?

user2808117

In an IPython notebook cell I wrote:

import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
handler = logging.FileHandler('model.log')
handler.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)

Notice that I am supplying a file name, but not a path.

Where could I find that log? (ran a 'find' and couldn't locate it...)

famousgarkin

There's multiple ways to set the IPython working directory. If you don't set any of that in your IPython profile/config, environment or notebook, the log should be in your working directory. Also try $ ipython locate to print the default IPython directory path, the log may be there.

What about giving it an absolute file path to see if it works at all?

Other than that the call to logging.basicConfig doesn't seem to do anything inside an IPython notebook:

# In:
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger()
logger.debug('root debug test')

There's no output.

As per the docs, the logging.basicConfig doesn't do anything if the root logger already has handlers configured for it. This seems to be the case, IPython apparently already has the root logger set up. We can confirm it:

# In:
import logging
logger = logging.getLogger()
logger.handlers

# Out:
[<logging.StreamHandler at 0x106fa19d0>]

So we can try setting the root logger level manually:

import logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logger.debug('root debug test')

which yields a formatted output in the notebook:

enter image description here

Now onto setting up the file logger:

# In:
import logging

# set root logger level
root_logger = logging.getLogger()
root_logger.setLevel(logging.DEBUG)

# setup custom logger
logger = logging.getLogger(__name__)
handler = logging.FileHandler('model.log')
handler.setLevel(logging.INFO)
logger.addHandler(handler)

# log
logger.info('test info my')

which results in writing the output both to the notebook and the model.log file, which for me is located in a directory I started IPython and notebook from.

Mind that repeated calls to this piece of code without restarting the IPython kernel will result in creating and attaching yet another handler to the logger on every run and the number of messages being logged to the file with each log call will grow.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

iPython Notebook svg Figures by Default

From Dev

ipython notebook: how to toggle header invisible by default

From Dev

How to change default colour scheme for ipython notebook?

From Dev

run ipython notebook remotely through ssh tunneling

From Dev

Exception raised when running ipython notebook

From Dev

Default notebook directory in iPython Notebook - iPython 3.0.0

From Dev

IPython/Jupyter notebook 3 - hide headers by default

From Dev

Changing the default port for iPython notebook server / Jupyter

From Dev

iPython notebook error when trying to load matplotlib

From Dev

Ipython Notebook: Default Initialization Python Code

From Dev

Ipython Notebook: where is jupyter_notebook_config.py in Mac?

From Dev

Inline display when using GalSim on iPython Notebook

From Dev

Where are my roundcube logs stored?

From Dev

Default template for iPython notebook (using Jupyter)

From Dev

Where is ipython notebook hiding?

From Dev

Where are Datalab iPython notebook files stored on AppEngine?

From Dev

How to change location where logs are stored?

From Dev

Where is the "Default Wallpaper" wallpaper stored

From Dev

Producing comprehensible logs for shell script ran through xargs

From Dev

Where is the default location of the directory in which PowerShell scripts are ran?

From Dev

kernel busy when pylab is used in ipython notebook

From Dev

ipython notebook hang when open a large notebook

From Dev

Where are Apache file access logs stored?

From Dev

Where are 'wine' program execution logs stored?

From Dev

How to change location where logs are stored?

From Dev

Where is ipython notebook hiding?

From Dev

Where are Datalab iPython notebook files stored on AppEngine?

From Dev

Ipython notebook - Create a new notebook (Python conda or default Python)

From Dev

python don't extract zipfile when ran through crontab

Related Related

  1. 1

    iPython Notebook svg Figures by Default

  2. 2

    ipython notebook: how to toggle header invisible by default

  3. 3

    How to change default colour scheme for ipython notebook?

  4. 4

    run ipython notebook remotely through ssh tunneling

  5. 5

    Exception raised when running ipython notebook

  6. 6

    Default notebook directory in iPython Notebook - iPython 3.0.0

  7. 7

    IPython/Jupyter notebook 3 - hide headers by default

  8. 8

    Changing the default port for iPython notebook server / Jupyter

  9. 9

    iPython notebook error when trying to load matplotlib

  10. 10

    Ipython Notebook: Default Initialization Python Code

  11. 11

    Ipython Notebook: where is jupyter_notebook_config.py in Mac?

  12. 12

    Inline display when using GalSim on iPython Notebook

  13. 13

    Where are my roundcube logs stored?

  14. 14

    Default template for iPython notebook (using Jupyter)

  15. 15

    Where is ipython notebook hiding?

  16. 16

    Where are Datalab iPython notebook files stored on AppEngine?

  17. 17

    How to change location where logs are stored?

  18. 18

    Where is the "Default Wallpaper" wallpaper stored

  19. 19

    Producing comprehensible logs for shell script ran through xargs

  20. 20

    Where is the default location of the directory in which PowerShell scripts are ran?

  21. 21

    kernel busy when pylab is used in ipython notebook

  22. 22

    ipython notebook hang when open a large notebook

  23. 23

    Where are Apache file access logs stored?

  24. 24

    Where are 'wine' program execution logs stored?

  25. 25

    How to change location where logs are stored?

  26. 26

    Where is ipython notebook hiding?

  27. 27

    Where are Datalab iPython notebook files stored on AppEngine?

  28. 28

    Ipython notebook - Create a new notebook (Python conda or default Python)

  29. 29

    python don't extract zipfile when ran through crontab

HotTag

Archive