28

I'm using the Freebase Python library. It creates a log before executing:

self.log = logging.getLogger("freebase")

Where is this log in the file system? It's not in the executing directory or tmp.

Matt Norris
  • 7,408
  • 11
  • 51
  • 88
  • 1
    I noticed a downvote on this question without any explanation. I would appreciate it if the person downvoting would let me know why so I can be sure to be more clear in the future. – Matt Norris Apr 20 '14 at 19:46
  • To save the log into a file, we have to use logging.basicConfig(filename = 'blah',...) if we don't use that, the logger just prints stuff to command line, or standard output. – user44875 Aug 27 '19 at 09:40

1 Answers1

28

That call does not store anything. It merely creates a logger object which can be bound and configured however you would like.

So if in your Python code, you were to add

logging.basicConfig(level=logging.WARNING)

All warnings and errors would be logged to the standard output (that's what basicConfig does), including the calls that Freebase makes. If you want to log to the filesystem or other target, you'll want to reference the logging module documentation for more information. You may also wish to reference the Logging HOWTO.

Jason R. Coombs
  • 36,798
  • 8
  • 75
  • 83
  • 10
    +1 to what Jason said. You can also do e.g. `logging.basicConfig(filename='/path/to/file.log', filemode='w', level=logging.DEBUG)` to do simple logging of everything to a file. – Vinay Sajip Oct 28 '10 at 12:29
  • So, after `self.log` is defined as in @Matt Norris' question, subsequent calls to `self.logger.debug` will not be saved to disk (assuming no intermediate calls are made)? – dbliss Feb 27 '15 at 23:49
  • @dbliss If you configured logging per Vinay's suggestion, subsequent calls to `self.log.debug` would be written to the file. If you configured logging per my answer instead, calls to `self.log.debug` would be ignored because they're below the specified level of `logging.WARNING`. – Jason R. Coombs Mar 02 '15 at 16:31
  • 1
    What if you didn't bother to configure it at all? (I'm trying to reverse-engineer a package I didn't write, in which the logger was not configured.) My question is, what's the default location to which `self.logger.debug` calls are saved? – dbliss Mar 02 '15 at 20:19
  • 3
    If the code were not to configure any handlers (i.e. nothing calls `basicConfig` or otherwise configures logging), the default behavior is that messages WARNING and above are emitted to standard error and messages below WARNING (including INFO and DEBUG) are discarded. – Jason R. Coombs Mar 03 '15 at 19:53