Open jypeter opened 3 years ago
CliMAF creates the logfile in the directory indicated by environment variable CIMAF_LOG_DIR (which defaullts to "./"). See relevant doc paragraph
Oh, OK! Well, Running CliMAF interactively below the paragraph you mention indeed says please first make sur you have write permission in the current directory (used for some log files)
But it would be nice (for the users) to check (at the beginning of a script/session) if whatever is specified for CLIMAF_LOG_DIR
(default or not) is writable, and abort with an error message about this otherwise.
It would also be nice if there was a clog_file
parameter that you could use to completely disable the log file
BTW:
verbosity
, severity
and critical
, but I have not found anything defining the different levels. Are they only defined in the example notebooks? I was wondering if there was a special level that I could use for completely disabling the log file output (e.g. something like clog_file('none')
)I have solved my problem by adding the following code to my script before importing CliMAF
# Check the WRITE access of the directory that will be used for
# writing the CliMAF log file, and silently specify a writable
# directory if the initial directory is NOT writable
#
# CliMAF uses the directory specified in the CLIMAF_LOG_DIR
# environment variable, if defined, or the current directory
#
# If we don't do this, and a user executes a script importing CliMAF
# in a directory where (s)he has no write access, CliMAF will generate
# a PermissionError traceback that may confuse the user
#
# https://github.com/rigoudyg/climaf/issues/192
climaf_log_dir = os.environ.get('CLIMAF_LOG_DIR', os.path.curdir)
# print('Current CliMAF log directory =', climaf_log_dir)
if not os.access(climaf_log_dir, mode=os.W_OK):
# NO write-access, we force the log directory to be '/tmp'
os.environ['CLIMAF_LOG_DIR'] = '/tmp'
# print('New CliMAF log directory', os.environ['CLIMAF_LOG_DIR'])
# Import CliMAF and specify some CliMAF settings
from climaf.api import *
BTW:
* there is no documentation for [clog and clog_file](https://climaf.readthedocs.io/en/latest/functions_utilities.html?highlight=LOG#clog-tune-verbosity)
There was a bug in the doc source file. This is fixed by #216
* I have searched the documentation (possibly too quickly) for `verbosity`, `severity` and `critical`, but I have not found anything defining the different levels. Are they only defined in the example notebooks? I was wondering if there was a special level that I could use for completely disabling the log file output (e.g. something like `clog_file('none')`)
The relevant level to use is 'crtitical', because it means that CliMAF can't work normally from meeting that level of issues
Pull request #216
Severity levels are Python's logging standards (see https://docs.python.org/3.6/library/logging.html?highlight=logging#logging-levels)
I got a surprising error. After investigating, it seems that CliMAF tries to create a
climaf.log
file at import time in whatever the current directory is, and fails of course if the user doesn't have write access.I guess the log file should be created in the home directory, the cache, the tmpdir, the /tmp dir, or somewhere that makes sense (if we want to retrieve the log file) and will not generate an error
Example below: I initialize CliMAF, and go to @jservonnat home dir
And then I start python and try to import CliMAF...