-
Notifications
You must be signed in to change notification settings - Fork 101
feat(reporter): Add new reporter for common logging, timing, and eventing #3654
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
Open
JasonVMo
wants to merge
18
commits into
main
Choose a base branch
from
jasonvmo/scripts/reporter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,791
−0
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Create @rnx-kit/reporter
This is a common package for logging output to the console and/or logfiles,
timing tasks and operations, and listening for events for task start, finish,
and errors.
It also contains a performance tracker that can be enabled to dump performance
information from execution of tasks. Enabling performance tracing will chain to
child processes as well to handle script tracking.
Motivation
Standardizing the reporter used in our packages allows for easier high level
perf analysis of how our tools are behaving. By adding the various events it
also gives a common framework for people to add listeners for telemetry if
desired.
Usage
Reporters have two roles, the base Reporter role, and a Task role. Reporters are
effectively at the root level, whereas Tasks are parented to a reporter or
another Task.
Reporters are created by calling
createReporter<T>(options: ReporterOptions<T>)
with any options specified.data
property.will be surfaced in events.
The reporter interface is comprised of several parts:
Logging Functions
These include
error
,warn
,log
, andverbose
. These are structured likethe console logging functions in that they have variable parameters, which will
be serialized into a single message string by using node's
inspect
. This isthe same internal mechanism used by console.log, at least in the node
implementation.
LogLevel
set in either the global settings, or overridden in thereporter settings dictates whether anything is output from the functions.
"log"
is the default level, which will enable theerror
,warn
, andlog
functions. The
verbose
function will do nothing.OutputOptions
when creating areporter or by calling
updateDefaultOutput
.set specifically in the file settings.
all messages of this type. For instance the default error prefix contains
"Error:"
types.
An additional
throwError
function is provided which will log the error andthen throw with that message. It will send an event for the error, and log it
under the reporter/task.
Timing Functions
The task functions wrap a function call, either async or synchronous, creating a
new sub reporter in the Task role which is passed as a parameter. The task data
type, output, and formatting options are inherited from the parent reporter.
Events will be sent when the task is started and when it completes, with errors
and sub-operation timing recorded within.
The
time
andtimeAsync
functions are helpers for high frequency operationtiming. The results of these operations will be aggregated within the given
reporter or task, and will record the total elapsed time and number of calls.
These will be available in the complete event.
Formatting Functions
These functions are part of the
ReporterFormatting
interface and providehelpers which will format or color text using the settings for the given
reporter.