Xingdi
Xingdi

Reputation: 81

Tensorflow how to enable logging to print out?

In the object-detection API code, I saw many logging statements in the source code, but when I run the program, none of them actually print out.

I found that these logging statements are not using tf.logging, instead they are using the sysmtem logging, such as

import logging
#do some fancy job here
logging.info("this is a test")

How to enable these logging statements to print out? I know I can insert a piece of code in the python source file, such as

logger = logging.getLogger()    # initialize logging class
logger.setLevel(logging.DEBUG)  # default log level
format = logging.Formatter("%(asctime)s - %(message)s")    # output format 
sh = logging.StreamHandler(stream=sys.stdout)    # output to standard output
sh.setFormatter(format)
logger.addHandler(sh)

But this is tedious, I need to insert this piece of code in each source file. Is there some smart way to to activate the system logging statements?

Upvotes: 1

Views: 2019

Answers (1)

gdelab
gdelab

Reputation: 6220

You only need this piece of code to be run once before all the others work (it will create a log handler that is stored statically in logging, all subsequent calls to any logging functions will fnind and use this handler), so for instance you can add it at the start of the main function in train.py and eval.py. Or you can use your own wrapper script, that basically creates the logger and calls the main functions from eval.py and train.py.

Upvotes: 1

Related Questions