Reputation: 10128
I wrote some script which renders scenes and want see output on console I am using print but it not works what I should use to print something.
I run script with:
blender -b -P render.py
Want output such string from render.py:
print '#' * 80
It is little trivial question but print not works and not know how to progress development without debug messages.
Upvotes: 1
Views: 7571
Reputation: 661
use the logging module to setup your custom logger.
you can setup a Console handler to log the content to the console or/and
formatter = logging.Formatter('%(message)s')
console_handler = logging.StreamHandler(sys.stdout)
console_handler.setFormatter(formatter)
setup a File handler if you want to log to a file:
file_handler = logging.FileHandler(log_file)
file_handler.setFormatter(formatter)
# Add the handler to the logger:
logger.addHandler(console_handler)
logger.addHandler(file_handler)
They can both have different log levels which you can set via script or environement variable:
log_level = level
if 'LOG_LEVEL' in os.environ:
log_level = os.environ['LOG_LEVEL']
console_handler.setLevel(log_level)
file_handler.setLevel('INFO')
Read trough: https://docs.python.org/3/howto/logging.html
Upvotes: 2