You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unclear, the docs and behavior conflict. I suspect the author's intent was to make self.class.build_time_format(precision) the default time format.
The documentation and behavior for the Base formatter (lib/semantic_logger/formatters/base.rb) conflict. The documentation for the constructor includes:
# nil: Returns Empty string for time ( no time is output ).
# Default: '%Y-%m-%d %H:%M:%S.%<precision>N'
...but the constructor defaults the time_format parameter to nil:
definitialize(time_format: nil, ...
...so it would appear that the time_format defaults to excluding the time from the formatted log string, since the format_time method returns the empty string if the time_format property is nil.
However, in the constructor, the code guarantees that if nil is passed it will be overridden with a non-nil formatter:
If nil is passed to the constructor, or the parameter is omitted, the nil is overridden with a non-empty time format.
Pull Request
I am filing a PR with test code that illustrates the conflict, and shows how one can work around it if one wants to set the time_format to nil. (That is, to call thetime_format= method, passing nil, after the formatter is initialized.)
This PR is not (yet) intended to be merged, so I have marked it WIP and not added any entries to the Changelog.
@reidmorrison Which is the desired behavior? Perhaps we should make self.class.build_time_format(precision) the default value for the time_format parameter so that nil can be specified to override it?
The text was updated successfully, but these errors were encountered:
Environment
Expected Behavior
Unclear, the docs and behavior conflict. I suspect the author's intent was to make
self.class.build_time_format(precision)
the default time format.The documentation and behavior for the Base formatter (lib/semantic_logger/formatters/base.rb) conflict. The documentation for the constructor includes:
...but the constructor defaults the time_format parameter to nil:
...so it would appear that the time_format defaults to excluding the time from the formatted log string, since the
format_time
method returns the empty string if thetime_format
property is nil.However, in the constructor, the code guarantees that if nil is passed it will be overridden with a non-nil formatter:
Actual Behavior
If nil is passed to the constructor, or the parameter is omitted, the nil is overridden with a non-empty time format.
Pull Request
I am filing a PR with test code that illustrates the conflict, and shows how one can work around it if one wants to set the time_format to nil. (That is, to call the
time_format=
method, passing nil, after the formatter is initialized.)This PR is not (yet) intended to be merged, so I have marked it WIP and not added any entries to the Changelog.
@reidmorrison Which is the desired behavior? Perhaps we should make
self.class.build_time_format(precision)
the default value for thetime_format
parameter so thatnil
can be specified to override it?The text was updated successfully, but these errors were encountered: