I am playing with stdlib_logger and I think it would be nice to have a subroutine for messages that should be printed only during debug phases.
message to self % log_unitscall self % log_debug( message [,module, procedure, stat, errmsg] )
Log levels are used for filtering the messages based on their level/severity.
Each subroutine log_error, log_information, log_io_error, log_text_error, log_warning, and the additional log_debug is associated with a level.
For example:
log_debug associated with debug_levellog_information associated with information_levellog_warning associated with warning_levellog_error, log_io_error, log_text_error associated with error_levelwith debug_level < information_level < warning_level < error_level.
Since log_message is called by all other log subroutines, it is probably best to not assign a level to log_message IMO.
The level of the logger should be set with the method configure, e.g. call self %configure( level = information_level), meaning that all calls with a level < information_level would be ignored.
Such log level options are avaible in Julia or Python loggers.
@wclodius2 , @milancurcic , @14NGiestas , @ivan-pi , @certik is that of interests? any thoughs, comments?
A few comments. This is really two separate proposals" adding log_debug and adding level, and I think it would be best addressed by two separate PRs. Levels are also used by FLIBS (m_exception). On the other hand, Futility (exception_handler) has separate flags for each "level", so that you can output "debug" while not outputting "information" or "warning". Testing the effects of level will be tricky. How do you verify what is not output? log_text_error is different from the other error levels. It indicates a problem not with the application, but rather with a file being read by the application. I suspect its output should be independent of level. Overall I am in favor of adding log_debug, but worry that adding level will be a bit tricky.
A few comments. This is really two separate proposals" adding
log_debugand addinglevel, and I think it would be best addressed by two separate PRs.
I agree with you that it should be two separate PR.
Re: log_debug, its implementation is straighfoward. The main question is about its API. Should it be similar to e.g., log_information,
call self % log_debug( message [, module, procedure ] )
Here is a draft of log_debug.
Levels are also used by FLIBS (
m_exception). On the other hand, Futility (exception_handler) has separate flags for each "level", so that you can output "debug" while not outputting "information" or "warning".
The proposed approach in this message is similar to Julia and Python loggers.
However, the approach proposed of Futility (exception_handler) seem to be more flexible, but more difficult to implement and manage (even for the user).
Here is a draft for a proposition similar to Julia and Python loggers.
Note that the different default levels could be set by the user too.
Testing the effects of
levelwill be tricky. How do you verify what is not output?
I don't understand that. For example, we could verify that a message is not printed to output_unit. Here is a proposition for testing the different options.
log_text_erroris different from the other error levels. It indicates a problem not with the application, but rather with a file being read by the application. I suspect its output should be independent oflevel.
Right. Default levels should be discussed first and set accordingly.
Overall I am in favor of adding
log_debug, but worry that addinglevelwill be a bit tricky.
I am not sure what is tricky with the option level (at least in the way I imagine it). I might miss something about the 'level' approach.
The draft and the proposition for testing look mostly reasonable. A few comments on it:
stdlib_ prefix useful for avoiding naming conflicts between modules, but unnecessary for module entities. If you insist on a prefix I would make it "log_".if ... then ... else ... end if, I no longer do that though you may be doing that to be consistent with my earlier style in the test code.if ( self % level > stdlib_..._level) return should have a blank between level and ).Thank you for your comments. I integrated them, and submitted a first PR (#256) for adding log_debug.
Great!
Most helpful comment
The draft and the proposition for testing look mostly reasonable. A few comments on it:
stdlib_prefix useful for avoiding naming conflicts between modules, but unnecessary for module entities. If you insist on a prefix I would make it "log_".if ... then ... else ... end if, I no longer do that though you may be doing that to be consistent with my earlier style in the test code.if ( self % level > stdlib_..._level) returnshould have a blank betweenleveland).