Logging

optuna.logging.get_verbosity()[source]

Return the current level for the Optuna’s root logger.

Returns:Logging level, e.g., optuna.logging.DEBUG and optuna.logging.INFO.

Note

Optuna has following logging levels:

  • optuna.logging.CRITICAL, optuna.logging.FATAL
  • optuna.logging.ERROR
  • optuna.logging.WARNING, optuna.logging.WARN
  • optuna.logging.INFO
  • optuna.logging.DEBUG
optuna.logging.set_verbosity(verbosity)[source]

Set the level for the Optuna’s root logger.

Parameters:verbosity – Logging level, e.g., optuna.logging.DEBUG and optuna.logging.INFO.
optuna.logging.disable_default_handler()[source]

Disable the default handler of the Optuna’s root logger.

Example

Stop and then resume logging to standard output.

>> study = optuna.create_study()
>> optuna.logging.disable_default_handler()
>> study.optimize(objective, n_trials=10)
>> len(study.trials)
10
>> optuna.logging.enable_default_handler()
>> study.optimize(objective, n_trials=10)
[I 2018-11-07 16:11:28,285] Finished a trial resulted in value: 3787.44371584515. ...
optuna.logging.enable_default_handler()[source]

Enable the default handler of the Optuna’s root logger.

Please refer to the example shown in disable_default_handler().

optuna.logging.disable_propagation()[source]

Disable propagation of the library log outputs.

Note that log propagation is disabled by default.

optuna.logging.enable_propagation()[source]

Enable propagation of the library log outputs.

Please disable the Optuna’s default handler to prevent double logging if the root logger has been configured.

Example

Propagate all log output to the root logger in order to save them to the file.

>> logging.getLogger().setLevel(logging.INFO)  # Setup the root logger.
>> logging.getLogger().addHandler(logging.FileHandler('foo.log'))

>> optuna.logging.enable_propagation()  # Propagate logs to the root logger.
>> optuna.logging.disable_default_handler()  # Stop showing logs in stderr.

>> study = optuna.create_study()
>> logging.getLogger().info("Start optimization.")
>> study.optimize(objective, n_trials=10)
>> open('foo.log').readlines()
["Start optimization.", "Finished trial#0 resulted in value: ...