1

I have a Python script using https://abseil.io/docs/python/guides/logging.

Documentation does not specify how to set output file like in PEP 282.

I thought that Abseil Logging is built on top of the standard Python logging and I could just set the logging.basicConfig(filename='myapp.log', level=logging.INFO)

But I get:

AttributeError: module 'absl.logging' has no attribute 'basicConfig'

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
engineer-x
  • 2,173
  • 2
  • 12
  • 25

2 Answers2

0

For PEP-282 formatted output, use:

logging.basicConfig(filename='myapp.log', level=logging.INFO)
J_H
  • 17,926
  • 4
  • 24
  • 44
0

You can set it via the command line:

python --log_dir=/path/to/my/logs

See the (limited) flag documentation by running --helpfull and looking at the absl.logging module.

You can also change it in code (somewhat convolutedly) by calling:

from absl import logging

# ...

logging.get_absl_handler().python_handler.use_absl_log_file(log_dir='/whatever')
print('Logging to: %s' % logging.get_log_file_name())

This will print something like /whatever/py_<myprog>.<hostname>.log.INFO.<ts>. Note that this also creates a friendlier symlink for your latest run that's just /whatever/py_<myprog>.INFO.

kris
  • 23,024
  • 10
  • 70
  • 79