various routines to log and control the output. The idea is that decisions about where to log should not be done in the code that generates the log, but should be globally changeable a central place. So some care has been taken to have enough information about the place from where the log comes so that in the future intelligent and flexible decisions can be taken by the logger, without having to change other code.
Note
contains also routines to convert to a string. in my idea they should have been with variable length, (i.e. they should have returned a trim(adjustl(actual_result))) As a logger should be robust, at the moment I have given up. At the moment logging and output refer to the same object (dbcsr_logger_type) as these are actually different it might be better to separate them (they have already separate routines in a separate module @see dbcsr_output_handling). some practices (use of print *, no dbcsr_error_type, manual retain release of some objects) are dictated by the need to have minimal dependency
@see dbcsr_error_handling @version 12.2001
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
character(len=*), | private, | parameter | :: | moduleN | = | 'dbcsr_log_handling' | |
logical, | private, | parameter | :: | debug_this_module | = | .FALSE. |
level of an error |
integer, | public, | parameter | :: | dbcsr_fatal_level | = | 3 |
level of a failure |
integer, | public, | parameter | :: | dbcsr_failure_level | = | 2 |
level of a warning |
integer, | public, | parameter | :: | dbcsr_warning_level | = | 1 |
level of a note |
integer, | public, | parameter | :: | dbcsr_note_level | = | 0 |
a generic function to trasform different types to strings |
integer, | private | :: | stack_pointer | = | 0 | ||
integer, | private, | parameter | :: | max_stack_pointer | = | 10 | |
type(default_logger_stack_type), | private, | SAVE, DIMENSION(max_stack_pointer) | :: | default_logger_stack | |||
integer, | private, | SAVE | :: | last_logger_id_nr | = | 0 |
converts an int to a string (should be a variable length string, but that does not work with all the compilers)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | i |
the integer to convert |
convert a double precision real in a string (should be a variable length string, but that does not work with all the compilers)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=dp), | intent(in) | :: | val |
the number to convert |
convert a logical in a string ('T' or 'F')
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
logical, | intent(in) | :: | val |
the number to convert |
type of a logger, at the moment it contains just a print level starting at which level it should be logged (0 note, 1 warning, 2 failure, 3 fatal) it could be expanded with the ability to focus on one or more module/object/thread/processor
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer, | public | :: | id_nr | = | -1 |
unique number to identify the logger reference count (see cp2k/doc/ReferenceCounting.html) |
|
integer, | public | :: | ref_count | = | -1 |
unique number to identify the logger reference count (see cp2k/doc/ReferenceCounting.html) |
|
integer, | public | :: | print_level | = | -1 |
the level starting at which something gets printed |
|
integer, | public | :: | default_local_unit_nr | = | -1 |
default unit for local logging (-1 if not yet initialized). Local logging guarantee to each task its own file. |
|
integer, | public | :: | default_global_unit_nr | = | -1 |
default unit for global logging (-1 if not yet initialized). This unit is valid only on the processor with %mp_env%mp%mynode==%mv_env%mp%source. |
|
logical, | public | :: | close_local_unit_on_dealloc | = | .FALSE. |
if the local unit should be closed when this logger is deallocated whether the global unit should be closed when this logger is deallocated |
|
logical, | public | :: | close_global_unit_on_dealloc | = | .FALSE. |
if the local unit should be closed when this logger is deallocated whether the global unit should be closed when this logger is deallocated |
|
character(len=default_string_length), | public | :: | suffix | = | "" |
a short string that is used as suffix in all the filenames created by this logger. Can be used to guarantee the uniqueness of generated filename |
|
character(len=default_path_length), | public | :: | local_filename | = | "" |
the root of the name of the file used for local logging (can be different from the name of the file corresponding to default_local_unit_nr, only the one used if the unit needs to be opened) the root of the name of the file used for global logging (can be different from the name of the file corresponding to default_global_unit_nr, only the one used if the unit needs to be opened) |
|
character(len=default_path_length), | public | :: | global_filename | = | "" |
the root of the name of the file used for local logging (can be different from the name of the file corresponding to default_local_unit_nr, only the one used if the unit needs to be opened) the root of the name of the file used for global logging (can be different from the name of the file corresponding to default_global_unit_nr, only the one used if the unit needs to be opened) |
|
type(dbcsr_mp_obj), | public | :: | mp_env | = | dbcsr_mp_obj() |
the parallel environment for the output. |
|
type(dbcsr_iteration_info_type), | public, | POINTER | :: | iter_info | => | NULL() |
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
type(dbcsr_logger_type), | public, | POINTER | :: | p | => | Null() |
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
type(dbcsr_logger_type), | public, | POINTER | :: | dbcsr_default_logger | => | Null() |
this function can be called to check if the logger would log a message with the given level from the given source you should use this function if you do direct logging (without using dbcsr_logger_log), or if you want to know if the generation of some costly log info is necessary
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(dbcsr_logger_type), | POINTER | :: | logger |
the logger you want to log in |
||
integer, | intent(in) | :: | level |
describes the of the message: dbcsr_fatal_level(3), dbcsr_failure_level(2), dbcsr_warning_level(1), dbcsr_note_level(0). |
returns the unit nr for the requested kind of log.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(dbcsr_logger_type), | POINTER | :: | logger |
the logger you want to log in |
||
logical, | intent(in), | optional | :: | local |
if true returns a local logger (one per task), otherwise returns a global logger (only the process with mp_env%mp%mynode== mp_env%mp%source should write to the global logger). Defaults to false |
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs calling this function is not the ionode
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(dbcsr_logger_type), | optional, | POINTER | :: | logger |
the logger you want to log in |
asks the default unit number of the given logger. try to use dbcsr_logger_get_unit_nr
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(dbcsr_logger_type), | optional, | POINTER | :: | logger |
the logger you want info from |
|
logical, | intent(in), | optional | :: | local |
if you want the local unit nr (defaults to false) |
|
logical, | intent(in), | optional | :: | skip_not_ionode |
if you want the local unit nr (defaults to false) |
converts an int to a string (should be a variable length string, but that does not work with all the compilers)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | i |
the integer to convert |
convert a double precision real in a string (should be a variable length string, but that does not work with all the compilers)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=dp), | intent(in) | :: | val |
the number to convert |
convert a logical in a string ('T' or 'F')
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
logical, | intent(in) | :: | val |
the number to convert |
adds a default logger. MUST be called before logging occurs
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(dbcsr_logger_type), | POINTER | :: | logger |
the cousin of dbcsr_add_default_logger, decrements the stack, so that the default logger is what it has been
initializes a logger
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(dbcsr_logger_type), | POINTER | :: | logger |
the logger to initialize |
||
type(dbcsr_mp_obj), | optional | :: | mp_env |
the parallel environment (this is most likely the global parallel environment |
||
integer, | intent(in), | optional | :: | print_level |
the level starting with which something is written (defaults to dbcsr_note_level) the default unit_nr for output (if not given, and no file is given defaults to the standard output) the default unit number for local (i.e. task) output. If not given defaults to a out.taskid file created upon |
|
integer, | intent(in), | optional | :: | default_global_unit_nr |
the level starting with which something is written (defaults to dbcsr_note_level) the default unit_nr for output (if not given, and no file is given defaults to the standard output) the default unit number for local (i.e. task) output. If not given defaults to a out.taskid file created upon |
|
integer, | intent(in), | optional | :: | default_local_unit_nr |
the level starting with which something is written (defaults to dbcsr_note_level) the default unit_nr for output (if not given, and no file is given defaults to the standard output) the default unit number for local (i.e. task) output. If not given defaults to a out.taskid file created upon |
|
character(len=*), | intent(in), | optional | :: | global_filename |
a new file to open (can be given instead of the global_unit_nr) a new file to open (with suffix and mp_env%mp%mynode appended). Can be given instead of the default_local_unit_nr). the file is created only upon the first local logging request |
|
character(len=*), | intent(in), | optional | :: | local_filename |
a new file to open (can be given instead of the global_unit_nr) a new file to open (with suffix and mp_env%mp%mynode appended). Can be given instead of the default_local_unit_nr). the file is created only upon the first local logging request |
|
logical, | intent(in), | optional | :: | close_global_unit_on_dealloc |
if the unit should be closed when the logger is deallocated (defaults to true if a local_filename is given, to false otherwise) |
|
type(dbcsr_iteration_info_type), | optional, | POINTER | :: | iter_info | ||
logical, | intent(in), | optional | :: | close_local_unit_on_dealloc |
if the unit should be closed when the logger is deallocated (defaults to true) |
|
character(len=*), | intent(in), | optional | :: | suffix |
the suffix that should be added to all the generated filenames |
|
type(dbcsr_logger_type), | optional, | POINTER | :: | template_logger |
a logger from where to take the unspecified things |
retains the given logger (to be called to keep a shared copy of the logger)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(dbcsr_logger_type), | POINTER | :: | logger |
the logger to retain |
releases this logger
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(dbcsr_logger_type), | POINTER | :: | logger |
the logger to release |
changes the logging level. Log messages with a level less than the one given wo not be printed.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(dbcsr_logger_type), | POINTER | :: | logger |
the logger to change |
||
integer, | intent(in) | :: | level |
the new logging level for the logger |
generates a unique filename (ie adding eventual suffixes and process ids)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(dbcsr_logger_type), | POINTER | :: | logger | |||
character(len=*), | intent(inout) | :: | res |
the resulting string |
||
character(len=*), | intent(in) | :: | root |
the start of filename the end of the name |
||
character(len=*), | intent(in) | :: | postfix |
the start of filename the end of the name |
||
logical, | intent(in), | optional | :: | local |
if the name should be local to this task (defaults to false) |
sets various attributes of the given logger
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(dbcsr_logger_type), | POINTER | :: | logger |
the logger you want to change |
||
character(len=*), | intent(in), | optional | :: | local_filename |
the root of the name of the file used for local logging the root of the name of the file used for global logging |
|
character(len=*), | intent(in), | optional | :: | global_filename |
the root of the name of the file used for local logging the root of the name of the file used for global logging |