From ae17d55c28122a9362df7b5219c2e7c63272678d Mon Sep 17 00:00:00 2001 From: Philipp Date: Fri, 1 Mar 2024 16:16:48 +0100 Subject: [PATCH] Refactoring of logging sub-system. --- Makefile | 184 ++++++++++++++++++------------------ app/dmbeat.f90 | 38 ++++---- app/dmdb.f90 | 30 +++--- app/dmfeed.f90 | 42 ++++---- app/dmfs.f90 | 55 ++++++----- app/dmlog.f90 | 6 +- app/dmlogger.f90 | 32 +++---- app/dmlua.f90 | 44 ++++----- app/dmpipe.f90 | 51 +++++----- app/dmrecv.f90 | 34 +++---- app/dmreport.f90 | 4 +- app/dmsend.f90 | 42 ++++---- app/dmserial.f90 | 86 ++++++++--------- app/dmsync.f90 | 64 ++++++------- config/dmfeed.conf.sample | 16 ++-- config/dmlogger.conf.sample | 14 +-- config/dmreport.conf.sample | 16 ++-- guide/guide.adoc | 106 ++++++++++----------- src/dm_atom.f90 | 2 +- src/dm_html.f90 | 4 +- src/dm_log.f90 | 33 ++++--- src/dm_logger.f90 | 106 +++++++++++++++++++-- src/dm_lua_api.f90 | 24 ++--- src/dm_mqueue_util.f90 | 29 +++--- src/dm_report.f90 | 10 +- src/dm_test.f90 | 2 +- test/dmtestlogger.f90 | 51 +++++++--- 27 files changed, 619 insertions(+), 506 deletions(-) diff --git a/Makefile b/Makefile index fb5ab3f..e8fc79c 100644 --- a/Makefile +++ b/Makefile @@ -66,7 +66,7 @@ # FORD - FORD documentation generator. # # FFLAGS - Fortran compiler options. -# CLAGS - C compiler options. +# CFLAGS - C compiler options. # PPFLAGS - Pre-processor options (must be empty for Intel oneAPI). # ARFLAGS - Archiver options. # LDFLAGS - Linker options. @@ -145,8 +145,8 @@ DEBUG = -g -O0 -Wall -fcheck=all -fmax-errors=1 RELEASE = -mtune=native -O2 # Common build options. -FFLAGS = $(RELEASE) -ffree-line-length-0 -std=f2018 -CFLAGS = $(RELEASE) +FFLAGS = $(RELEASE) -fPIC -ffree-line-length-0 -std=f2018 +CFLAGS = $(RELEASE) -fPIC PPFLAGS = -cpp -D__$(OS)__ ARFLAGS = -rcs LDFLAGS = -I$(INCDIR) -J$(INCDIR) -L$(PREFIX)/lib -z execstack -z now @@ -322,30 +322,30 @@ linux: # ****************************************************************************** $(LIBFCURL): setup - cd vendor/fortran-curl/ && make CFLAGS="-fPIC $(CFLAGS)" FFLAGS="-fPIC $(FFLAGS)" PREFIX="$(PREFIX)" TARGET="../../$(LIBFCURL)" + cd vendor/fortran-curl/ && make CC=$(CC) FC=$(FC) CFLAGS="$(CFLAGS)" FFLAGS="$(FFLAGS)" PREFIX="$(PREFIX)" TARGET="../../$(LIBFCURL)" cp ./vendor/fortran-curl/*.mod $(INCDIR)/ $(LIBFLUA54): setup - cd vendor/fortran-lua54/ && make CFLAGS="-fPIC $(CFLAGS)" FFLAGS="-fPIC $(FFLAGS)" PREFIX="$(PREFIX)" TARGET="../../$(LIBFLUA54)" + cd vendor/fortran-lua54/ && make CC=$(CC) FC=$(FC) CFLAGS="$(CFLAGS)" FFLAGS="$(FFLAGS)" PREFIX="$(PREFIX)" TARGET="../../$(LIBFLUA54)" cp ./vendor/fortran-lua54/*.mod $(INCDIR)/ $(LIBFPCRE2): setup - cd vendor/fortran-pcre2/ && make CFLAGS="-fPIC $(CFLAGS)" FFLAGS="-fPIC $(FFLAGS)" PREFIX="$(PREFIX)" TARGET="../../$(LIBFPCRE2)" + cd vendor/fortran-pcre2/ && make CC=$(CC) FC=$(FC) CFLAGS="$(CFLAGS)" FFLAGS="$(FFLAGS)" PREFIX="$(PREFIX)" TARGET="../../$(LIBFPCRE2)" cp ./vendor/fortran-pcre2/*.mod $(INCDIR)/ $(LIBFSQLITE3): setup - cd vendor/fortran-sqlite3/ && make CFLAGS="-fPIC $(CFLAGS)" FFLAGS="-fPIC $(FFLAGS)" PREFIX="$(PREFIX)" TARGET="../../$(LIBFSQLITE3)" + cd vendor/fortran-sqlite3/ && make CC=$(CC) FC=$(FC) CFLAGS="$(CFLAGS)" FFLAGS="$(FFLAGS)" PREFIX="$(PREFIX)" TARGET="../../$(LIBFSQLITE3)" cp ./vendor/fortran-sqlite3/*.mod $(INCDIR)/ $(LIBFUNIX): setup @echo "---" @echo "--- Building for $(OS) ..." @echo "---" - cd vendor/fortran-unix/ && make CFLAGS="-fPIC $(CFLAGS)" FFLAGS="-fPIC $(FFLAGS)" PREFIX="$(PREFIX)" PPFLAGS="$(PPFLAGS)" TARGET="../../$(LIBFUNIX)" + cd vendor/fortran-unix/ && make CC=$(CC) FC=$(FC) CFLAGS="$(CFLAGS)" FFLAGS="$(FFLAGS)" PREFIX="$(PREFIX)" PPFLAGS="$(PPFLAGS)" TARGET="../../$(LIBFUNIX)" cp ./vendor/fortran-unix/*.mod $(INCDIR)/ $(LIBFZ): setup - cd vendor/fortran-zlib/ && make CFLAGS="-fPIC $(CFLAGS)" FFLAGS="-fPIC $(FFLAGS)" PREFIX="$(PREFIX)" TARGET="../../$(LIBFZ)" + cd vendor/fortran-zlib/ && make CC=$(CC) FC=$(FC) CFLAGS="$(CFLAGS)" FFLAGS="$(FFLAGS)" PREFIX="$(PREFIX)" TARGET="../../$(LIBFZ)" cp ./vendor/fortran-zlib/*.mod $(INCDIR)/ # ****************************************************************************** @@ -355,88 +355,88 @@ $(LIBFZ): setup # ****************************************************************************** $(OBJ): $(SRC) - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_version.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_kind.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_platform.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_ascii.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_const.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_error.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_string.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_type.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_format.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_ansi.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_env.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_util.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_time.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_timer.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_base64.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_path.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_file.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_hash.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_hash_table.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_unit.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_id.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_uuid.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_arg.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_signal.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_system.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_pipe.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_tty.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_sem.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_mutex.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_dp.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_fifo.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_node.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_sensor.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_target.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_response.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_request.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_observ.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_log.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_job.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_plot.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_report.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_regex.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_sync.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_beat.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_mqueue.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_logger.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_test.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_nml.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) $(INCHDF5) -c src/dm_hdf5.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_sql.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_db.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_z.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_person.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_mail.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_http.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_mime.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_api.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_rpc.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_mqtt.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_cgi.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_fcgi.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_block.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_csv.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_json.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_jsonl.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_html.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_atom.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_cgi_router.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_la.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_transform.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_geocom_error.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_geocom_type.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_geocom_api.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_geocom.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_lua.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_lua_api.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_lua_geocom.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_lua_lib.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_config.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_rts.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dm_mqueue_util.f90 - $(FC) -fPIC $(FFLAGS) $(LDFLAGS) -c src/dmpack.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_version.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_kind.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_platform.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_ascii.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_const.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_error.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_string.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_type.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_format.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_ansi.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_env.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_util.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_time.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_timer.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_base64.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_path.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_file.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_hash.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_hash_table.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_unit.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_id.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_uuid.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_arg.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_signal.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_system.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_pipe.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_tty.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_sem.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_mutex.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_dp.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_fifo.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_node.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_sensor.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_target.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_response.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_request.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_observ.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_log.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_job.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_plot.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_report.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_regex.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_sync.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_beat.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_mqueue.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_logger.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_test.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_nml.f90 + $(FC) $(FFLAGS) $(LDFLAGS) $(INCHDF5) -c src/dm_hdf5.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_sql.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_db.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_z.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_person.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_mail.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_http.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_mime.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_api.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_rpc.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_mqtt.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_cgi.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_fcgi.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_block.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_csv.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_json.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_jsonl.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_html.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_atom.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_cgi_router.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_la.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_transform.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_geocom_error.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_geocom_type.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_geocom_api.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_geocom.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_lua.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_lua_api.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_lua_geocom.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_lua_lib.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_config.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_rts.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_mqueue_util.f90 + $(FC) $(FFLAGS) $(LDFLAGS) -c src/dmpack.f90 # Static library `libdmpack.a`. $(TARGET): $(LIBF) $(OBJ) @@ -451,7 +451,7 @@ $(TARGET): $(LIBF) $(OBJ) # Shared library `libdmpack.so`. $(SHARED): $(TARGET) - $(FC) -fPIC -shared $(FFLAGS) $(LDFLAGS) -o $(SHARED) -Wl,--whole-archive $(TARGET) -Wl,--no-whole-archive $(LIBSHARED) $(LDLIBS) + $(FC) $(FFLAGS) $(LDFLAGS) -shared -o $(SHARED) -Wl,--whole-archive $(TARGET) -Wl,--no-whole-archive $(LIBSHARED) $(LDLIBS) # ****************************************************************************** # diff --git a/app/dmbeat.f90 b/app/dmbeat.f90 index bb2cfeb..3910372 100644 --- a/app/dmbeat.f90 +++ b/app/dmbeat.f90 @@ -4,7 +4,7 @@ ! Licence: ISC program dmbeat !! Heartbeat emitter, sends status messages to the RPC API. - use :: dmpack, dm_log => dm_logger_log + use :: dmpack implicit none (type, external) character(len=*), parameter :: APP_NAME = 'dmbeat' @@ -58,7 +58,7 @@ program dmbeat rc = dm_rpc_init() if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to initialize libcurl', error=rc) + call dm_log_error('failed to initialize libcurl', error=rc) call dm_stop(1) end if @@ -195,7 +195,7 @@ subroutine run(app) type(rpc_response_type) :: response type(timer_type) :: timer - call dm_log(LOG_INFO, 'started ' // app%name) + call dm_log_info('started ' // app%name) ! Client and library version. client = dm_version_to_string(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, library=.true.) @@ -211,7 +211,7 @@ subroutine run(app) emit_loop: do call dm_timer_start(timer) - call dm_log(LOG_DEBUG, 'emitting beat for node ' // trim(app%node) // ' to host ' // app%host) + call dm_log_debug('emitting beat for node ' // trim(app%node) // ' to host ' // app%host) ! Create new heartbeat. beat = beat_type(node_id = app%node, & @@ -234,7 +234,7 @@ subroutine run(app) url = url) if (dm_is_error(rc)) then - call dm_log(LOG_DEBUG, 'failed to send beat to host ' // app%host, error=rc) + call dm_log_debug('failed to send beat to host ' // app%host, error=rc) end if last_error = rc @@ -242,34 +242,34 @@ subroutine run(app) code_select: & select case (response%code) case (0) - call dm_log(LOG_WARNING, 'connection to host ' // trim(app%host) // ' failed: ' // & - response%error_message, error=rc) + call dm_log_warning('connection to host ' // trim(app%host) // ' failed: ' // & + response%error_message, error=rc) case (HTTP_CREATED) - call dm_log(LOG_DEBUG, 'beat accepted by host ' // app%host) + call dm_log_debug('beat accepted by host ' // app%host) case (HTTP_UNAUTHORIZED) - call dm_log(LOG_ERROR, 'unauthorized access on host ' // app%host, error=E_RPC_AUTH) + call dm_log_error('unauthorized access on host ' // app%host, error=E_RPC_AUTH) case (HTTP_INTERNAL_SERVER_ERROR) - call dm_log(LOG_ERROR, 'internal server error on host ' // app%host, error=E_RPC_SERVER) + call dm_log_error('internal server error on host ' // app%host, error=E_RPC_SERVER) case (HTTP_BAD_GATEWAY) - call dm_log(LOG_ERROR, 'bad gateway on host ' // app%host, error=E_RPC_CONNECT) + call dm_log_error('bad gateway on host ' // app%host, error=E_RPC_CONNECT) case default ! Log response from api message if available. if (response%content_type == MIME_TEXT) then if (dm_is_ok(dm_api_status_from_string(api, response%payload))) then - call dm_log(LOG_ERROR, 'server error on host ' // trim(app%host) // & - ' (HTTP ' // dm_itoa(response%code) // '): ' // & - api%message, error=api%error) + call dm_log_error('server error on host ' // trim(app%host) // & + ' (HTTP ' // dm_itoa(response%code) // '): ' // & + api%message, error=api%error) exit code_select end if end if - call dm_log(LOG_WARNING, 'API call to host ' // trim(app%host) // ' failed (HTTP ' // & - dm_itoa(response%code) // ')', error=E_RPC_API) + call dm_log_warning('API call to host ' // trim(app%host) // ' failed (HTTP ' // & + dm_itoa(response%code) // ')', error=E_RPC_API) end select code_select if (app%count > 0) then @@ -278,11 +278,11 @@ subroutine run(app) end if t = max(0, int(app%interval - dm_timer_stop(timer))) - call dm_log(LOG_DEBUG, 'next beat in ' // dm_itoa(t) // ' sec') + call dm_log_debug('next beat in ' // dm_itoa(t) // ' sec') call dm_sleep(t) end do emit_loop - call dm_log(LOG_DEBUG, 'finished transmission') + call dm_log_debug('finished transmission') end subroutine run subroutine signal_handler(signum) bind(c) @@ -293,7 +293,7 @@ subroutine signal_handler(signum) bind(c) select case (signum) case default - call dm_log(LOG_INFO, 'exit on signal ' // dm_itoa(signum)) + call dm_log_info('exit on signal ' // dm_itoa(signum)) call dm_rpc_destroy() call dm_stop(0) end select diff --git a/app/dmdb.f90 b/app/dmdb.f90 index f51c014..c38ef6b 100644 --- a/app/dmdb.f90 +++ b/app/dmdb.f90 @@ -5,7 +5,7 @@ program dmdb !! The database program collects observations from a POSIX message queue and !! stores them in a SQLite database. - use :: dmpack, dm_log => dm_logger_log + use :: dmpack implicit none (type, external) character(len=*), parameter :: APP_NAME = 'dmdb' @@ -56,7 +56,7 @@ program dmdb rc = dm_db_open(db, path=app%database, timeout=APP_DB_TIMEOUT) if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to open database ' // app%database, error=rc) + call dm_log_error('failed to open database ' // app%database, error=rc) exit init_block end if @@ -67,8 +67,8 @@ program dmdb access = MQUEUE_RDONLY) if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to open mqueue /' // trim(app%name) // ': ' // & - dm_system_error_message(), error=rc) + call dm_log_error('failed to open mqueue /' // trim(app%name) // ': ' // & + dm_system_error_message(), error=rc) exit init_block end if @@ -77,7 +77,7 @@ program dmdb rc = dm_sem_open(sem, name=app%name, value=0, create=.true.) if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to open semaphore /' // app%name, error=rc) + call dm_log_error('failed to open semaphore /' // app%name, error=rc) exit init_block end if end if @@ -212,25 +212,25 @@ subroutine run(app, db, mqueue, sem) type(observ_type) :: observ steps = 0 - call dm_log(LOG_INFO, 'started ' // app%name) + call dm_log_info('started ' // app%name) ipc_loop: do ! Blocking read from POSIX message queue. rc = dm_mqueue_read(mqueue, observ) if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to read from mqueue /' // app%name, error=rc) + call dm_log_error('failed to read from mqueue /' // app%name, error=rc) call dm_sleep(1) cycle ipc_loop end if if (.not. dm_observ_valid(observ)) then - call dm_log(LOG_ERROR, 'invalid observ ' // trim(observ%name), error=E_INVALID) + call dm_log_error('invalid observ ' // trim(observ%name), error=E_INVALID) cycle ipc_loop end if if (dm_db_exists_observ(db, observ%id)) then - call dm_log(LOG_WARNING, 'observ ' // trim(observ%id) // ' exists', error=E_EXIST) + call dm_log_warning('observ ' // trim(observ%id) // ' exists', error=E_EXIST) cycle ipc_loop end if @@ -240,7 +240,7 @@ subroutine run(app, db, mqueue, sem) ! Retry if database is busy. if (rc == E_DB_BUSY) then - call dm_log(LOG_DEBUG, 'database busy', error=rc) + call dm_log_debug('database busy', error=rc) call dm_db_sleep(APP_DB_TIMEOUT) cycle db_loop end if @@ -248,11 +248,11 @@ subroutine run(app, db, mqueue, sem) ! Get more precise database error. if (dm_is_error(rc)) then rc = dm_db_error(db) - call dm_log(LOG_ERROR, 'failed to insert observ ' // observ%name, error=rc) + call dm_log_error('failed to insert observ ' // observ%name, error=rc) exit db_loop end if - call dm_log(LOG_DEBUG, 'inserted observ ' // observ%name) + call dm_log_debug('inserted observ ' // observ%name) ! Post semaphore. if (app%ipc) then @@ -268,11 +268,11 @@ subroutine run(app, db, mqueue, sem) if (steps == 0) then ! Optimise database. - call dm_log(LOG_DEBUG, 'optimizing database') + call dm_log_debug('optimizing database') rc = dm_db_optimize(db) if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to optimize database', error=rc) + call dm_log_error('failed to optimize database', error=rc) end if end if @@ -289,7 +289,7 @@ subroutine signal_handler(signum) bind(c) select case (signum) case default - call dm_log(LOG_INFO, 'exit on signal ' // dm_itoa(signum)) + call dm_log_info('exit on signal ' // dm_itoa(signum)) call halt(E_NONE) end select end subroutine signal_handler diff --git a/app/dmfeed.f90 b/app/dmfeed.f90 index c58d2d1..96d8f48 100644 --- a/app/dmfeed.f90 +++ b/app/dmfeed.f90 @@ -17,16 +17,16 @@ program dmfeed type :: app_type !! Application settings. - character(len=ID_LEN) :: name = APP_NAME !! Name of instance/configuration. - character(len=FILE_PATH_LEN) :: config = ' ' !! Path to config file. - character(len=FILE_PATH_LEN) :: database = ' ' !! Path to log database. - character(len=FILE_PATH_LEN) :: output = ' ' !! Output path of Atom file (stdout if empty). - character(len=NODE_ID_LEN) :: node = ' ' !! Optional node id. - integer :: minlevel = LOG_DEBUG !! Minimum log level - integer :: maxlevel = LOG_CRITICAL !! Maximum log level. - integer :: nentries = 50 !! Max. number of entries in feed. - logical :: force = .false. !! Force writing of output file. - type(atom_type) :: atom !! Atom type. + character(len=ID_LEN) :: name = APP_NAME !! Name of instance/configuration. + character(len=FILE_PATH_LEN) :: config = ' ' !! Path to config file. + character(len=FILE_PATH_LEN) :: database = ' ' !! Path to log database. + character(len=FILE_PATH_LEN) :: output = ' ' !! Output path of Atom file (stdout if empty). + character(len=NODE_ID_LEN) :: node = ' ' !! Optional node id. + integer :: min_level = LVL_DEBUG !! Minimum log level + integer :: max_level = LVL_CRITICAL !! Maximum log level. + integer :: nentries = 50 !! Max. number of entries in feed. + logical :: force = .false. !! Force writing of output file. + type(atom_type) :: atom !! Atom type. end type app_type integer :: rc ! Return code. @@ -111,8 +111,8 @@ integer function read_args(app) result(rc) rc = dm_arg_get(args( 3), app%database) rc = dm_arg_get(args( 4), app%output) rc = dm_arg_get(args( 5), app%node) - rc = dm_arg_get(args( 6), app%minlevel) - rc = dm_arg_get(args( 7), app%maxlevel) + rc = dm_arg_get(args( 6), app%min_level) + rc = dm_arg_get(args( 7), app%max_level) rc = dm_arg_get(args( 8), app%nentries) rc = dm_arg_get(args( 9), app%force) rc = dm_arg_get(args(10), app%atom%author) @@ -141,17 +141,17 @@ integer function read_args(app) result(rc) return end if - if (app%minlevel < LOG_DEBUG .or. app%minlevel > LOG_CRITICAL) then + if (.not. dm_log_valid(app%min_level)) then call dm_error_out(rc, 'invalid minimum log level') return end if - if (app%maxlevel < LOG_DEBUG .or. app%maxlevel > LOG_CRITICAL) then + if (.not. dm_log_valid(app%max_level)) then call dm_error_out(rc, 'invalid maximum log level') return end if - if (app%maxlevel < app%minlevel) then + if (app%max_level < app%min_level) then call dm_error_out(rc, 'maximum level must be greater than minimum level') return end if @@ -178,8 +178,8 @@ integer function read_config(app) result(rc) rc = dm_config_get(config, 'database', app%database) rc = dm_config_get(config, 'output', app%output) rc = dm_config_get(config, 'node', app%node) - rc = dm_config_get(config, 'minlevel', app%minlevel) - rc = dm_config_get(config, 'maxlevel', app%maxlevel) + rc = dm_config_get(config, 'minlevel', app%min_level) + rc = dm_config_get(config, 'maxlevel', app%max_level) rc = dm_config_get(config, 'nentries', app%nentries) rc = dm_config_get(config, 'force', app%force) rc = dm_config_get(config, 'author', app%atom%author) @@ -222,15 +222,15 @@ subroutine create_feed(app, error) rc = dm_db_select(db = db, & logs = logs, & node_id = app%node, & - min_level = app%minlevel, & - max_level = app%maxlevel, & + min_level = app%min_level, & + max_level = app%max_level, & desc = .true., & limit = int(app%nentries, kind=i8)) else rc = dm_db_select(db = db, & logs = logs, & - min_level = app%minlevel, & - max_level = app%maxlevel, & + min_level = app%min_level, & + max_level = app%max_level, & desc = .true., & limit = int(app%nentries, kind=i8)) end if diff --git a/app/dmfs.f90 b/app/dmfs.f90 index d927e2a..22e02c1 100644 --- a/app/dmfs.f90 +++ b/app/dmfs.f90 @@ -4,7 +4,7 @@ ! Licence: ISC program dmfs !! Reads observations from file system (file, virtual file, or named pipe). - use :: dmpack, dm_log => dm_logger_log + use :: dmpack implicit none (type, external) character(len=*), parameter :: APP_NAME = 'dmfs' @@ -77,7 +77,7 @@ integer function output_observ(observ, type) result(rc) rc = write_observ(observ, unit=stdout, format=app%format) if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to output observ', error=rc) + call dm_log_error('failed to output observ', error=rc) return end if @@ -89,15 +89,14 @@ integer function output_observ(observ, type) result(rc) newunit=fu, position='append', status='unknown') if (stat /= 0) then - call dm_log(LOG_ERROR, 'failed to open file ' // app%output, error=rc) + call dm_log_error('failed to open file ' // app%output, error=rc) return end if rc = write_observ(observ, unit=fu, format=app%format) if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to write observ to file ' // & - app%output, error=rc) + call dm_log_error('failed to write observ to file ' // app%output, error=rc) end if close (fu) @@ -240,7 +239,7 @@ integer function read_observ(observ, node_id, sensor_id, source, debug) result(r observ%timestamp = dm_time_now() if (observ%nrequests == 0) then - if (debug_) call dm_log(LOG_DEBUG, 'no requests in observ ' // observ%name, observ=observ) + if (debug_) call dm_log_debug('no requests in observ ' // observ%name, observ=observ) return end if @@ -255,8 +254,8 @@ integer function read_observ(observ, node_id, sensor_id, source, debug) result(r ! Check if file path passed as observation request exists. if (.not. dm_file_exists(request%request)) then - call dm_log(LOG_ERROR, 'file ' // trim(request%request) // ' not found', & - observ=observ, error=request%error) + call dm_log_error('file ' // trim(request%request) // ' not found', & + observ=observ, error=request%error) cycle req_loop end if @@ -265,8 +264,8 @@ integer function read_observ(observ, node_id, sensor_id, source, debug) result(r if (stat == 0) request%error = E_NONE if (dm_is_error(request%error)) then - call dm_log(LOG_ERROR, 'failed to open ' // trim(request%request), & - observ=observ, error=request%error) + call dm_log_error('failed to open ' // trim(request%request), & + observ=observ, error=request%error) cycle req_loop end if @@ -281,7 +280,7 @@ integer function read_observ(observ, node_id, sensor_id, source, debug) result(r rc = dm_regex_request(request) if (dm_is_error(rc)) then - if (debug_) call dm_log(LOG_DEBUG, 'line does not match pattern', observ=observ, error=rc) + if (debug_) call dm_log_debug('line does not match pattern', observ=observ, error=rc) cycle read_loop end if @@ -289,8 +288,8 @@ integer function read_observ(observ, node_id, sensor_id, source, debug) result(r do j = 1, request%nresponses response => request%responses(j) if (dm_is_ok(response%error)) cycle - call dm_log(LOG_WARNING, 'failed to extract response ' // trim(response%name) // & - ' of request ' // dm_itoa(i), observ=observ, error=response%error) + call dm_log_warning('failed to extract response ' // trim(response%name) // & + ' of request ' // dm_itoa(i), observ=observ, error=response%error) end do ! Cycle on error or exit on success. @@ -307,14 +306,14 @@ integer function read_observ(observ, node_id, sensor_id, source, debug) result(r ! Create log message and repeat. if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to read from file ' // request%request, observ=observ, error=rc) + call dm_log_error('failed to read from file ' // request%request, observ=observ, error=rc) call dm_sleep(10) ! Wait grace period. cycle req_loop end if if (debug_) then - call dm_log(LOG_DEBUG, 'finished request ' // dm_itoa(i) // ' of ' // & - dm_itoa(observ%nrequests), observ=observ) + call dm_log_debug('finished request ' // dm_itoa(i) // ' of ' // & + dm_itoa(observ%nrequests), observ=observ) end if ! Wait the set delay time of the request. @@ -322,8 +321,8 @@ integer function read_observ(observ, node_id, sensor_id, source, debug) result(r if (delay <= 0) cycle req_loop if (debug_) then - call dm_log(LOG_DEBUG, 'next request of observ ' // trim(observ%name) // & - ' in ' // dm_itoa(delay / 1000) // ' sec', observ=observ) + call dm_log_debug('next request of observ ' // trim(observ%name) // & + ' in ' // dm_itoa(delay / 1000) // ' sec', observ=observ) end if call dm_usleep(delay * 1000) @@ -361,24 +360,24 @@ subroutine run(app) type(observ_type), pointer :: observ ! Observation of job. debug = (app%debug .or. app%verbose) - call dm_log(LOG_INFO, 'started ' // app%name) + call dm_log_info('started ' // app%name) ! Run until no jobs are left. job_loop: do njobs = dm_job_list_count(app%jobs) if (njobs == 0) then - call dm_log(LOG_DEBUG, 'no jobs left') + call dm_log_debug('no jobs left') exit job_loop end if - if (debug) call dm_log(LOG_DEBUG, dm_itoa(njobs) // ' job(s) left in job queue') + if (debug) call dm_log_debug(dm_itoa(njobs) // ' job(s) left in job queue') ! Get next job as deep copy. rc = dm_job_list_next(app%jobs, job) if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to fetch next job', error=rc) + call dm_log_error('failed to fetch next job', error=rc) cycle job_loop end if @@ -386,16 +385,16 @@ subroutine run(app) observ => job%observ if (debug) then - call dm_log(LOG_DEBUG, 'starting observ ' // trim(observ%name) // & - ' for sensor ' // app%sensor, observ=observ) + call dm_log_debug('starting observ ' // trim(observ%name) // & + ' for sensor ' // app%sensor, observ=observ) end if ! Read observation from file system. rc = read_observ(observ, app%node, app%sensor, app%name, debug=debug) if (debug) then - call dm_log(LOG_DEBUG, 'finished observ ' // trim(observ%name) // & - ' for sensor ' // app%sensor, observ=observ) + call dm_log_debug('finished observ ' // trim(observ%name) // & + ' for sensor ' // app%sensor, observ=observ) end if ! Forward observation via message queue. @@ -408,7 +407,7 @@ subroutine run(app) ! Wait delay time of the job if set (absolute). delay = max(0, job%delay) if (delay <= 0) cycle job_loop - if (debug) call dm_log(LOG_DEBUG, 'next job in ' // dm_itoa(delay / 1000) // ' sec', observ=observ) + if (debug) call dm_log_debug('next job in ' // dm_itoa(delay / 1000) // ' sec', observ=observ) call dm_usleep(delay * 1000) end do job_loop end subroutine run @@ -420,7 +419,7 @@ subroutine signal_handler(signum) bind(c) select case (signum) case default - call dm_log(LOG_INFO, 'exit on signal ' // dm_itoa(signum)) + call dm_log_info('exit on signal ' // dm_itoa(signum)) call dm_stop(0) end select end subroutine signal_handler diff --git a/app/dmlog.f90 b/app/dmlog.f90 index 6ad8dc7..db7be4d 100644 --- a/app/dmlog.f90 +++ b/app/dmlog.f90 @@ -4,7 +4,7 @@ ! Licence: ISC program dmlog !! Logging utility that sends log messages to a dmlogger instance. - use :: dmpack, dm_log => dm_logger_log + use :: dmpack implicit none (type, external) character(len=*), parameter :: APP_NAME = 'dmlog' @@ -36,7 +36,7 @@ program dmlog log%id = dm_uuid4() log%timestamp = dm_time_now() - call dm_log(log) + call dm_logger_log(log) contains integer function read_args(app, log) result(rc) !! Reads command-line arguments. @@ -66,7 +66,7 @@ integer function read_args(app, log) result(rc) rc = dm_arg_get(args( 1), app%logger) rc = dm_arg_get(args( 2), app%verbose) - rc = dm_arg_get(args( 3), log%level, LOG_INFO) + rc = dm_arg_get(args( 3), log%level, LVL_INFO) rc = dm_arg_get(args( 4), log%error) rc = dm_arg_get(args( 5), log%node_id) rc = dm_arg_get(args( 6), log%sensor_id) diff --git a/app/dmlogger.f90 b/app/dmlogger.f90 index 4e7ffae..df65293 100644 --- a/app/dmlogger.f90 +++ b/app/dmlogger.f90 @@ -5,7 +5,7 @@ program dmlogger !! The logger program collects log messages from a POSIX message queue and !! stores them in a SQLite database. - use :: dmpack, dm_log => dm_logger_log + use :: dmpack implicit none (type, external) character(len=*), parameter :: APP_NAME = 'dmlogger' @@ -22,7 +22,7 @@ program dmlogger character(len=FILE_PATH_LEN) :: config = ' ' !! Path to configuration file. character(len=FILE_PATH_LEN) :: database = ' ' !! Path to SQLite database file. character(len=NODE_ID_LEN) :: node = ' ' !! Node id. - integer :: minlevel = LOG_WARNING !! Minimum level for a log to be stored in the database. + integer :: minlevel = LVL_WARNING !! Minimum level for a log to be stored in the database. logical :: ipc = .false. !! Use POSIX semaphore for process synchronisation. logical :: verbose = .false. !! Print debug messages to stderr. end type app_type @@ -52,7 +52,7 @@ program dmlogger rc = dm_db_open(db, path=app%database, timeout=APP_DB_TIMEOUT) if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to open database ' // app%database, error=rc) + call dm_log_error('failed to open database ' // app%database, error=rc) exit init_block end if @@ -63,8 +63,8 @@ program dmlogger access = MQUEUE_RDONLY) if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to open mqueue /' // trim(app%name) // ': ' // & - dm_system_error_message(), error=rc) + call dm_log_error('failed to open mqueue /' // trim(app%name) // ': ' // & + dm_system_error_message(), error=rc) exit init_block end if @@ -73,7 +73,7 @@ program dmlogger rc = dm_sem_open(sem, app%name, value=0, create=.true.) if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to open semaphore /' // app%name, error=rc) + call dm_log_error('failed to open semaphore /' // app%name, error=rc) exit init_block end if end if @@ -202,15 +202,15 @@ subroutine run(app, db, mqueue, sem) type(log_type) :: log steps = 0 - call dm_log(LOG_INFO, 'started ' // app%name) - call dm_log(LOG_DEBUG, 'minimum log level is set to ' // LOG_LEVEL_NAMES(app%minlevel)) + call dm_log_info('started ' // app%name) + call dm_log_debug('minimum log level is set to ' // LOG_LEVEL_NAMES(app%minlevel)) ipc_loop: do ! Blocking read from POSIX message queue. rc = dm_mqueue_read(mqueue, log) if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to read from mqueue /' // app%name, error=rc) + call dm_log_error('failed to read from mqueue /' // app%name, error=rc) call dm_sleep(1) cycle ipc_loop end if @@ -226,7 +226,7 @@ subroutine run(app, db, mqueue, sem) ! Skip if log already exists. if (dm_db_exists_log(db, log%id)) then - call dm_log(LOG_WARNING, 'log ' // trim(log%id) // ' exists', error=E_EXIST) + call dm_log_warning('log ' // trim(log%id) // ' exists', error=E_EXIST) cycle ipc_loop end if @@ -239,13 +239,13 @@ subroutine run(app, db, mqueue, sem) rc = dm_db_error(db) if (rc == E_DB_BUSY) then - call dm_log(LOG_WARNING, 'database busy', error=rc) + call dm_log_warning('database busy', error=rc) call dm_db_sleep(APP_DB_TIMEOUT) cycle db_loop end if - call dm_log(LOG_ERROR, 'failed to insert log ' // trim(log%id) // ': ' // & - dm_db_error_message(db), error=rc) + call dm_log_error('failed to insert log ' // trim(log%id) // ': ' // & + dm_db_error_message(db), error=rc) exit db_loop end if @@ -260,9 +260,9 @@ subroutine run(app, db, mqueue, sem) if (steps == 0) then ! Optimise database. - call dm_log(LOG_DEBUG, 'optimizing database') + call dm_log_debug('optimizing database') rc = dm_db_optimize(db) - if (dm_is_error(rc)) call dm_log(LOG_ERROR, 'failed to optimize database', error=rc) + if (dm_is_error(rc)) call dm_log_error('failed to optimize database', error=rc) end if ! Increase optimise step counter. @@ -278,7 +278,7 @@ subroutine signal_handler(signum) bind(c) select case (signum) case default - call dm_log(LOG_INFO, 'exit on signal ' // dm_itoa(signum)) + call dm_log_info('exit on signal ' // dm_itoa(signum)) call dm_sleep(2) call halt(0) end select diff --git a/app/dmlua.f90 b/app/dmlua.f90 index ea2d665..8b61f63 100644 --- a/app/dmlua.f90 +++ b/app/dmlua.f90 @@ -6,7 +6,7 @@ program dmlua !! Lua script spawner that reads an observation from POSIX message queue, !! passes it to a configured Lua script, and forwards the returned !! observation to the next specified receiver. - use :: dmpack, dm_log => dm_logger_log + use :: dmpack implicit none (type, external) character(len=*), parameter :: APP_NAME = 'dmlua' @@ -54,7 +54,7 @@ program dmlua rc = dm_lua_init(lua) if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to init Lua interpreter', error=rc) + call dm_log_error('failed to init Lua interpreter', error=rc) exit init_block end if @@ -62,7 +62,7 @@ program dmlua rc = dm_lua_api_register(lua, add_errors=.true., add_levels=.true., add_procedures=.true.) if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to register Lua API', error=rc) + call dm_log_error('failed to register Lua API', error=rc) exit init_block end if @@ -70,7 +70,7 @@ program dmlua rc = dm_lua_open(lua, app%script, eval=.true.) if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to load Lua script', error=rc) + call dm_log_error('failed to load Lua script', error=rc) exit init_block end if @@ -81,8 +81,8 @@ program dmlua access = MQUEUE_RDONLY) if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to open mqueue /' // trim(app%name) // ': ' // & - dm_system_error_message(), error=rc) + call dm_log_error('failed to open mqueue /' // trim(app%name) // ': ' // & + dm_system_error_message(), error=rc) exit init_block end if @@ -220,27 +220,27 @@ subroutine run(app, lua, mqueue) integer :: rc type(observ_type) :: observ_in, observ_out - call dm_log(LOG_INFO, 'started ' // app%name) + call dm_log_info('started ' // app%name) ipc_loop: do ! Blocking read from POSIX message queue. rc = dm_mqueue_read(mqueue, observ_in) if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to read from mqueue /' // app%name, error=rc) + call dm_log_error('failed to read from mqueue /' // app%name, error=rc) call dm_sleep(1) cycle ipc_loop end if ! Validate observation. if (.not. dm_observ_valid(observ_in)) then - call dm_log(LOG_ERROR, 'invalid observ ' // trim(observ_in%name), & - observ=observ_in, error=E_INVALID) + call dm_log_error('invalid observ ' // trim(observ_in%name), & + observ=observ_in, error=E_INVALID) cycle ipc_loop end if - call dm_log(LOG_DEBUG, 'passing observ ' // trim(observ_in%name) // & - ' to Lua function ' // trim(app%proc) // '()', observ=observ_in) + call dm_log_debug('passing observ ' // trim(observ_in%name) // & + ' to Lua function ' // trim(app%proc) // '()', observ=observ_in) ! Pass the observation to the Lua function in read the returned ! observation. @@ -249,13 +249,13 @@ subroutine run(app, lua, mqueue) rc = dm_lua_read(lua, trim(app%proc)) if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to load Lua function ' // trim(app%proc) // '()', error=rc) + call dm_log_error('failed to load Lua function ' // trim(app%proc) // '()', error=rc) exit lua_block end if if (.not. dm_lua_is_function(lua)) then rc = E_INVALID - call dm_log(LOG_ERROR, 'invalid Lua function ' // trim(app%proc) // '()', error=rc) + call dm_log_error('invalid Lua function ' // trim(app%proc) // '()', error=rc) exit lua_block end if @@ -265,8 +265,8 @@ subroutine run(app, lua, mqueue) if (dm_is_error(rc)) then call dm_lua_pop(lua) - call dm_log(LOG_ERROR, 'failed to execute Lua function ' // trim(app%proc) // '()', & - observ=observ_in, error=rc) + call dm_log_error('failed to execute Lua function ' // trim(app%proc) // '()', & + observ=observ_in, error=rc) exit lua_block end if @@ -275,16 +275,16 @@ subroutine run(app, lua, mqueue) if (dm_is_error(rc)) then call dm_lua_pop(lua) - call dm_log(LOG_ERROR, 'failed to read observ from Lua stack', & - error=rc, observ=observ_in) + call dm_log_error('failed to read observ from Lua stack', & + error=rc, observ=observ_in) exit lua_block end if ! Validate returned observation. if (.not. dm_observ_valid(observ_out)) then rc = E_INVALID - call dm_log(LOG_ERROR, 'invalid observ returned from Lua function ' // & - trim(app%proc) // '()', error=rc, observ=observ_in) + call dm_log_error('invalid observ returned from Lua function ' // & + trim(app%proc) // '()', error=rc, observ=observ_in) exit lua_block end if end block lua_block @@ -293,7 +293,7 @@ subroutine run(app, lua, mqueue) if (dm_is_error(rc)) then observ_out = observ_in else - call dm_log(LOG_DEBUG, 'finished observ ' // observ_out%name, observ=observ_out) + call dm_log_debug('finished observ ' // observ_out%name, observ=observ_out) end if rc = dm_mqueue_forward(observ_out, app%name, APP_MQ_BLOCKING) @@ -307,7 +307,7 @@ subroutine signal_handler(signum) bind(c) select case (signum) case default - call dm_log(LOG_INFO, 'exit on signal ' // dm_itoa(signum)) + call dm_log_info('exit on signal ' // dm_itoa(signum)) call halt(E_NONE) end select end subroutine signal_handler diff --git a/app/dmpipe.f90 b/app/dmpipe.f90 index ac7e858..fcd003c 100644 --- a/app/dmpipe.f90 +++ b/app/dmpipe.f90 @@ -7,7 +7,7 @@ program dmpipe !! applications. Runs a process through an anonymous pipe and forwards !! the parsed result as observation to the next specified process via POSIX !! message queue. - use :: dmpack, dm_log => dm_logger_log + use :: dmpack implicit none (type, external) character(len=*), parameter :: APP_NAME = 'dmpipe' @@ -79,7 +79,7 @@ integer function output_observ(observ, type) result(rc) rc = write_observ(observ, unit=stdout, format=app%format) if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to output observ', error=rc) + call dm_log_error('failed to output observ', error=rc) return end if @@ -90,15 +90,14 @@ integer function output_observ(observ, type) result(rc) newunit=fu, position='append', status='unknown') if (stat /= 0) then - call dm_log(LOG_ERROR, 'failed to open file ' // app%output, error=rc) + call dm_log_error('failed to open file ' // app%output, error=rc) return end if rc = write_observ(observ, unit=fu, format=app%format) if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to write observ to file ' // & - app%output, error=rc) + call dm_log_error('failed to write observ to file ' // app%output, error=rc) end if close (fu) @@ -250,24 +249,24 @@ subroutine run(app) debug = (app%debug .or. app%verbose) - call dm_log(LOG_INFO, 'started ' // app%name) + call dm_log_info('started ' // app%name) ! Run until no jobs are left. job_loop: do njobs = dm_job_list_count(app%jobs) if (njobs == 0) then - if (debug) call dm_log(LOG_DEBUG, 'no jobs left') + if (debug) call dm_log_debug('no jobs left') exit job_loop end if - if (debug) call dm_log(LOG_DEBUG, dm_itoa(njobs) // ' job(s) left in job queue') + if (debug) call dm_log_debug(dm_itoa(njobs) // ' job(s) left in job queue') ! Get next job as deep copy. rc = dm_job_list_next(app%jobs, job) if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to fetch next job', error=rc) + call dm_log_error('failed to fetch next job', error=rc) cycle job_loop end if @@ -275,7 +274,7 @@ subroutine run(app) ! Get pointer to job observation. observ => job%observ - if (debug) call dm_log(LOG_DEBUG, 'starting observ ' // observ%name, observ=observ) + if (debug) call dm_log_debug('starting observ ' // observ%name, observ=observ) ! Initialise observation. observ%id = dm_uuid4() @@ -285,7 +284,7 @@ subroutine run(app) observ%timestamp = dm_time_now() if (observ%nrequests == 0) then - if (debug) call dm_log(LOG_DEBUG, 'no requests in observ ' // observ%name, observ=observ) + if (debug) call dm_log_debug('no requests in observ ' // observ%name, observ=observ) exit observ_if end if @@ -302,8 +301,8 @@ subroutine run(app) if (dm_is_error(rc)) then call dm_pipe_close(pipe) - call dm_log(LOG_ERROR, 'failed to open pipe to ' // request%request, & - observ=observ, error=rc) + call dm_log_error('failed to open pipe to ' // request%request, & + observ=observ, error=rc) cycle req_loop end if @@ -318,8 +317,8 @@ subroutine run(app) rc = dm_regex_request(request) if (dm_is_error(rc)) then - call dm_log(LOG_WARNING, 'response to request ' // dm_itoa(i) // ' does not match pattern', & - observ=observ, error=rc) + call dm_log_warning('response to request ' // dm_itoa(i) // ' does not match pattern', & + observ=observ, error=rc) cycle read_loop end if @@ -327,8 +326,8 @@ subroutine run(app) do j = 1, request%nresponses response => request%responses(j) if (dm_is_ok(response%error)) cycle - call dm_log(LOG_WARNING, 'failed to read response ' // response%name, & - observ=observ, error=response%error) + call dm_log_warning('failed to read response ' // response%name, & + observ=observ, error=response%error) end do exit read_loop @@ -340,26 +339,26 @@ subroutine run(app) request%error = rc if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to read from process ' // request%request, & - observ=observ, error=rc) + call dm_log_error('failed to read from process ' // request%request, & + observ=observ, error=rc) cycle req_loop end if - call dm_log(LOG_DEBUG, 'finished request ' // dm_itoa(i) // ' of ' // & - dm_itoa(observ%nrequests), observ=observ) + call dm_log_debug('finished request ' // dm_itoa(i) // ' of ' // & + dm_itoa(observ%nrequests), observ=observ) ! Wait the set delay time of the request. delay = max(0, request%delay) if (delay <= 0) cycle req_loop if (debug) then - call dm_log(LOG_DEBUG, 'next request of observ ' // trim(observ%name) // & - ' in ' // dm_itoa(delay / 1000) // ' sec', observ=observ) + call dm_log_debug('next request of observ ' // trim(observ%name) // & + ' in ' // dm_itoa(delay / 1000) // ' sec', observ=observ) end if call dm_usleep(delay * 1000) end do req_loop ! Forward observation. - if (debug) call dm_log(LOG_DEBUG, 'finished observ ' // observ%name, observ=observ) + if (debug) call dm_log_debug('finished observ ' // observ%name, observ=observ) rc = dm_mqueue_forward(observ, app%name, APP_MQ_BLOCKING) ! Output observation. @@ -369,7 +368,7 @@ subroutine run(app) ! Wait the set delay time of the job (absolute). delay = max(0, job%delay) if (delay <= 0) cycle job_loop - if (debug) call dm_log(LOG_DEBUG, 'next job in ' // dm_itoa(delay / 1000) // ' sec', observ=observ) + if (debug) call dm_log_debug('next job in ' // dm_itoa(delay / 1000) // ' sec', observ=observ) call dm_usleep(delay * 1000) end do job_loop end subroutine run @@ -381,7 +380,7 @@ subroutine signal_handler(signum) bind(c) select case (signum) case default - call dm_log(LOG_INFO, 'exit on signal ' // dm_itoa(signum)) + call dm_log_info('exit on signal ' // dm_itoa(signum)) call dm_stop(0) end select end subroutine signal_handler diff --git a/app/dmrecv.f90 b/app/dmrecv.f90 index 4fd9076..249dcbe 100644 --- a/app/dmrecv.f90 +++ b/app/dmrecv.f90 @@ -17,7 +17,7 @@ program dmrecv !! Another process has to send observations to message queue "/dmrecv". !! Only responses of name "tz0" will be converted to ASCII block format and !! printed to standard output. - use :: dmpack, dm_log => dm_logger_log + use :: dmpack implicit none (type, external) character(len=*), parameter :: APP_NAME = 'dmrecv' @@ -73,7 +73,7 @@ program dmrecv access = MQUEUE_RDONLY) if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to open mqueue /' // app%name, error=rc) + call dm_log_error('failed to open mqueue /' // app%name, error=rc) exit init_block end if @@ -246,23 +246,23 @@ subroutine run(app, mqueue) file_unit = stdout - call dm_log(LOG_INFO, 'started ' // app%name) + call dm_log_info('started ' // app%name) ipc_loop: do ! Read observation or log from POSIX message queue (blocking). if (app%type == TYPE_OBSERV) then ! Observation. - call dm_log(LOG_DEBUG, 'waiting for observ on mqueue /' // app%name) + call dm_log_debug('waiting for observ on mqueue /' // app%name) rc = dm_mqueue_read(mqueue, observ) else if (app%type == TYPE_LOG) then ! Log. - call dm_log(LOG_DEBUG, 'waiting for log on mqueue /' // app%name) + call dm_log_debug('waiting for log on mqueue /' // app%name) rc = dm_mqueue_read(mqueue, log) end if ! Handle message queue error. if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to read from mqueue /' // app%name, error=rc) + call dm_log_error('failed to read from mqueue /' // app%name, error=rc) call dm_sleep(1) cycle ipc_loop end if @@ -271,19 +271,19 @@ subroutine run(app, mqueue) if (app%type == TYPE_OBSERV) then ! Observation. if (.not. dm_observ_valid(observ)) then - call dm_log(LOG_ERROR, 'invalid observ received', error=E_INVALID) + call dm_log_error('invalid observ received', error=E_INVALID) cycle ipc_loop end if - call dm_log(LOG_DEBUG, 'received observ ' // trim(observ%id)) + call dm_log_debug('received observ ' // trim(observ%id)) else if (app%type == TYPE_LOG) then ! Log. if (.not. dm_log_valid(log)) then - call dm_log(LOG_ERROR, 'invalid log received', error=E_INVALID) + call dm_log_error('invalid log received', error=E_INVALID) cycle ipc_loop end if - call dm_log(LOG_DEBUG, 'received log ' // trim(log%id)) + call dm_log_debug('received log ' // trim(log%id)) end if ! Open output file. @@ -299,7 +299,7 @@ subroutine run(app, mqueue) end if if (stat /= 0) then - call dm_log(LOG_ERROR, 'failed to open file ' // app%output, error=E_IO) + call dm_log_error('failed to open file ' // app%output, error=E_IO) exit ipc_loop end if end if @@ -316,7 +316,7 @@ subroutine run(app, mqueue) y = observ%requests(i)%responses(j)%value) rc = dm_block_write(dp, unit=file_unit) else - call dm_log(LOG_DEBUG, 'no response of name ' // app%response, error=E_NOT_FOUND) + call dm_log_debug('no response of name ' // app%response, error=E_NOT_FOUND) end if case (FORMAT_CSV) ! CSV format. @@ -358,10 +358,10 @@ subroutine run(app, mqueue) if (dm_is_error(rc)) then if (app%type == TYPE_OBSERV) then ! Observation. - call dm_log(LOG_ERROR, 'failed to write observ ' // observ%id, error=rc) + call dm_log_error('failed to write observ ' // observ%id, error=rc) else if (app%type == TYPE_LOG) then ! Log. - call dm_log(LOG_ERROR, 'failed to write log ' // log%id, error=rc) + call dm_log_error('failed to write log ' // log%id, error=rc) end if end if @@ -369,10 +369,10 @@ subroutine run(app, mqueue) if (app%file) then if (app%type == TYPE_OBSERV) then ! Observation. - call dm_log(LOG_DEBUG, 'observ ' // trim(observ%id) // ' written to ' // app%output) + call dm_log_debug('observ ' // trim(observ%id) // ' written to ' // app%output) else if (app%type == TYPE_LOG) then ! Log. - call dm_log(LOG_DEBUG, 'log ' // trim(log%id) // ' written to ' // app%output) + call dm_log_debug('log ' // trim(log%id) // ' written to ' // app%output) end if close (file_unit) @@ -391,7 +391,7 @@ subroutine signal_handler(signum) bind(c) select case (signum) case default - call dm_log(LOG_INFO, 'exit on signal ' // dm_itoa(signum)) + call dm_log_info('exit on signal ' // dm_itoa(signum)) call halt(E_NONE) end select end subroutine signal_handler diff --git a/app/dmreport.f90 b/app/dmreport.f90 index 104b5fd..e54ddc9 100644 --- a/app/dmreport.f90 +++ b/app/dmreport.f90 @@ -252,12 +252,12 @@ integer function read_args(app) result(rc) ! Validate log settings. if (.not. log%disabled) then - if (log%min_level < LOG_NONE .or. log%min_level > LOG_CRITICAL) then + if (.not. dm_log_valid(log%min_level)) then call dm_error_out(rc, 'invalid minimum log level') return end if - if (log%max_level < LOG_NONE .or. log%max_level > LOG_CRITICAL) then + if (.not. dm_log_valid(log%max_level)) then call dm_error_out(rc, 'invalid maximum log level') return end if diff --git a/app/dmsend.f90 b/app/dmsend.f90 index dd22005..4217694 100644 --- a/app/dmsend.f90 +++ b/app/dmsend.f90 @@ -5,7 +5,7 @@ program dmsend !! Reads logs or observations in CSV or Fortran 95 Namelist format from !! file or standard input, then sends all records to a POSIX message queue. - use :: dmpack, dm_log => dm_logger_log + use :: dmpack implicit none (type, external) character(len=*), parameter :: APP_NAME = 'dmsend' @@ -188,11 +188,11 @@ integer function run(app) result(rc) if (len_trim(app%input) > 0 .and. app%input /= '-') is_file = .true. - call dm_log(LOG_INFO, 'started ' // app%name) + call dm_log_info('started ' // app%name) ! Open message queue of receiver for writing. if (.not. app%forward) then - call dm_log(LOG_DEBUG, 'opening mqueue /' // app%receiver) + call dm_log_debug('opening mqueue /' // app%receiver) rc = dm_mqueue_open(mqueue = mqueue, & type = app%type, & name = app%receiver, & @@ -200,7 +200,7 @@ integer function run(app) result(rc) blocking = .true.) if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to open mqueue /' // app%receiver, error=rc) + call dm_log_error('failed to open mqueue /' // app%receiver, error=rc) return end if end if @@ -208,12 +208,12 @@ integer function run(app) result(rc) read_block: block if (is_file) then ! Open input file. - call dm_log(LOG_DEBUG, 'opening input file ' // app%input) + call dm_log_debug('opening input file ' // app%input) open (action='read', file=trim(app%input), iostat=stat, newunit=file_unit, status='old') if (stat /= 0) then rc = E_IO - call dm_log(LOG_ERROR, 'failed to open input file ' // app%input, error=rc) + call dm_log_error('failed to open input file ' // app%input, error=rc) exit read_block end if end if @@ -227,28 +227,28 @@ integer function run(app) result(rc) ! Read observation in CSV or Namelist format. select case (app%format) case (FORMAT_CSV) - call dm_log(LOG_DEBUG, 'reading observ in CSV format') + call dm_log_debug('reading observ in CSV format') rc = dm_csv_read(observ, unit=file_unit) case (FORMAT_NML) - call dm_log(LOG_DEBUG, 'reading observ in NML format') + call dm_log_debug('reading observ in NML format') rc = dm_nml_read(observ, unit=file_unit) end select ! End of file reached. if (rc == E_EOF) then rc = E_NONE - call dm_log(LOG_DEBUG, 'end of file reached') + call dm_log_debug('end of file reached') exit ipc_loop end if if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to read observ', error=rc) + call dm_log_error('failed to read observ', error=rc) exit ipc_loop end if ! Validate input. if (.not. dm_observ_valid(observ)) then - call dm_log(LOG_ERROR, 'invalid input observ ' // observ%id, error=E_INVALID) + call dm_log_error('invalid input observ ' // observ%id, error=E_INVALID) cycle ipc_loop end if @@ -265,28 +265,28 @@ integer function run(app) result(rc) ! Read log in CSV or Namelist format. select case (app%format) case (FORMAT_CSV) - call dm_log(LOG_DEBUG, 'reading log in CSV format') + call dm_log_debug('reading log in CSV format') rc = dm_csv_read(log, unit=file_unit) case (FORMAT_NML) - call dm_log(LOG_DEBUG, 'reading log in NML format') + call dm_log_debug('reading log in NML format') rc = dm_nml_read(log, unit=file_unit) end select ! End of file reached. if (rc == E_EOF) then rc = E_NONE - call dm_log(LOG_DEBUG, 'end of file reached') + call dm_log_debug('end of file reached') exit ipc_loop end if if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to read log', error=rc) + call dm_log_error('failed to read log', error=rc) exit ipc_loop end if ! Validate input. if (.not. dm_log_valid(log)) then - call dm_log(LOG_ERROR, 'invalid input log ' // log%id, error=E_INVALID) + call dm_log_error('invalid input log ' // log%id, error=E_INVALID) cycle ipc_loop end if @@ -296,7 +296,7 @@ integer function run(app) result(rc) ! Handle message queue error. if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to write to mqueue', error=rc) + call dm_log_error('failed to write to mqueue', error=rc) call dm_sleep(1) cycle ipc_loop end if @@ -305,23 +305,23 @@ integer function run(app) result(rc) end do ipc_loop if (is_file) then - call dm_log(LOG_DEBUG, 'closing input file ' // app%input) + call dm_log_debug('closing input file ' // app%input) close (file_unit) end if end block read_block ! Close message queue. if (.not. app%forward) then - call dm_log(LOG_DEBUG, 'closing mqueue /' // app%receiver) + call dm_log_debug('closing mqueue /' // app%receiver) stat = dm_mqueue_close(mqueue) if (dm_is_error(stat)) then - call dm_log(LOG_WARNING, 'failed to close mqueue /' // app%receiver, error=stat) + call dm_log_warning('failed to close mqueue /' // app%receiver, error=stat) end if rc = max(rc, stat) end if - call dm_log(LOG_DEBUG, 'finished transmission of ' // dm_itoa(nrecords) // ' records') + call dm_log_debug('finished transmission of ' // dm_itoa(nrecords) // ' records') end function run end program dmsend diff --git a/app/dmserial.f90 b/app/dmserial.f90 index 3ea4fce..a7f5bc0 100644 --- a/app/dmserial.f90 +++ b/app/dmserial.f90 @@ -4,7 +4,7 @@ ! Licence: ISC program dmserial !! Reads observations from serial port (TTY/PTY). - use :: dmpack, dm_log => dm_logger_log + use :: dmpack implicit none (type, external) character(len=*), parameter :: APP_NAME = 'dmserial' @@ -122,7 +122,7 @@ integer function output_observ(observ, type) result(rc) rc = write_observ(observ, unit=stdout, format=app%format) if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to output observ', error=rc) + call dm_log_error('failed to output observ', error=rc) return end if @@ -134,7 +134,7 @@ integer function output_observ(observ, type) result(rc) newunit=fu, position='append', status='unknown') if (stat /= 0) then - call dm_log(LOG_ERROR, 'failed to open file ' // app%output, error=rc) + call dm_log_error('failed to open file ' // app%output, error=rc) return end if @@ -142,7 +142,7 @@ integer function output_observ(observ, type) result(rc) rc = write_observ(observ, unit=fu, format=app%format) if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to write observ to file ' // app%output, error=rc) + call dm_log_error('failed to write observ to file ' // app%output, error=rc) end if close (fu) @@ -340,7 +340,7 @@ integer function read_observ(tty, observ, debug) result(rc) observ%timestamp = dm_time_now() if (observ%nrequests == 0) then - call dm_log(LOG_INFO, 'no requests in observ ' // observ%name, observ=observ) + call dm_log_info('no requests in observ ' // observ%name, observ=observ) observ%error = rc return end if @@ -350,9 +350,9 @@ integer function read_observ(tty, observ, debug) result(rc) request => observ%requests(i) if (debug_) then - call dm_log(LOG_DEBUG, 'starting request ' // dm_itoa(i) // ' of ' // & - dm_itoa(observ%nrequests), observ=observ) - call dm_log(LOG_DEBUG, 'sending request: ' // request%request, observ=observ) + call dm_log_debug('starting request ' // dm_itoa(i) // ' of ' // & + dm_itoa(observ%nrequests), observ=observ) + call dm_log_debug('sending request: ' // request%request, observ=observ) end if ! Prepare request. @@ -370,14 +370,14 @@ integer function read_observ(tty, observ, debug) result(rc) request%error = dm_tty_write(tty, trim(raw_request)) if (dm_is_error(request%error)) then - call dm_log(LOG_ERROR, 'failed to write to TTY ' // app%tty, observ=observ, & - error=request%error) + call dm_log_error('failed to write to TTY ' // app%tty, observ=observ, & + error=request%error) cycle req_loop end if ! Ignore sensor response if no delimiter is set. if (len_trim(raw_delimiter) == 0) then - if (debug_) call dm_log(LOG_DEBUG, 'no delimiter set in request ' // dm_itoa(i), observ=observ) + if (debug_) call dm_log_debug('no delimiter set in request ' // dm_itoa(i), observ=observ) cycle req_loop end if @@ -386,26 +386,26 @@ integer function read_observ(tty, observ, debug) result(rc) request%response = dm_ascii_escape(raw_response) if (dm_is_error(request%error)) then - call dm_log(LOG_ERROR, 'failed to read from TTY ' // app%tty, & - observ=observ, error=request%error) + call dm_log_error('failed to read from TTY ' // app%tty, & + observ=observ, error=request%error) cycle req_loop end if - if (debug_) call dm_log(LOG_DEBUG, 'received response: ' // raw_response, observ=observ) + if (debug_) call dm_log_debug('received response: ' // raw_response, observ=observ) ! Do not extract responses if no pattern is set. if (len_trim(request%pattern) == 0) then - if (debug_) call dm_log(LOG_DEBUG, 'no pattern in request ' // dm_itoa(i), observ=observ) + if (debug_) call dm_log_debug('no pattern in request ' // dm_itoa(i), observ=observ) cycle req_loop end if ! Try to extract the response values if a regex pattern is given. - if (debug_) call dm_log(LOG_DEBUG, 'extracting response values of request ' // dm_itoa(i), observ=observ) + if (debug_) call dm_log_debug('extracting response values of request ' // dm_itoa(i), observ=observ) request%error = dm_regex_request(request) if (dm_is_error(request%error)) then - call dm_log(LOG_WARNING, 'response to request ' // dm_itoa(i) // ' does not match pattern', & - observ=observ, error=request%error) + call dm_log_warning('response to request ' // dm_itoa(i) // ' does not match pattern', & + observ=observ, error=request%error) cycle req_loop end if @@ -414,28 +414,28 @@ integer function read_observ(tty, observ, debug) result(rc) response => request%responses(j) if (dm_is_error(response%error)) then - call dm_log(LOG_WARNING, 'failed to extract response ' // trim(response%name) // & - ' of request ' // dm_itoa(i), observ=observ, error=response%error) + call dm_log_warning('failed to extract response ' // trim(response%name) // & + ' of request ' // dm_itoa(i), observ=observ, error=response%error) cycle end if if (debug_) then - call dm_log(LOG_DEBUG, 'extracted response ' // trim(response%name) // & - ' of request ' // dm_itoa(i), observ=observ) + call dm_log_debug('extracted response ' // trim(response%name) // & + ' of request ' // dm_itoa(i), observ=observ) end if end do if (debug_) then - call dm_log(LOG_DEBUG, 'finished request ' // dm_itoa(i) // ' of ' // & - dm_itoa(observ%nrequests), observ=observ) + call dm_log_debug('finished request ' // dm_itoa(i) // ' of ' // & + dm_itoa(observ%nrequests), observ=observ) end if ! Wait the set delay time of the request. delay = max(0, request%delay) if (delay <= 0) cycle req_loop if (debug_) then - call dm_log(LOG_DEBUG, 'next request of observ ' // trim(observ%name) // & - ' in ' // dm_itoa(delay / 1000) // ' sec', observ=observ) + call dm_log_debug('next request of observ ' // trim(observ%name) // & + ' in ' // dm_itoa(delay / 1000) // ' sec', observ=observ) end if call dm_usleep(delay * 1000) @@ -454,17 +454,17 @@ integer function run(app, tty) result(rc) debug = (app%debug .or. app%verbose) - call dm_log(LOG_INFO, 'started ' // app%name) - call dm_log(LOG_DEBUG, 'opening TTY ' // trim(app%tty) // ' to sensor ' // trim(app%sensor) // & - ' (' // dm_itoa(tty%baud_rate) // ' ' // dm_itoa(app%byte_size) // & - dm_upper(app%parity(1:1)) // dm_itoa(app%stop_bits) // ')') + call dm_log_info('started ' // app%name) + call dm_log_debug('opening TTY ' // trim(app%tty) // ' to sensor ' // trim(app%sensor) // & + ' (' // dm_itoa(tty%baud_rate) // ' ' // dm_itoa(app%byte_size) // & + dm_upper(app%parity(1:1)) // dm_itoa(app%stop_bits) // ')') ! Open TTY/PTY. do rc = dm_tty_open(tty) if (dm_is_ok(rc)) exit - call dm_log(LOG_ERROR, 'failed to open TTY ' // app%tty, error=rc) - call dm_log(LOG_DEBUG, 'trying to open TTY again in 5 sec', error=rc) + call dm_log_error('failed to open TTY ' // app%tty, error=rc) + call dm_log_debug('trying to open TTY again in 5 sec', error=rc) call dm_sleep(5) end do @@ -475,16 +475,16 @@ integer function run(app, tty) result(rc) if (njobs == 0) then rc = E_NONE - if (debug) call dm_log(LOG_DEBUG, 'no jobs left') + if (debug) call dm_log_debug('no jobs left') exit job_loop end if ! Get next job as deep copy. - if (debug) call dm_log(LOG_DEBUG, dm_itoa(njobs) // ' job(s) left in job queue') + if (debug) call dm_log_debug(dm_itoa(njobs) // ' job(s) left in job queue') rc = dm_job_list_next(app%jobs, job) if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to fetch next job', error=rc) + call dm_log_error('failed to fetch next job', error=rc) cycle job_loop end if @@ -499,16 +499,16 @@ integer function run(app, tty) result(rc) observ%path = trim(app%tty) if (debug) then - call dm_log(LOG_DEBUG, 'starting observ ' // trim(observ%name) // & - ' for sensor ' // app%sensor, observ=observ) + call dm_log_debug('starting observ ' // trim(observ%name) // & + ' for sensor ' // app%sensor, observ=observ) end if ! Read observation from TTY. rc = read_observ(tty, observ, debug=debug) if (debug) then - call dm_log(LOG_DEBUG, 'finished observ ' // trim(observ%name) // & - ' for sensor ' // app%sensor, observ=observ) + call dm_log_debug('finished observ ' // trim(observ%name) // & + ' for sensor ' // app%sensor, observ=observ) end if ! Forward observation. @@ -521,12 +521,12 @@ integer function run(app, tty) result(rc) ! Wait the set delay time of the job (absolute). delay = max(0, job%delay) if (delay <= 0) cycle job_loop - if (debug) call dm_log(LOG_DEBUG, 'next job in ' // dm_itoa(delay / 1000) // ' sec', observ=observ) + if (debug) call dm_log_debug('next job in ' // dm_itoa(delay / 1000) // ' sec', observ=observ) call dm_usleep(delay * 1000) end do job_loop if (dm_tty_connected(tty)) then - call dm_log(LOG_DEBUG, 'closing TTY ' // app%tty) + call dm_log_debug('closing TTY ' // app%tty) call dm_tty_close(tty) end if @@ -561,10 +561,10 @@ subroutine signal_handler(signum) bind(c) select case (signum) case default - call dm_log(LOG_INFO, 'exit on signal ' // dm_itoa(signum)) + call dm_log_info('exit on signal ' // dm_itoa(signum)) if (dm_tty_connected(tty)) then - call dm_log(LOG_DEBUG, 'closing TTY ' // tty%path) + call dm_log_debug('closing TTY ' // tty%path) call dm_tty_close(tty) end if diff --git a/app/dmsync.f90 b/app/dmsync.f90 index 5b71c83..2f646a1 100644 --- a/app/dmsync.f90 +++ b/app/dmsync.f90 @@ -4,7 +4,7 @@ ! Licence: ISC program dmsync !! Observation and log database synchronisation program. - use :: dmpack, dm_log => dm_logger_log + use :: dmpack implicit none (type, external) character(len=*), parameter :: APP_NAME = 'dmsync' @@ -71,7 +71,7 @@ program dmsync timeout = APP_DB_TIMEOUT) if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to open database', error=rc) + call dm_log_error('failed to open database', error=rc) exit init_block end if @@ -80,7 +80,7 @@ program dmsync rc = dm_db_create_observs(db, sync=.true.) if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to create database tables', error=rc) + call dm_log_error('failed to create database tables', error=rc) exit init_block end if end if @@ -90,7 +90,7 @@ program dmsync rc = dm_sem_open(sem, app%wait) if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to open semaphore /' // app%wait, error=rc) + call dm_log_error('failed to open semaphore /' // app%wait, error=rc) exit init_block end if end if @@ -99,7 +99,7 @@ program dmsync rc = dm_rpc_init() if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to initialize libcurl', error=rc) + call dm_log_error('failed to initialize libcurl', error=rc) exit init_block end if @@ -269,7 +269,7 @@ integer function run(app, db, sem) result(rc) type(sensor_type), allocatable :: sensors(:) type(target_type), allocatable :: targets(:) - call dm_log(LOG_INFO, 'started ' // app%name) + call dm_log_info('started ' // app%name) name = dm_sync_name(app%type) limit = APP_SYNC_LIMIT @@ -296,7 +296,7 @@ integer function run(app, db, sem) result(rc) case default ! Fail-safe, should never occur. rc = E_TYPE - call dm_log(LOG_ERROR, 'invalid sync type', error=rc) + call dm_log_error('invalid sync type', error=rc) return end select @@ -329,12 +329,12 @@ integer function run(app, db, sem) result(rc) call dm_timer_start(sync_timer) else ! Wait for semaphore. - call dm_log(LOG_DEBUG, 'waiting for signal from ' // app%wait) + call dm_log_debug('waiting for signal from ' // app%wait) rc = dm_sem_wait(sem) if (dm_is_error(rc)) then ! Unrecoverable semaphore error. Stop program. - call dm_log(LOG_ERROR, 'semaphore error', error=rc) + call dm_log_error('semaphore error', error=rc) exit sync_loop end if end if @@ -359,7 +359,7 @@ integer function run(app, db, sem) result(rc) if (dm_is_error(rc) .and. rc /= E_DB_NO_ROWS) then ! Unrecoverable database error. Stop program. - call dm_log(LOG_ERROR, 'failed to select sync data from database', error=rc) + call dm_log_error('failed to select sync data from database', error=rc) exit sync_loop end if @@ -386,7 +386,7 @@ integer function run(app, db, sem) result(rc) end select if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to select ' // name // ' ' // syncs(i)%id, error=rc) + call dm_log_error('failed to select ' // name // ' ' // syncs(i)%id, error=rc) call dm_sleep(1) cycle sync_loop end if @@ -395,13 +395,13 @@ integer function run(app, db, sem) result(rc) ! Send records concurrently to HTTP-RPC API. rpc_block: block if (n == 0) then - call dm_log(LOG_DEBUG, 'no ' // name // 's to sync found') + call dm_log_debug('no ' // name // 's to sync found') exit rpc_block end if write (message, '("syncing ", i0, " of ", i0, " ", a, "s from database ", a, " with host ", a)') & n, nsyncs, name, trim(app%database), app%host - call dm_log(LOG_DEBUG, message) + call dm_log_debug(message) ! Send data records via HTTP-RPC to the host. call dm_timer_start(rpc_timer) @@ -423,10 +423,10 @@ integer function run(app, db, sem) result(rc) dt = dm_timer_stop(rpc_timer) if (dm_is_error(rc)) then - call dm_log(LOG_DEBUG, 'failed to sync with host ' // app%host, error=rc) + call dm_log_debug('failed to sync with host ' // app%host, error=rc) else write (message, '("finished sync in ", f0.2, " sec")') dt - call dm_log(LOG_DEBUG, message, error=rc) + call dm_log_debug(message, error=rc) end if update_loop: do i = 1, n @@ -434,28 +434,28 @@ integer function run(app, db, sem) result(rc) code_select: select case (responses(i)%code) case (0) ! Failed to connect. - call dm_log(LOG_WARNING, 'connection to host ' // trim(app%host) // ' failed: ' // & - responses(i)%error_message, error=E_RPC_CONNECT) + call dm_log_warning('connection to host ' // trim(app%host) // ' failed: ' // & + responses(i)%error_message, error=E_RPC_CONNECT) case (HTTP_CREATED) ! Success. - call dm_log(LOG_DEBUG, 'synced ' // name // ' ' // trim(ids(i))) + call dm_log_debug('synced ' // name // ' ' // trim(ids(i))) case (HTTP_CONFLICT) ! Record exists in server database. - call dm_log(LOG_INFO, name // ' ' // trim(ids(i)) // ' exists', error=E_EXIST) + call dm_log_info(name // ' ' // trim(ids(i)) // ' exists', error=E_EXIST) case (HTTP_UNAUTHORIZED) ! Missing or wrong API credentials. - call dm_log(LOG_ERROR, 'unauthorized access on host ' // app%host, error=E_RPC_AUTH) + call dm_log_error('unauthorized access on host ' // app%host, error=E_RPC_AUTH) case (HTTP_INTERNAL_SERVER_ERROR) ! Server crashed. - call dm_log(LOG_ERROR, 'internal server error on host ' // app%host, error=E_RPC_SERVER) + call dm_log_error('internal server error on host ' // app%host, error=E_RPC_SERVER) case (HTTP_BAD_GATEWAY) ! Reverse proxy of server failed to connect to API. - call dm_log(LOG_ERROR, 'bad gateway on host ' // app%host, error=E_RPC_CONNECT) + call dm_log_error('bad gateway on host ' // app%host, error=E_RPC_CONNECT) case default ! MIME type `text/plain` indicates API status response. @@ -466,7 +466,7 @@ integer function run(app, db, sem) result(rc) if (dm_is_ok(stat)) then write (message, '("server error on host ", a, " (HTTP ", i0, "): ", a)') & trim(app%host), responses(i)%code, api%message - call dm_log(LOG_ERROR, message, error=api%error) + call dm_log_error(message, error=api%error) exit code_select end if end if @@ -474,7 +474,7 @@ integer function run(app, db, sem) result(rc) ! Otherwise, output generic log message. write (message, '("API call to host ", a, " failed (HTTP ", i0, ")")') & trim(app%host), responses(i)%code - call dm_log(LOG_WARNING, message, error=E_RPC_API) + call dm_log_warning(message, error=E_RPC_API) end select code_select ! Update sync data. @@ -491,20 +491,20 @@ integer function run(app, db, sem) result(rc) ! Re-try insert if database is busy. if (rc == E_DB_BUSY) then write (message, '("database busy (attempt ", i0, " of ", i0, ")")') i, APP_DB_NATTEMPTS - call dm_log(LOG_WARNING, message, error=rc) + call dm_log_warning(message, error=rc) if (j < APP_DB_NATTEMPTS) then call dm_db_sleep(APP_DB_TIMEOUT) else - call dm_log(LOG_INFO, 'sync database update aborted') + call dm_log_info('sync database update aborted') end if cycle db_loop end if if (dm_is_error(rc)) then - call dm_log(LOG_ERROR, 'failed to update sync status: ' // & - dm_db_error_message(db), error=rc) + call dm_log_error('failed to update sync status: ' // & + dm_db_error_message(db), error=rc) end if exit @@ -515,7 +515,7 @@ integer function run(app, db, sem) result(rc) if (nsyncs > limit) then if (dm_is_error(rc)) then ! Wait a grace period on error. - call dm_log(LOG_DEBUG, 'waiting 10 sec before next sync attempt') + call dm_log_debug('waiting 10 sec before next sync attempt') call dm_sleep(10) end if @@ -527,12 +527,12 @@ integer function run(app, db, sem) result(rc) if (.not. app%ipc) then if (app%interval <= 0) exit sync_loop delay = max(1, nint(app%interval - dm_timer_stop(sync_timer))) - call dm_log(LOG_DEBUG, 'next sync in ' // dm_itoa(delay) // ' sec') + call dm_log_debug('next sync in ' // dm_itoa(delay) // ' sec') call dm_sleep(delay) end if end do sync_loop - call dm_log(LOG_DEBUG, 'exiting ...') + call dm_log_debug('exiting ...') end function run subroutine halt(error) @@ -557,7 +557,7 @@ subroutine signal_handler(signum) bind(c) select case (signum) case default - call dm_log(LOG_INFO, 'exit on signal ' // dm_itoa(signum)) + call dm_log_info('exit on signal ' // dm_itoa(signum)) call halt(E_NONE) end select end subroutine signal_handler diff --git a/config/dmfeed.conf.sample b/config/dmfeed.conf.sample index 5bfd53e..426c03a 100644 --- a/config/dmfeed.conf.sample +++ b/config/dmfeed.conf.sample @@ -7,12 +7,12 @@ -- The options `minlevel` and `maxlevel` may be set to one of the following -- named constants: -- --- LOG_NONE - 0 --- LOG_DEBUG - 1 --- LOG_INFO - 2 --- LOG_WARNING - 3 --- LOG_ERROR - 4 --- LOG_CRITICAL - 5 +-- LVL_NONE - 0 +-- LVL_DEBUG - 1 +-- LVL_INFO - 2 +-- LVL_WARNING - 3 +-- LVL_ERROR - 4 +-- LVL_CRITICAL - 5 -- -- Rename table "dmfeed" to the instance name (parameter `--name`). -- @@ -43,8 +43,8 @@ dmfeed = { url = "https://example.com/feed.xml", database = "/var/dmpack/log.sqlite", node = "dummy-node", - minlevel = LOG_WARNING, - maxlevel = LOG_CRITICAL, + minlevel = LVL_WARNING, + maxlevel = LVL_CRITICAL, nentries = 100, xsl = "feed.xsl", output = "/var/www/feed.xml", diff --git a/config/dmlogger.conf.sample b/config/dmlogger.conf.sample index b1f513e..e62ad55 100644 --- a/config/dmlogger.conf.sample +++ b/config/dmlogger.conf.sample @@ -4,12 +4,12 @@ -- The option `minlevel` may be set to one of the following -- named constants: -- --- LOG_NONE - 0 --- LOG_DEBUG - 1 --- LOG_INFO - 2 --- LOG_WARNING - 3 --- LOG_ERROR - 4 --- LOG_CRITICAL - 5 +-- LVL_NONE - 0 +-- LVL_DEBUG - 1 +-- LVL_INFO - 2 +-- LVL_WARNING - 3 +-- LVL_ERROR - 4 +-- LVL_CRITICAL - 5 -- -- Rename table "dmlogger" to the instance name (parameter `--name`). -- @@ -25,7 +25,7 @@ dmlogger = { database = "/var/dmpack/log.sqlite", node = "dummy-node", - minlevel = LOG_INFO, + minlevel = LVL_INFO, ipc = false, verbose = true } diff --git a/config/dmreport.conf.sample b/config/dmreport.conf.sample index 4db340c..8b15a58 100644 --- a/config/dmreport.conf.sample +++ b/config/dmreport.conf.sample @@ -4,12 +4,12 @@ -- The options `minlevel` and `maxlevel` may be set to one of the following -- named constants: -- --- LOG_NONE - 0 --- LOG_DEBUG - 1 --- LOG_INFO - 2 --- LOG_WARNING - 3 --- LOG_ERROR - 4 --- LOG_CRITICAL - 5 +-- LVL_NONE - 0 +-- LVL_DEBUG - 1 +-- LVL_INFO - 2 +-- LVL_WARNING - 3 +-- LVL_ERROR - 4 +-- LVL_CRITICAL - 5 -- -- Rename table "dmreport" to the instance name (parameter `--name`). -- @@ -60,8 +60,8 @@ dmreport = { logs = { disabled = false, -- Disable logs. database = "/var/dmpack/log.sqlite", -- Path to log database. - minlevel = LOG_WARNING, -- Minimum log level (default: 3). - maxlevel = LOG_CRITICAL, -- Maximum log level (default: 5). + minlevel = LVL_WARNING, -- Minimum log level (default: LVL_WARNING). + maxlevel = LVL_CRITICAL, -- Maximum log level (default: LVL_CRITICAL). title = "Logs", -- Overwrite default heading. meta = "Logs example.", -- Optional description. } diff --git a/guide/guide.adoc b/guide/guide.adoc index 5f5f888..a4da6d9 100644 --- a/guide/guide.adoc +++ b/guide/guide.adoc @@ -361,28 +361,28 @@ example, `1970-01-01T00:00:00.000000+00:00`. === Observation Entities -Node:: A unique sensor node within a sensor network. Contains id, name, +<>:: A unique sensor node within a sensor network. Contains id, +name, description, and optional position. +<>:: A unique sensor attached to a _node_, with id, name, description, and optional position. -Sensor:: A unique sensor attached to a _node_, with id, name, description, and -optional position. -Target:: A unique measurement target (point of interest, location) with id, -name, description, and optional position. Multiple nodes and sensors may share a -single target. -Observation:: A single measurement identified by name and unique UUID4 that -contains requests to and responses from a sensor, referencing a _node_, a -_sensor_, and a _target_. An observation can contain up to 8 requests which will -be sent to the sensor in sequential order. -Request:: Command to send to the sensor, referencing an _observation_ and -ordered by index. A request can contain up to 16 _responses_. -Response:: Floating-point values in the raw response of a _sensor_ can be -matched by regular expression groups. Each matched group is stored as a -response. Responses reference a _request_, and are ordered by index. They -contain name, type, value, unit, and an optional error code. +<>:: A unique measurement target (point of interest, +location) with id, name, description, and optional position. Multiple nodes and +sensors may share a single target. +<>:: A single measurement identified by name and unique +UUID4 that contains requests to and responses from a sensor, referencing a +_node_, a _sensor_, and a _target_. An observation can contain up to 8 requests +which will be sent to the sensor in sequential order. +<>:: Command to send to the sensor, referencing an +_observation_ and ordered by index. A request can contain up to 16 _responses_. +<>:: Floating-point values in the raw response of a +_sensor_ can be matched by regular expression groups. Each matched group is +stored as a response. Responses reference a _request_, and are ordered by index. +They contain name, type, value, unit, and an optional error code. === Log Entities -Log:: Log message of a sensor node, either of level `DEBUG`, `INFO`, `WARNING`, -`ERROR`, or `CRITICAL`, and optionally related to a _sensor_, a _target_, and an +Log:: Log message of a sensor node, either of level _debug_, _info_, _warning_, +_error_, or _critical_, and optionally related to a _sensor_, a _target_, and an _observation_. === Beat Entities @@ -602,7 +602,7 @@ for testing. | `--config _file_` | `-c` | – | Path to configuration file. | `--count _n_` | `-C` | 0 | Maximum number of heartbeats to send (unlimited if `0`). -| `--debug` | `-D` | off | Forward log messages of level `DEBUG` via IPC (if logger is set). +| `--debug` | `-D` | off | Forward log messages of level _debug_ via IPC (if logger is set). | `--help` | `-h` | – | Output available command-line arguments and quit. | `--host _host_` | `-H` | – | IP or FQDN of HTTP-RPC host (for instance, `127.0.0.1` or `iot.example.com`). | `--interval _seconds_` | `-I` | 0 | Emit interval in seconds. @@ -645,7 +645,7 @@ equals the *dmdb* name. Only a single process may wait for the semaphore. | `--config _file_` | `-c` | – | Path to configuration file. | `--database _file_` | `-d` | – | Path to SQLite observation database. -| `--debug` | `-D` | off | Forward log messages of level `DEBUG` via IPC (if logger is set). +| `--debug` | `-D` | off | Forward log messages of level _debug_ via IPC (if logger is set). | `--help` | `-h` | – | Output available command-line arguments and quit. | `--ipc` @@ -914,7 +914,7 @@ present in the database. | Option | Short | Default | Description | `--config _file_` | `-c` | – | Path to configuration file (required). -| `--debug` | `-D` | off | Forward log messages of level `DEBUG` via IPC (if logger is set). +| `--debug` | `-D` | off | Forward log messages of level _debug_ via IPC (if logger is set). | `--format _format_` | `-f` | – | Output format, either `csv` or `jsonl`. | `--help` | `-h` | – | Output available command-line arguments and quit. | `--logger _name_` | `-l` | – | Optional name of logger. If set, sends logs to <> process of given name. @@ -1185,11 +1185,11 @@ The following log levels are accepted: |=== | Level | Name -| 1 | `DEBUG` -| 2 | `INFO` -| 3 | `WARNING` -| 4 | `ERROR` -| 5 | `CRITICAL` +| 1 | debug +| 2 | info` +| 3 | warning +| 4 | error +| 5 | critical |=== ==== Command-Line Options @@ -1256,11 +1256,11 @@ The following log levels are accepted: |=== | Level | Name -| 1 | `DEBUG` -| 2 | `INFO` -| 3 | `WARNING` -| 4 | `ERROR` -| 5 | `CRITICAL` +| 1 | debug +| 2 | info +| 3 | warning +| 4 | error +| 5 | critical |=== ==== Command-Line Options @@ -1338,7 +1338,7 @@ the observation will be discarded. | Option | Short | Default | Description | `--config _file_` | `-c` | – | Path to configuration file (optional). -| `--debug` | `-D` | off | Forward log messages of level `DEBUG` via IPC (if logger is set). +| `--debug` | `-D` | off | Forward log messages of level _debug_ via IPC (if logger is set). | `--help` | `-h` | – | Output available command-line arguments and quit. | `--logger _name_` | `-l` | – | Optional name of logger. If set, sends logs to <> process of given name. | `--name _name_` | `-n` | `dmlua` | Name of instance and table in given configuration file. @@ -1408,7 +1408,7 @@ database for the observation to be stored. | Option | Short | Default | Description | `--config _file_` | `-c` | – | Path to configuration file (required). -| `--debug` | `-D` | off | Forward log messages of level `DEBUG` via IPC (if logger is set). +| `--debug` | `-D` | off | Forward log messages of level _debug_ via IPC (if logger is set). | `--format _format_` | `-f` | – | Output format, either `csv` or `jsonl`. | `--help` | `-h` | – | Output available command-line arguments and quit. | `--logger _name_` | `-l` | – | Optional name of logger. If set, sends logs to <> process of given name. @@ -1585,8 +1585,8 @@ Output the plot directly to terminal, with the configuration loaded from file: $ dmplot --name dmplot -node --config dmplot.conf --terminal sixelgd .... -The `sixelgd` format requires a terminal emulator with Sixel support (such as -_xterm(1)_ or _mlterm(1)_). +The `sixelgd` format requires a terminal emulator with Sixel support, such as +_xterm(1)_ or _mlterm(1)_. .Plotting time series directly in XTerm [#img-dmplot] @@ -1640,7 +1640,7 @@ configuration file. The arguments overwrite settings from file. | Option | Short | Default | Description | `--config _file_` | `-c` | – | Path to configuration file. -| `--debug` | `-D` | off | Forward log messages of level `DEBUG` via IPC (if logger is set). +| `--debug` | `-D` | off | Forward log messages of level _debug_ via IPC (if logger is set). | `--format _format_` | `-f` | – | <> (`block`, `csv`, `jsonl`, `nml`). | `--forward` | `-F` | off | Forward observations to the next specified receiver. | `--help` | `-h` | – | Output available command-line arguments and quit. @@ -1770,8 +1770,8 @@ dmreport = { logs = { disabled = false, -- Disable logs. database = "log.sqlite", -- Path to log database. - minlevel = LOG_WARNING, -- Minimum log level (default: LOG_WARNING). - maxlevel = LOG_CRITICAL, -- Maximum log level (default: LOG_CRITICAL). + minlevel = LVL_WARNING, -- Minimum log level (default: LVL_WARNING). + maxlevel = LVL_CRITICAL, -- Maximum log level (default: LVL_CRITICAL). title = "Logs", -- Overwrite default heading. meta = "", -- Optional description. } @@ -1832,7 +1832,7 @@ configuration file. The arguments overwrite settings from file. | Option | Short | Default | Description | `--config _file_` | `-c` | – | Path to configuration file. -| `--debug` | `-D` | off | Forward log messages of level `DEBUG` via IPC (if logger is set). +| `--debug` | `-D` | off | Forward log messages of level _debug_ via IPC (if logger is set). | `--format _format_` | `-f` | – | Input format: `csv` or `nml`. | `--input _file_` | `-i` | _stdin_ | Path to input file (empty or `-` for _stdin_). | `--forward` | `-F` | off | Forward observations to the next specified receiver. @@ -1895,7 +1895,7 @@ The following baud rates are supported: 50, 75, 110, 134, 150, 200, 300, 600, | `--baudrate _n_` | `-B` | 9600 | Number of symbols transmitted per second (4800, 9600, 115200, …). | `--bytesize _n_` | `-Z` | 8 | Byte size (5, 6, 7, 8). | `--config _file_` | `-c` | – | Path to configuration file (required). -| `--debug` | `-D` | off | Forward log messages of level `DEBUG` via IPC (if logger is set). +| `--debug` | `-D` | off | Forward log messages of level _debug_ via IPC (if logger is set). | `--dtr` | `-Q` | off | Enable Data Terminal Ready (DTR). | `--format _format_` | `-f` | – | Output format, either `csv` or `jsonl`. | `--help` | `-h` | – | Output available command-line arguments and quit. @@ -1964,7 +1964,7 @@ for testing. | `--config _file_` | `-c` | – | Path to configuration file. | `--create` | `-C` | off | Create database synchronisation tables if they do not exist. | `--database _file_` | `-d` | – | Path to log or observation database, depending on `--type`. -| `--debug` | `-D` | off | Forward log messages of level `DEBUG` via IPC (if logger is set). +| `--debug` | `-D` | off | Forward log messages of level _debug_ via IPC (if logger is set). | `--help` | `-h` | – | Output available command-line arguments and quit. | `--host _host_` | `-H` | – | IP address or FQDN of HTTP-RPC host (for instance, `127.0.0.1` or `iot.example.com`). | `--interval _seconds_` | `-I` | 60 | Synchronisation interval in seconds. If `0`, synchronisation is executed only once. @@ -2912,10 +2912,10 @@ the beat, otherwise, the request will be rejected as unauthorised (HTTP 401). |=== | Status | Description -| `200` | Heartbeat is returned. +| `200` | Beat is returned. | `400` | Invalid request. | `401` | Unauthorised. -| `404` | Heartbeat not found. +| `404` | Beat not found. | `500` | Server error. | `503` | Database error. |=== @@ -2925,7 +2925,7 @@ the beat, otherwise, the request will be rejected as unauthorised (HTTP 401). |=== | Status | Description -| `201` | Heartbeat was accepted. +| `201` | Beat was accepted. | `400` | Invalid request or payload. | `401` | Unauthorised. | `413` | Payload too large. @@ -3571,11 +3571,11 @@ BEAT%UPTIME=0, |=== | Level | Name -| 1 | `DEBUG` -| 2 | `INFO` -| 3 | `WARNING` -| 4 | `ERROR` -| 5 | `CRITICAL` +| 1 | debug +| 2 | info +| 3 | warning +| 4 | error +| 5 | critical |=== .Atom XML [[data-log-atom]] @@ -3775,7 +3775,7 @@ NODE%Z=0.0, | `requests` | array | 8{nbsp}×{nbsp}1380 | Array of requests (8). |=== -.Request derived type of an observation +.Request derived type of an observation [[data-request]] [cols="3,2,2,14"] |=== | Attribute | Type | Size | Description @@ -3796,7 +3796,7 @@ NODE%Z=0.0, | `responses` | array | 16{nbsp}×{nbsp}32 | Extracted values from the raw response (16). |=== -.Response derived type of a request +.Response derived type of a request [[data-response]] [cols="3,2,2,14"] |=== | Attribute | Type | Size | Description @@ -4278,7 +4278,7 @@ Observation Database:: Stores nodes, sensors, targets, observations, observation receivers, observation requests, and observation responses, with optional synchronisation tables for all record types. Log Database:: Stores all log messages in single table. -Heartbeat Database:: Stores heartbeat messages by unique node id. +Beat Database:: Stores heartbeat messages by unique node id. The databases are usually located in directory `/var/dmpack/`. @@ -4309,7 +4309,7 @@ image::log.svg[UML,align="center",scaledwidth=25%] [#db-uml-observ] image::observ.svg[UML,align="center"] -.Heartbeat database +.Beat database [#db-uml-beat] image::beat.svg[UML,align="center",scaledwidth=25%] diff --git a/src/dm_atom.f90 b/src/dm_atom.f90 index a679a43..db99e8b 100644 --- a/src/dm_atom.f90 +++ b/src/dm_atom.f90 @@ -192,7 +192,7 @@ function atom_entry_log(log, alt) result(xml) integer :: level - level = max(min(LOG_NLEVEL, log%level), LOG_NONE) + level = max(LVL_NONE, min(LVL_LAST, log%level)) ! Atom entry. xml = A_ENTRY // & diff --git a/src/dm_html.f90 b/src/dm_html.f90 index 908442d..b34aaa9 100644 --- a/src/dm_html.f90 +++ b/src/dm_html.f90 @@ -834,7 +834,7 @@ function dm_html_log(log, prefix_node, prefix_sensor, prefix_target, prefix_obse integer :: level type(anchor_type) :: anchor - level = max(LOG_NONE, min(LOG_NLEVEL, log%level)) + level = max(LVL_NONE, min(LVL_LAST, log%level)) ! Node id. if (present(prefix_node) .and. len_trim(log%node_id) > 0) then @@ -946,7 +946,7 @@ function dm_html_logs(logs, prefix, node, max_len) result(html) if (node_) html = html // H_TD // dm_html_encode(logs(i)%node_id) // H_TD_END - level = max(LOG_NONE, min(LOG_NLEVEL, logs(i)%level)) + level = max(LVL_NONE, min(LVL_LAST, logs(i)%level)) min_len = len_trim(logs(i)%message) max_len_ = min_len diff --git a/src/dm_log.f90 b/src/dm_log.f90 index f0b1c57..141de51 100644 --- a/src/dm_log.f90 +++ b/src/dm_log.f90 @@ -15,29 +15,32 @@ module dm_log private ! Log level. - integer, parameter, public :: LOG_NONE = 0 !! Invalid log level, not used by DMPACK. - integer, parameter, public :: LOG_DEBUG = 1 !! For debugging purposes. - integer, parameter, public :: LOG_INFO = 2 !! For information regarding normal system behaviour. - integer, parameter, public :: LOG_WARNING = 3 !! For events requiring the attention of the system operator. - integer, parameter, public :: LOG_ERROR = 4 !! Unexpected behaviour, may indicate failure. - integer, parameter, public :: LOG_CRITICAL = 5 !! Reserved for monitoring events, not used by DMPACK internally. - integer, parameter, public :: LOG_NLEVEL = 6 !! Number of log level. + integer, parameter, public :: LVL_NONE = 0 !! Invalid log level, not used by DMPACK. + integer, parameter, public :: LVL_DEBUG = 1 !! For debugging purposes. + integer, parameter, public :: LVL_INFO = 2 !! For information regarding normal system behaviour. + integer, parameter, public :: LVL_WARNING = 3 !! For events requiring the attention of the system operator. + integer, parameter, public :: LVL_ERROR = 4 !! Unexpected behaviour, may indicate failure. + integer, parameter, public :: LVL_CRITICAL = 5 !! Reserved for monitoring events, not used by DMPACK internally. + integer, parameter, public :: LVL_LAST = 5 !! Never use this. ! Log parameters. + integer, parameter, public :: LOG_NLEVEL = 6 !! Number of log level. integer, parameter, public :: LOG_ID_LEN = UUID_LEN !! Max. log id length. integer, parameter, public :: LOG_SOURCE_LEN = ID_LEN !! Max. log source length. integer, parameter, public :: LOG_MESSAGE_LEN = 512 !! Max. log message length. - character(len=*), parameter, public :: LOG_LEVEL_NAMES(0:LOG_NLEVEL - 1) = [ & - character(len=8) :: 'NONE', 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL' ] !! Log level strings. + character(len=*), parameter, public :: LOG_LEVEL_NAMES(0:LVL_LAST) = [ & + character(len=8) :: 'NONE', 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL' & + ] !! Log level strings. - character(len=*), parameter, public :: LOG_LEVEL_NAMES_LOWER(0:LOG_NLEVEL - 1) = [ & - character(len=8) :: 'none', 'debug', 'info', 'warning', 'error', 'critical' ] !! Log level strings in lower-case. + character(len=*), parameter, public :: LOG_LEVEL_NAMES_LOWER(0:LVL_LAST) = [ & + character(len=8) :: 'none', 'debug', 'info', 'warning', 'error', 'critical' & + ] !! Log level strings in lower-case. type, public :: log_type !! Log message type. character(len=LOG_ID_LEN) :: id = UUID_DEFAULT !! Database log id (mandatory). - integer :: level = LOG_WARNING !! Log level (mandatory). + integer :: level = LVL_WARNING !! Log level (mandatory). integer :: error = E_NONE !! Error code (optional). character(len=TIME_LEN) :: timestamp = TIME_DEFAULT !! Timestamp, shall be in ISO 8601 plus milliseconds and time zone (mandatory). character(len=NODE_ID_LEN) :: node_id = ' ' !! Sensor node ID (optional). @@ -121,13 +124,13 @@ end subroutine dm_log_out ! ****************************************************************** pure elemental logical function dm_log_valid_level(level) result(valid) !! Returns `.true.` if given log level is valid, i.e., either - !! `LOG_DEBUG`, `LOG_WARNING`, `LOG_ERROR`, or `LOG_CRITICAL`. + !! `LVL_DEBUG`, `LVL_WARNING`, `LVL_ERROR`, or `LVL_CRITICAL`. !! - !! The level `LOG_NONE` is invalid. + !! The level `LVL_NONE` is invalid. integer, intent(in) :: level !! Log level. valid = .false. - if (level < LOG_DEBUG .or. level > LOG_CRITICAL) return + if (level < 0 .or. level > LVL_LAST) return valid = .true. end function dm_log_valid_level diff --git a/src/dm_logger.f90 b/src/dm_logger.f90 index ccef076..f87c1df 100644 --- a/src/dm_logger.f90 +++ b/src/dm_logger.f90 @@ -30,7 +30,8 @@ module dm_logger ! ANSI colours of log level. integer, parameter :: LOGGER_COLORS(0:5) = [ & - COLOR_RESET, COLOR_GREEN, COLOR_BLUE, COLOR_YELLOW, COLOR_RED, COLOR_RED ] + COLOR_RESET, COLOR_GREEN, COLOR_BLUE, COLOR_YELLOW, COLOR_RED, COLOR_RED & + ] type, public :: logger_type !! Opaque logger type. @@ -53,9 +54,45 @@ module dm_logger procedure :: dm_logger_log_type end interface dm_logger_log + interface dm_log_critical + !! Alias for subroutine. + module procedure :: dm_logger_log_critical + end interface + + interface dm_log_debug + !! Alias for subroutine. + module procedure :: dm_logger_log_debug + end interface + + interface dm_log_error + !! Alias for subroutine. + module procedure :: dm_logger_log_error + end interface + + interface dm_log_info + !! Alias for subroutine. + module procedure :: dm_logger_log_info + end interface + + interface dm_log_warning + !! Alias for subroutine. + module procedure :: dm_logger_log_warning + end interface + + public :: dm_log_debug + public :: dm_log_info + public :: dm_log_warning + public :: dm_log_error + public :: dm_log_critical + public :: dm_logger_fail public :: dm_logger_init public :: dm_logger_log + public :: dm_logger_log_critical + public :: dm_logger_log_debug + public :: dm_logger_log_error + public :: dm_logger_log_info + public :: dm_logger_log_warning public :: dm_logger_out public :: dm_logger_send @@ -72,7 +109,7 @@ subroutine dm_logger_fail(message, error, source) type(log_type) :: log log = log_type(timestamp = dm_time_now(), & - level = LOG_ERROR, & + level = LVL_ERROR, & message = message, & source = LOGGER%source) @@ -119,10 +156,10 @@ subroutine dm_logger_log_args(level, message, source, observ, timestamp, error) type(log_type) :: log ! Ignore debug messages if forwarding and output are both disabled. - if (level == LOG_DEBUG .and. .not. LOGGER%debug .and. .not. LOGGER%verbose) return + if (level == LVL_DEBUG .and. .not. LOGGER%debug .and. .not. LOGGER%verbose) return - ! Replace invalid log level with `LOG_ERROR`. - log%level = LOG_ERROR + ! Replace invalid log level with `LVL_ERROR`. + log%level = LVL_ERROR if (dm_log_valid(level)) log%level = level ! Set log data. @@ -157,6 +194,61 @@ subroutine dm_logger_log_args(level, message, source, observ, timestamp, error) if (LOGGER%ipc) call dm_logger_send(log) end subroutine dm_logger_log_args + subroutine dm_logger_log_critical(message, source, observ, timestamp, error) + !! Sends a debug log message to the message queue. + character(len=*), intent(in) :: message !! Log message. + character(len=*), intent(in), optional :: source !! Optional source of log. + type(observ_type), intent(inout), optional :: observ !! Optional observation data. + character(len=*), intent(in), optional :: timestamp !! Optional timestamp of log. + integer, intent(in), optional :: error !! Optional error code. + + call dm_logger_log(LVL_CRITICAL, message, source, observ, timestamp, error) + end subroutine dm_logger_log_critical + + subroutine dm_logger_log_debug(message, source, observ, timestamp, error) + !! Sends a debug log message to the message queue. + character(len=*), intent(in) :: message !! Log message. + character(len=*), intent(in), optional :: source !! Optional source of log. + type(observ_type), intent(inout), optional :: observ !! Optional observation data. + character(len=*), intent(in), optional :: timestamp !! Optional timestamp of log. + integer, intent(in), optional :: error !! Optional error code. + + call dm_logger_log(LVL_DEBUG, message, source, observ, timestamp, error) + end subroutine dm_logger_log_debug + + subroutine dm_logger_log_error(message, source, observ, timestamp, error) + !! Sends a error log message to the message queue. + character(len=*), intent(in) :: message !! Log message. + character(len=*), intent(in), optional :: source !! Optional source of log. + type(observ_type), intent(inout), optional :: observ !! Optional observation data. + character(len=*), intent(in), optional :: timestamp !! Optional timestamp of log. + integer, intent(in), optional :: error !! Optional error code. + + call dm_logger_log(LVL_ERROR, message, source, observ, timestamp, error) + end subroutine dm_logger_log_error + + subroutine dm_logger_log_info(message, source, observ, timestamp, error) + !! Sends a info log message to the message queue. + character(len=*), intent(in) :: message !! Log message. + character(len=*), intent(in), optional :: source !! Optional source of log. + type(observ_type), intent(inout), optional :: observ !! Optional observation data. + character(len=*), intent(in), optional :: timestamp !! Optional timestamp of log. + integer, intent(in), optional :: error !! Optional error code. + + call dm_logger_log(LVL_INFO, message, source, observ, timestamp, error) + end subroutine dm_logger_log_info + + subroutine dm_logger_log_warning(message, source, observ, timestamp, error) + !! Sends a warning log message to the message queue. + character(len=*), intent(in) :: message !! Log message. + character(len=*), intent(in), optional :: source !! Optional source of log. + type(observ_type), intent(inout), optional :: observ !! Optional observation data. + character(len=*), intent(in), optional :: timestamp !! Optional timestamp of log. + integer, intent(in), optional :: error !! Optional error code. + + call dm_logger_log(LVL_WARNING, message, source, observ, timestamp, error) + end subroutine dm_logger_log_warning + subroutine dm_logger_log_type(log) !! Sends a log data type to the message queue (send & forget). The !! passed log is not validated and must have id, node id, and @@ -178,7 +270,7 @@ subroutine dm_logger_out(log, unit) integer :: level, unit_ - level = LOG_ERROR + level = LVL_ERROR if (dm_log_valid(log%level)) level = log%level unit_ = stderr @@ -213,7 +305,7 @@ subroutine dm_logger_send(log) type(mqueue_type) :: mqueue if (.not. LOGGER%ipc) return - if (.not. LOGGER%debug .and. log%level <= LOG_DEBUG) return + if (.not. LOGGER%debug .and. log%level <= LVL_DEBUG) return ! Open message queue for writing. rc = dm_mqueue_open(mqueue = mqueue, & diff --git a/src/dm_lua_api.f90 b/src/dm_lua_api.f90 index 88502ba..a007e5d 100644 --- a/src/dm_lua_api.f90 +++ b/src/dm_lua_api.f90 @@ -36,12 +36,12 @@ integer function dm_lua_api_register(lua, add_errors, add_levels, add_procedures !! The following log level parameters are injected if `add_levels` is !! not `.false.`: !! - !! * `LOG_NONE` - !! * `LOG_DEBUG` - !! * `LOG_INFO` - !! * `LOG_WARNING` - !! * `LOG_ERROR` - !! * `LOG_CRITICAL` + !! * `LVL_NONE` + !! * `LVL_DEBUG` + !! * `LVL_INFO` + !! * `LVL_WARNING` + !! * `LVL_ERROR` + !! * `LVL_CRITICAL` !! !! The following Lua procedures are registered if `add_procedures` is !! not `.false.`: @@ -179,12 +179,12 @@ integer function dm_lua_api_register(lua, add_errors, add_levels, add_procedures ! Add log levels. if (add_levels_) then - rc = dm_lua_eval(lua, 'LOG_NONE = ' // dm_itoa(LOG_NONE)); if (dm_is_error(rc)) return - rc = dm_lua_eval(lua, 'LOG_DEBUG = ' // dm_itoa(LOG_DEBUG)); if (dm_is_error(rc)) return - rc = dm_lua_eval(lua, 'LOG_INFO = ' // dm_itoa(LOG_INFO)); if (dm_is_error(rc)) return - rc = dm_lua_eval(lua, 'LOG_WARNING = ' // dm_itoa(LOG_WARNING)); if (dm_is_error(rc)) return - rc = dm_lua_eval(lua, 'LOG_ERROR = ' // dm_itoa(LOG_ERROR)); if (dm_is_error(rc)) return - rc = dm_lua_eval(lua, 'LOG_CRITICAL = ' // dm_itoa(LOG_CRITICAL)); if (dm_is_error(rc)) return + rc = dm_lua_eval(lua, 'LVL_NONE = ' // dm_itoa(LVL_NONE)); if (dm_is_error(rc)) return + rc = dm_lua_eval(lua, 'LVL_DEBUG = ' // dm_itoa(LVL_DEBUG)); if (dm_is_error(rc)) return + rc = dm_lua_eval(lua, 'LVL_INFO = ' // dm_itoa(LVL_INFO)); if (dm_is_error(rc)) return + rc = dm_lua_eval(lua, 'LVL_WARNING = ' // dm_itoa(LVL_WARNING)); if (dm_is_error(rc)) return + rc = dm_lua_eval(lua, 'LVL_ERROR = ' // dm_itoa(LVL_ERROR)); if (dm_is_error(rc)) return + rc = dm_lua_eval(lua, 'LVL_CRITICAL = ' // dm_itoa(LVL_CRITICAL)); if (dm_is_error(rc)) return end if ! Register response type parameters. diff --git a/src/dm_mqueue_util.f90 b/src/dm_mqueue_util.f90 index 243be52..1b912c0 100644 --- a/src/dm_mqueue_util.f90 +++ b/src/dm_mqueue_util.f90 @@ -35,7 +35,7 @@ integer function mqueue_forward_observ(observ, name, blocking, quiet, self) resu !! next receiver in the list. use :: dm_id use :: dm_log - use :: dm_logger, dm_log => dm_logger_log + use :: dm_logger use :: dm_observ use :: dm_system, only: dm_system_error_message type(observ_type), intent(inout) :: observ !! Observation to forward. @@ -69,7 +69,7 @@ integer function mqueue_forward_observ(observ, name, blocking, quiet, self) resu ! End of receiver list reached? if (next > observ%nreceivers) then - if (.not. quiet_) call dm_log(LOG_DEBUG, 'no receivers left in observ ' // observ%name, observ=observ) + if (.not. quiet_) call dm_log_debug('no receivers left in observ ' // observ%name, observ=observ) return end if @@ -77,8 +77,8 @@ integer function mqueue_forward_observ(observ, name, blocking, quiet, self) resu if (.not. dm_id_valid(observ%receivers(next))) then rc = E_INVALID if (.not. quiet_) then - call dm_log(LOG_ERROR, 'invalid receiver ' // trim(observ%receivers(next)) // & - ' in observ ' // observ%name, observ=observ, error=rc) + call dm_log_error('invalid receiver ' // trim(observ%receivers(next)) // & + ' in observ ' // observ%name, observ=observ, error=rc) end if return end if @@ -92,8 +92,8 @@ integer function mqueue_forward_observ(observ, name, blocking, quiet, self) resu if (self_ .or. observ%receivers(next) /= name) exit if (.not. quiet_) then - call dm_log(LOG_DEBUG, 'skipped receiver ' // dm_itoa(next) // ' (' // & - trim(observ%receivers(next)) // ') of observ ' // observ%name) + call dm_log_debug('skipped receiver ' // dm_itoa(next) // ' (' // & + trim(observ%receivers(next)) // ') of observ ' // observ%name) end if end do @@ -108,8 +108,8 @@ integer function mqueue_forward_observ(observ, name, blocking, quiet, self) resu ! Exit on error. if (dm_is_error(rc)) then if (.not. quiet_) then - call dm_log(LOG_ERROR, 'failed to open mqueue /' // trim(observ%receivers(next)) // ': ' // & - dm_system_error_message(), observ=observ, error=rc) + call dm_log_error('failed to open mqueue /' // trim(observ%receivers(next)) // ': ' // & + dm_system_error_message(), observ=observ, error=rc) end if exit mqueue_block end if @@ -121,15 +121,16 @@ integer function mqueue_forward_observ(observ, name, blocking, quiet, self) resu ! Exit on error. if (dm_is_error(rc)) then if (.not. quiet_) then - call dm_log(LOG_ERROR, 'failed to send observ ' // trim(observ%name) // & - ' to mqueue /' // observ%receivers(next), observ=observ, error=rc) + call dm_log_error('failed to send observ ' // trim(observ%name) // & + ' to mqueue /' // observ%receivers(next), observ=observ, error=rc) end if exit mqueue_block end if if (.not. quiet_) then - call dm_log(LOG_DEBUG, 'sent observ ' // trim(observ%name) // ' from ' // & - trim(observ%source) // ' to mqueue /' // observ%receivers(next), observ=observ) + call dm_log_debug('sent observ ' // trim(observ%name) // ' from ' // & + trim(observ%source) // ' to mqueue /' // observ%receivers(next), & + observ=observ) end if end block mqueue_block @@ -137,8 +138,8 @@ integer function mqueue_forward_observ(observ, name, blocking, quiet, self) resu rc = dm_mqueue_close(mqueue) if (dm_is_error(rc) .and. .not. quiet_) then - call dm_log(LOG_WARNING, 'failed to close mqueue /' // observ%receivers(next) // ': ' // & - dm_system_error_message(), observ=observ, error=rc) + call dm_log_warning('failed to close mqueue /' // observ%receivers(next) // ': ' // & + dm_system_error_message(), observ=observ, error=rc) end if end function mqueue_forward_observ end module dm_mqueue_util diff --git a/src/dm_report.f90 b/src/dm_report.f90 index c667379..af4777c 100644 --- a/src/dm_report.f90 +++ b/src/dm_report.f90 @@ -45,8 +45,8 @@ module dm_report type, public :: report_log_type !! Section logs of report. logical :: disabled = .false. !! Generate plots. - integer :: min_level = LOG_WARNING !! Minimum log level. - integer :: max_level = LOG_CRITICAL !! Maximum log level. + integer :: min_level = LVL_WARNING !! Minimum log level. + integer :: max_level = LVL_CRITICAL !! Maximum log level. character(len=FILE_PATH_LEN) :: database = ' ' !! Path to observation database (required). character(len=REPORT_META_LEN) :: meta = ' ' !! Description text. character(len=REPORT_TITLE_LEN) :: title = 'Logs' !! Section title. @@ -100,10 +100,8 @@ logical function dm_report_valid(report) result(valid) end if if (.not. report%log%disabled) then - if (report%log%min_level < LOG_NONE) return - if (report%log%min_level > LOG_CRITICAL) return - if (report%log%max_level < LOG_NONE) return - if (report%log%max_level > LOG_CRITICAL) return + if (.not. dm_log_valid(report%log%min_level)) return + if (.not. dm_log_valid(report%log%max_level)) return if (report%log%min_level > report%log%max_level) return if (len_trim(report%log%database) == 0) return end if diff --git a/src/dm_test.f90 b/src/dm_test.f90 index 71a093e..24a795a 100644 --- a/src/dm_test.f90 +++ b/src/dm_test.f90 @@ -112,7 +112,7 @@ impure elemental subroutine dm_test_dummy_log(log, timestamp) call random_number(r) log = log_type(id = dm_uuid4(), & - level = 1 + int(LOG_ERROR * r(1)), & + level = 1 + int(LVL_ERROR * r(1)), & error = int(E_READ_ONLY * r(2)), & timestamp = dm_time_now(), & node_id = 'dummy-node', & diff --git a/test/dmtestlogger.f90 b/test/dmtestlogger.f90 index 67cfb2d..a4b5a9a 100644 --- a/test/dmtestlogger.f90 +++ b/test/dmtestlogger.f90 @@ -12,19 +12,22 @@ program dmtestlogger type(test_type) :: tests(NTESTS) call dm_init() - tests(1) = test_type('dmtestlogger.test01', test01) + tests = [ test_type('dmtestlogger.test01', test01) ] call dm_test_run(tests, stats, dm_env_has('NO_COLOR')) contains logical function test01() result(stat) - character(len=*), parameter :: JSON = & - '{ "id": "f5ec2dd3870a47b5be3ae397552706fe", "level": 4, "error": 1, "timestamp": ' // & + character(len=*), parameter :: JSON = & + '{ "id": "f5ec2dd3870a47b5be3ae397552706fe", "level": 4, "error": 2, "timestamp": ' // & '"1970-01-01T00:00:00.000000+00:00", "node_id": "test-node", "sensor_id": "test-sensor", ' // & - '"target_id": "test-target", "observ_id": "6b0ca75ae594425a8d38adfd709b11cd", "message": "test" }' - character(len=*), parameter :: LOGGER_NAME = 'dmlogger' - character(len=*), parameter :: TEST_MESSAGE = 'test' + '"target_id": "test-target", "observ_id": "6b0ca75ae594425a8d38adfd709b11cd", ' // & + '"message": "test message" }' + character(len=*), parameter :: LOGGER_NAME = 'dmlogger' + character(len=*), parameter :: TEST_MESSAGE = 'test message' + integer, parameter :: TEST_ERROR = E_DUMMY + integer, parameter :: TEST_LEVEL = LVL_INFO character(len=:), allocatable :: buffer - type(log_type) :: log1, log2 + type(log_type) :: log1, log2, log3 type(log_type) :: logs(1) type(mqueue_type) :: mqueue type(observ_type) :: observ @@ -39,33 +42,42 @@ logical function test01() result(stat) observ%target_id = 'test-target' log1%id = 'f5ec2dd3870a47b5be3ae397552706fe' - log1%level = LOG_ERROR + log1%level = LVL_ERROR log1%message = TEST_MESSAGE log1%node_id = observ%node_id log1%sensor_id = observ%sensor_id log1%target_id = observ%target_id log1%observ_id = observ%id log1%timestamp = TIME_DEFAULT - log1%error = E_ERROR + log1%error = TEST_ERROR print *, 'Initialising logger ...' - call dm_logger_init(ipc=.true., no_color=dm_env_has('NO_COLOR')) - - print *, 'Creating log message ...' - call dm_logger_log(log1) + call dm_logger_init(debug=.true., ipc=.true., no_color=.true.) print *, 'Opening log message queue ...' if (dm_mqueue_open(mqueue, TYPE_LOG, LOGGER_NAME, MQUEUE_RDONLY) /= E_NONE) return + print *, 'Creating log message ...' + call dm_logger_log(log1) + print *, 'Reading from log message queue ...' if (dm_mqueue_read(mqueue, log2) /= E_NONE) return - print *, 'Printing log message ...' - call dm_logger_out(log2) + print *, 'Creating log message ...' + call dm_log_info(TEST_MESSAGE, error=TEST_ERROR, observ=observ) + + print *, 'Reading from log message queue ...' + if (dm_mqueue_read(mqueue, log3) /= E_NONE) return print *, 'Closing log message queue ...' if (dm_mqueue_close(mqueue) /= E_NONE) return + print *, 'Unlinking log message queue ...' + if (dm_mqueue_unlink(mqueue) /= E_NONE) return + + print *, 'Printing log message ...' + call dm_logger_out(log2) + print *, 'Validating log message ...' if (.not. dm_log_valid(log2)) return if (.not. (log1 == log2)) return @@ -78,6 +90,15 @@ logical function test01() result(stat) logs(1) = log2 print *, dm_json_from(logs) + print *, 'Printing log message ...' + call dm_logger_out(log3) + + print *, 'Validating log message ...' + if (.not. dm_log_valid(log3)) return + if (log3%level /= TEST_LEVEL) return + if (log3%message /= TEST_MESSAGE) return + if (log3%error /= TEST_ERROR) return + stat = TEST_PASSED end function test01 end program dmtestlogger