-
Notifications
You must be signed in to change notification settings - Fork 39
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
Custom logger for unstructured and structured logging #171
Conversation
# Conflicts: # fuzzing/config/config.go # fuzzing/config/config_defaults.go # fuzzing/fuzzer.go # fuzzing/test_case_property.go
So I'm well through this review. Generally, I think it looks pretty great. My thoughts so far is:
Hopefully that makes sense. I think if we can cook up a good solution to the first major bullet point, I'd generally be good to merge here. |
The PR has been updated as follows:
|
- Remove `CyanBold` and use `Bold` instead for coloring because it looks bad - Remove default " " delimiter and added spaces wherever necessary. - Update windows kernel calls to enable ANSI escape codes on stderr as well - Add an `init()` function to `colors` package so that ANSI escape codes are enabled during package import - Some small update to formatting
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.
bing bong
This PR introduces colorized logging for console and future support for structured logging --------- Co-authored-by: David Pokora <dpokora@gmail.com>
This PR closes #19 and introduces a custom logging API that has the capabilities to support both structured and unstructured logging. The logging API works as follows:
The API effectively accepts a variadic set of arguments. These arguments are evaluated one by one and are dealt with accordingly:
colors.Red
) then the nextn
arguments are colored with that color until we hit acolors.Reset
.StructuredLogInfo
then that info becomes a set of key-value pairs for that log object.fmt.Sprintf("%v")
.The API also allows you to create sub-loggers. Thus, there is one
GlobalLogger
that is instantiated inNewFuzzer
and each "module" (e.g. fuzzer, corpus) can create a sub-logger that can be used to contextualize each module's log message with their own "module" key-value pair.Each
Logger
consists of aconsoleLogger
and amultiLogger
. TheconsoleLogger
is used for console output whereas themultiLogger
holds a list ofwriters
that can perform both structured or unstructured logging to an arbitrary channel. This can be useful for third-party integrations down the line. Currently, at setup theGlobalLogger
is enabled with console logging and unstructured logging to one file (if requested by the config). Then, the fuzzer creates its own sub-logger off of that. The downside of this approach is that if youAddWriter
to theGlobalLogger
, then any sub-loggers branched off of it do not have access to the new writer. This downside should be evaluated during this PR review. Note that due to this design, theFatal
log level is not supported. This is because it is not possible to log to both channels before hitting anos.Exit(1)
.We also introduce the idea of a
LogBuffer
in this PR that allows you to create complex, formatted strings for log output (e.g. execution tracer). ALogBuffer
should ideally be used only right before logging or if aString()
capability is required. Otherwise, even an[]any
is sufficient for logging.The following should be evaluated before merging this PR:
AddWriter
/RemoveWriter
deter any future integrations. Is the use of aGlobalLogger
the best way to approach this? How do we handle adding new writers to a variety of different sub-loggers?