Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • FORCES FORCES
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 12
    • Issues 12
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 5
    • Merge requests 5
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • CHSCHS
  • FORCESFORCES
  • Merge requests
  • !63

Add logging

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Sebastian Müller requested to merge add_logging into main Sep 10, 2022
  • Overview 5
  • Commits 22
  • Pipelines 11
  • Changes 7

Added mo_logging that was derived from the flogging project of Daan van Vugt.

The logging module is integrated into mo_cli to setup a command line interface with logging options on the fly:

#include "logging.h"
program test_log
  use mo_logging
  use mo_cli, only : cli_parser
  implicit none
  type(cli_parser) :: parser
  parser = cli_parser( &
    description="Program with cli and logger.", &
    add_help_option=.true., &
    add_logger_options=.true.)
  call parser%parse()
  log_fatal(*) "fatal"
  log_error(*) "error"
  log_warn(*) "warn"
  log_info(*) "info"
  log_debug(*) "debug"
  log_trace(*) "trace"
  log_subtrace(*) "subtrace"
end program test_log

You can now call this program with:

$ ./prog --quiet
  test.F90:12    FATAL fatal
  test.F90:13    ERROR error
  test.F90:14     WARN warn

You can see the logging options with:

$ ./prog -h

mo_message provides a format reset switch, since logging uses formatting, you need to reset the format before you can write standard messages again (not colored or bold)

log_info(*) "info in green"
call message("normal text again", reset_format=.true.)

Also mo_message now has public switches to turn message on and off: show_msg and show_err. An optional show argument was added to message and error_message with these global variables as default values.

use mo_message, only : message, show_msg
show_msg = .false.
call message("not showing")
call message("forced to be showing", show=.true.)
show_msg = .true.
call message("showing up again")
call message("will never show up", show=.false.)

Finally, an optional raise argument was added to error_message to control the stop call:

call error_message("***ERROR: this went wrong", raise=.false.)
call error_message("          some more details and a stop..")
Edited Jan 10, 2023 by Sebastian Müller
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: add_logging