此模块定义了一个派生类型、过程、变量和常量,用于在 Fortran 应用程序中记录信息和报告错误。(规范)
派生类型 logger_type
用于定义变量,作为本地和全局日志记录器。日志记录器将其消息定向到选定的 I/O 单元,以便用户拥有主要事件的记录(日志)。对于 logger_type
的每个实体,报告都发送到由私有内部数组 log_units
表示的 I/O 单元列表。如果 log_units
为空,则默认输出发送到 output_unit
。否则,仅当 output_unit
已明确添加到 log_units
中时,报告才会发送到 output_unit
。logger_type
类型的每个实体还维护一个内部状态,用于控制输出的格式。
过程如下。逻辑函数 log_units_assigned
返回 log_units
中 I/O 单元的数量。子程序 add_log_file
和 add_log_unit
将指定的文件包含在 log_units
中。remove_log_units
从 log_units
数组中删除指定的逻辑单元,并可以选择关闭文件。configure
配置日志记录过程的详细信息。configuration
报告该配置的详细信息。子程序 log_error
、log_information
、log_io_error
、log_message
、log_text_error
和 log_warning
将消息发送到日志单元。
类型为 logger_type
的变量 global_logger
可用作源代码中任何位置的默认全局日志记录器。
这些常量用于通过某些子程序在其可选的 stat
参数中报告错误。常量如下。success
表示未发生错误。close_failure
表示 I/O 单元的 close
语句失败。index_invalid_error
表示给定 line
的 column
无效。open_failure
表示 open
语句失败。read_only_error
表示输出单元没有 "write"
或 "readwrite"
操作。non_sequential_error
表示该单元没有 sequential
访问权限。unformatted_in_error
表示该单元没有 form
为 "formatted"
。unopened_in_error
表示该单元未打开。write_failure
表示写入 log_units
的至少一个写入操作失败。
用作错误标志的公共常量 类型为 logger_type
的变量,用作全局日志记录器
类型 | 可见性 | 属性 | 名称 | 初始值 | |||
---|---|---|---|---|---|---|---|
integer, | public, | parameter | :: | all_level | = | -10+min(debug_level, information_level, warning_level, error_level, io_error_level, text_error_level) | |
integer, | public, | parameter | :: | close_failure | = | 1 | |
integer, | public, | parameter | :: | debug_level | = | 10 | |
integer, | public, | parameter | :: | error_level | = | 40 | |
type(logger_type), | public | :: | global_logger | ||||
integer, | public, | parameter | :: | index_invalid_error | = | 2 | |
integer, | public, | parameter | :: | information_level | = | 20 | |
integer, | public, | parameter | :: | io_error_level | = | 40 | |
integer, | public, | parameter | :: | non_sequential_error | = | 3 | |
integer, | public, | parameter | :: | none_level | = | 10+max(debug_level, information_level, warning_level, error_level, io_error_level, text_error_level) | |
integer, | public, | parameter | :: | open_failure | = | 4 | |
integer, | public, | parameter | :: | read_only_error | = | 5 | |
integer, | public, | parameter | :: | success | = | 0 | |
integer, | public, | parameter | :: | text_error_level | = | 50 | |
integer, | public, | parameter | :: | unformatted_in_error | = | 6 | |
integer, | public, | parameter | :: | unopened_in_error | = | 7 | |
integer, | public, | parameter | :: | warning_level | = | 30 | |
integer, | public, | parameter | :: | write_failure | = | 8 |
公共派生类型 (规范)
final :: final_logger |
procedure, public, pass(self) :: add_log_file | |
procedure, public, pass(self) :: add_log_unit | |
procedure, public, pass(self) :: configuration | |
procedure, public, pass(self) :: configure | |
procedure, public, pass(self) :: log_debug | |
procedure, public, pass(self) :: log_error | |
procedure, public, pass(self) :: log_information | |
procedure, public, pass(self) :: log_io_error | |
procedure, public, pass(self) :: log_message | |
procedure, public, pass(self) :: log_text_error | |
procedure, public, pass(self) :: log_units_assigned | |
procedure, public, pass(self) :: log_warning | |
procedure, public, pass(self) :: remove_log_unit |