Skip to content

Commit

Permalink
Log to sys.stderr if the user doesn't specify a file.
Browse files Browse the repository at this point in the history
  • Loading branch information
lohedges committed Jan 23, 2024
1 parent b5cab3e commit a3e393a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,10 @@ where the columns specify the current step, the in vacuo energy and the total
energy.

General log messages are written to the file specified by the `--log-file` or
`EMLE_LOG_FILE` options. (The default is `emle_log.txt`.) The log level can be
adjusted by using the `--log-level` or `EMLE_LOG_LEVEL` options. For performance,
the default log level is set to `ERROR`.
`EMLE_LOG_FILE` options. (By default, no log file is used and diagnostic messages
are written to `sys.stderr`.) The log level can be adjusted by using the
`--log-level` or `EMLE_LOG_LEVEL` options. For performance, the default log level
is set to `ERROR`.

```
# Step E_vac (Eh) E_tot (Eh)
Expand Down
11 changes: 6 additions & 5 deletions emle/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import shlex as _shlex
import shutil as _shutil
import subprocess as _subprocess
import sys as _sys
import tempfile as _tempfile
import yaml as _yaml

Expand Down Expand Up @@ -389,7 +390,7 @@ def __init__(
energy_frequency=1,
energy_file="emle_energy.txt",
log_level="ERROR",
log_file="emle_log.txt",
log_file=None,
save_settings=True,
):
"""Constructor.
Expand Down Expand Up @@ -521,9 +522,7 @@ def __init__(

# Validate the log file.

if log_file is None:
log_file = "emle_log.txt"
else:
if log_file is not None:
if not isinstance(log_file, str):
raise TypeError("'log_file' must be of type 'str'")

Expand All @@ -536,7 +535,9 @@ def __init__(
raise IOError(
f"Unable to create directory for log file: {log_file}"
)
self._log_file = _os.path.abspath(log_file)
self._log_file = _os.path.abspath(log_file)
else:
self._log_file = _sys.stderr

# Update the logger.
_logger.remove()
Expand Down

0 comments on commit a3e393a

Please sign in to comment.