1 | MODULE logging |
---|
2 | |
---|
3 | ! see also use_logging.h |
---|
4 | ! macro LOGBUF accumulates log output into logging_buffer |
---|
5 | |
---|
6 | IMPLICIT NONE |
---|
7 | SAVE |
---|
8 | PRIVATE |
---|
9 | |
---|
10 | INTERFACE ! Explicit interfaces for plugins |
---|
11 | |
---|
12 | ! Plugin that typically prints all lines in the loggin buffer 'buf' and prepends tags (log level, timestamp, ...) |
---|
13 | SUBROUTINE plugin(lev, tag, buf) |
---|
14 | INTEGER, INTENT(IN) :: lev |
---|
15 | CHARACTER(*), INTENT(IN) :: tag, buf(:) |
---|
16 | END SUBROUTINE plugin |
---|
17 | |
---|
18 | ! Plugin that writes into string 'line' information about the gridpoint of index 'index' |
---|
19 | SUBROUTINE plugin_log_gridpoint(index, line) |
---|
20 | INTEGER, INTENT(IN) :: index ! index of gridpoint |
---|
21 | CHARACTER(*), INTENT(OUT) :: line |
---|
22 | END SUBROUTINE plugin_log_gridpoint |
---|
23 | |
---|
24 | END INTERFACE |
---|
25 | |
---|
26 | ! This module provides a default implementation of flush_plugin but the top-level driver is welcome to override it. |
---|
27 | PROCEDURE(plugin), POINTER :: flush_plugin => default_flush |
---|
28 | |
---|
29 | ! The top-level driver MUST provide an implementation for log_gridpoint_plugin |
---|
30 | PROCEDURE(plugin_log_gridpoint), POINTER :: log_gridpoint_plugin => NULL() |
---|
31 | |
---|
32 | INTEGER, PARAMETER :: bufsize=10000 |
---|
33 | CHARACTER(bufsize) :: logging_buf(100) |
---|
34 | |
---|
35 | INTEGER :: logging_lineno=0 |
---|
36 | |
---|
37 | INTEGER, PARAMETER, PUBLIC :: log_level_fatal=0, log_level_error=1, log_level_warn=2, log_level_info=3, log_level_dbg=4 |
---|
38 | |
---|
39 | PUBLIC :: logging_buf, logging_lineno, flush_log, log_gridpoint, & |
---|
40 | flush_plugin, log_gridpoint_plugin |
---|
41 | |
---|
42 | CONTAINS |
---|
43 | |
---|
44 | SUBROUTINE flush_log(lev,tag) |
---|
45 | INTEGER, INTENT(IN) :: lev |
---|
46 | CHARACTER(*), INTENT(IN) :: tag |
---|
47 | CALL flush_plugin(lev, TRIM(tag), logging_buf(1:logging_lineno)) |
---|
48 | logging_lineno=0 |
---|
49 | END SUBROUTINE flush_log |
---|
50 | |
---|
51 | SUBROUTINE default_flush(lev, tag, buf) |
---|
52 | INTEGER, INTENT(IN) :: lev |
---|
53 | CHARACTER(*), INTENT(IN) :: tag, buf(:) |
---|
54 | INTEGER :: i |
---|
55 | DO i=1, SIZE(buf) |
---|
56 | PRINT *, '[INFO ',tag,']', TRIM(buf(i)) |
---|
57 | END DO |
---|
58 | END SUBROUTINE default_flush |
---|
59 | |
---|
60 | SUBROUTINE log_gridpoint(index) |
---|
61 | INTEGER, INTENT(IN) :: index |
---|
62 | logging_lineno = logging_lineno+1 |
---|
63 | CALL log_gridpoint_plugin(index, logging_buf(logging_lineno)) |
---|
64 | END SUBROUTINE log_gridpoint |
---|
65 | |
---|
66 | END MODULE logging |
---|