-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: create logging proxy #663
Conversation
27418b8
to
b8d265c
Compare
The logging proxy: - prevents the need to import chronicles (as well as export except toJson), - prevents the need to override `writeValue` or use or import nim-json-seralization elsewhere in the codebase, allowing for sole use of utils/json for de/serialization, - and handles json formatting correctly in chronicles json sinks
Not specifying a LogFormat will apply the formatting to both textlines and json sinks. Specifying a LogFormat will apply the formatting to only that sink.
We only need to import utils/json instead of std/json
Was causing unit tests to fail on Windows.
Windows was erroring with `could not load: pcre64.dll`. Instead of fixing that error, remove the pcre usage :)
Both json and textlines formatIt were not needed, and could be combined into one formatIt
debug output and logformat of json for integration test logs
Before the changes in this branch, fromBytes was likely being resolved by nim-stew, or other dependency. With the changes in this branch, that dependency was removed and fromBytes could no longer be resolved. By exporting fromBytes from nim-poseidon, the correct resolution is now happening.
b8d265c
to
ca98d10
Compare
json.`%`(body) | ||
else: | ||
newJNull() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oddly enough, if I add:
import questionable/results
proc setProperty*(r: var JsonRecord, key: string, opt: ?!T) =
# ...
The compiler complains that it cannot resolve the symbol ?!
. The same happens if I use the long hand Result[T, ref CatchableError]
as well. nimsuggest
offers a further explanation that this may be due to a circular depdency, BUT HOW???
undeclared identifier: '?!'
candidates (edit distance, scope distance); see '--spellSuggest':
(1, 3): '!' [template declared in /Users/egonat/repos/status-im/nim-codex/vendor/questionable/questionable/options.nim(23, 10)]
(1, 3): '?' [template declared in /Users/egonat/repos/status-im/nim-codex/vendor/questionable/questionable/options.nim(17, 10)]
This might be caused by a recursive module dependency:
/Users/egonat/repos/status-im/nim-codex/codex/logutils.nim imports /Users/egonat/repos/status-im/nim-codex/codex/logutils.nim
/Users/egonat/repos/status-im/nim-codex/codex/logutils.nim imports /Users/egonat/repos/status-im/nim-codex/codex/codex.nim
/Users/egonat/repos/status-im/nim-codex/codex/codex.nim imports /Users/egonat/repos/status-im/nim-codex/codex/logutils.nim
/Users/egonat/repos/status-im/nim-codex/codex/logutils.nim imports /Users/egonat/repos/status-im/nim-codex/codex/codex.nim
/Users/egonat/repos/status-im/nim-codex/codex/codex.nim imports /Users/egonat/repos/status-im/nim-codex/codex/codex.nim
/Users/egonat/repos/status-im/nim-codex/codex/codex.nim imports /Users/egonat/repos/status-im/nim-codex/codex/logutils.nim
/Users/egonat/repos/status-im/nim-codex/codex/logutils.nim imports /Users/egonat/repos/status-im/nim-codex/codex/node.nim
/Users/egonat/repos/status-im/nim-codex/codex/node.nim imports /Users/egonat/repos/status-im/nim-codex/codex/node.nim
/Users/egonat/repos/status-im/nim-codex/codex/node.nim imports /Users/egonat/repos/status-im/nim-codex/codex/node.nim
/Users/egonat/repos/status-im/nim-codex/codex/node.nim imports /Users/egonat/repos/status-im/nim-codex/codex/node.nim
/Users/egonat/repos/status-im/nim-codex/codex/node.nim imports /Users/egonat/repos/status-im/nim-codex/codex/node.nim
/Users/egonat/repos/status-im/nim-codex/codex/node.nim imports /Users/egonat/repos/status-im/nim-codex/codex/node.nim
/Users/egonat/repos/status-im/nim-codex/codex/node.nim imports /Users/egonat/repos/status-im/nim-codex/codex/codex.nim
/Users/egonat/repos/status-im/nim-codex/codex/codex.nim imports /Users/egonat/repos/status-im/nim-codex/codex/logutils.nim
/Users/egonat/repos/status-im/nim-codex/codex/logutils.nim imports /Users/egonat/repos/status-im/nim-codex/codex/logutils.nim
/Users/egonat/repos/status-im/nim-codex/codex/logutils.nim imports /Users/egonat/repos/status-im/nim-codex/codex/codex.nim
/Users/egonat/repos/status-im/nim-codex/codex/codex.nim imports /Users/egonat/repos/status-im/nim-codex/codex/logutils.nim
/Users/egonat/repos/status-im/nim-codex/codex/logutils.nim imports /Users/egonat/repos/status-im/nim-codex/codex/codex.nim
/Users/egonat/repos/status-im/nim-codex/codex/codex.nim imports /Users/egonat/repos/status-im/nim-codex/codex/logutils.nim
/Users/egonat/repos/status-im/nim-codex/codex/logutils.nim imports /Users/egonat/repos/status-im/nim-codex/codex/logutils.nim
/Users/egonat/repos/status-im/nim-codex/codex/logutils.nim imports /Users/egonat/repos/status-im/nim-codex/codex/logutils.nim
/Users/egonat/repos/status-im/nim-codex/codex/logutils.nim imports /Users/egonat/repos/status-im/nim-codex/codex/codex.nim
/Users/egonat/repos/status-im/nim-codex/codex/codex.nim imports /Users/egonat/repos/status-im/nim-codex/codex/node.nim
/Users/egonat/repos/status-im/nim-codex/codex/node.nim imports /Users/egonat/repos/status-im/nim-codex/codex/chunker.nim
/Users/egonat/repos/status-im/nim-codex/codex/chunker.nim imports /Users/egonat/repos/status-im/nim-codex/codex/blocktype.nim
/Users/egonat/repos/status-im/nim-codex/codex/blocktype.nim imports /Users/egonat/repos/status-im/nim-codex/codex/codextypes.nim
/Users/egonat/repos/status-im/nim-codex/codex/codextypes.nim imports /Users/egonat/repos/status-im/nim-codex/codex/units.nim
/Users/egonat/repos/status-im/nim-codex/codex/units.nim imports /Users/egonat/repos/status-im/nim-codex/codex/logutils.nim
logutils
does not import codex
which seems to be the root of the circular dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks bad overall, have we figured out the root cause?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By removing the {.dirty.}
annotation and injecting the needed it
vars, the issue was resolved. questionable/results
is also now exported, so its possible this was the cause of the undeclared identifier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Add a logging proxy to achieve several goals:
--log-format=json
) which was effectively broken for many types.nim-json-serialization
from the codebasewriteValue
for new typestoJson
,%
,%*
to prevent conflictsWhen declaring a new type, one should consider importing the
codex/logutils
module, and specifyingformatIt
. If textlines log output and json log output need to be different, overloadformatIt
appropriately. If a json serialization is needed, it can be declared with a%
proc. Onlycodex/logutils
needs to be imported.With this PR in:
pkg/chronicles
, importpkg/codex/logutils
chronicles
is exported bylogutils
std/json
, importpkg/codex/utils/json
std/json
is exported byutils/json
which is exported bylogutils
pkg/nim-json-serialization
, importpkg/codex/utils/json
nim-json-serialization
In this case,
BlockAddress
is just an object, soutils/json
can handle serializing it without issue (only fields annotated with{.serialize.}
will serialize (opt-in).If one so wished, another option for the textlines log output, would be to simply
toString
the serialised json:In that case, both the textlines and json sinks would have the same output, so we could reduce this even further by not specifying a
LogFormat
:Note
Special thanks to @elcritch for the help on this one!