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
The --format=human or --format=json now controls the STDERR reporting of exceptions. See: MatrixAI/Polykey#323.
Examples of the new error logging style:
# Single error (no cause)# --format=human (default)
ErrorStatusLocked: Status is locked by another process
exitCode 75
timestamp Mon May 23 2022 15:25:08 GMT+1000 (Australian Eastern Standard Time)
# --format=json
{"type":"ErrorStatusLocked","data":{"message":"","timestamp":"2022-05-23T05:00:32.049Z","data":{},"stack":"ErrorStatusLocked\n at constructor_.start (/home/emma/Projects/js-polykey/src/status/Status.ts:53:13)\n at async /home/emma/Projects/js-polykey/node_modules/@matrixai/async-init/src/StartStop.ts:56:24\n at async withF (/home/emma/Projects/js-polykey/node_modules/@matrixai/resources/src/utils.ts:24:12)\n at async Object.bootstrapState (/home/emma/Projects/js-polykey/src/bootstrap/utils.ts:73:5)\n at async /home/emma/Projects/js-polykey/src/bin/bootstrap/CommandBootstrap.ts:24:31\n at async CommandBootstrap.<anonymous> (/home/emma/Projects/js-polykey/src/bin/CommandPolykey.ts:75:7)\n at async CommandPolykey.parseAsync (/home/emma/Projects/js-polykey/node_modules/commander/lib/command.js:923:5)\n at async main (/home/emma/Projects/js-polykey/src/bin/polykey.ts:54:5)\n at async /home/emma/Projects/js-polykey/src/bin/polykey.ts:103:5","exitCode":75}}
# Remote error with cause# --format=human (default)
ErrorPolykeyRemote: Remote error from RPC call
command nodesPing
nodeId vasrqbpb1u51khi7ibg5j63ai3odomhj6js348k1ra5jffjuvrhsg
host 127.0.0.1
port 37595
timestamp Mon May 23 2022 15:25:21 GMT+1000 (Australian Eastern Standard Time)
remote error: ErrorNodeGraphEmptyDatabase: NodeGraph database was empty
exitCode 64
timestamp Mon May 23 2022 15:25:21 GMT+1000 (Australian Eastern Standard Time)
# --format=json
{"type":"ErrorPolykeyRemote","data":{"message":"","timestamp":"2022-05-23T04:56:47.661Z","data":{},"cause":{"type":"ErrorNodeGraphEmptyDatabase","data":{"message":"","timestamp":"2022-05-23T04:56:47.648Z","data":{},"stack":"ErrorNodeGraphEmptyDatabase\n at constructor_.getClosestGlobalNodes (/home/emma/Projects/js-polykey/src/nodes/NodeConnectionManager.ts:456:13)\n at async constructor_.findNode (/home/emma/Projects/js-polykey/src/nodes/NodeConnectionManager.ts:373:17)\n at async NodeManager.pingNode (/home/emma/Projects/js-polykey/src/nodes/NodeManager.ts:58:7)\n at async Object.nodesPing (/home/emma/Projects/js-polykey/src/client/service/nodesPing.ts:48:22)","exitCode":64}},"stack":"ErrorPolykeyRemote\n at toError (/home/emma/Projects/js-polykey/src/grpc/utils/utils.ts:202:29)\n at Object.callback (/home/emma/Projects/js-polykey/src/grpc/utils/utils.ts:380:17)\n at Object.onReceiveStatus (/home/emma/Projects/js-polykey/node_modules/@grpc/grpc-js/src/client.ts:351:26)\n at /home/emma/Projects/js-polykey/node_modules/@grpc/grpc-js/src/call-stream.ts:206:27\n at Object.onReceiveStatus (/home/emma/Projects/js-polykey/src/grpc/utils/FlowCountInterceptor.ts:57:13)\n at InterceptingListenerImpl.onReceiveStatus (/home/emma/Projects/js-polykey/node_modules/@grpc/grpc-js/src/call-stream.ts:202:19)\n at /home/emma/Projects/js-polykey/node_modules/@grpc/grpc-js/src/call-stream.ts:206:27\n at Object.onReceiveStatus (/home/emma/Projects/js-polykey/node_modules/@grpc/grpc-js/src/client-interceptors.ts:163:5)\n at InterceptingListenerImpl.onReceiveStatus (/home/emma/Projects/js-polykey/node_modules/@grpc/grpc-js/src/call-stream.ts:202:19)\n at Object.onReceiveStatus (/home/emma/Projects/js-polykey/node_modules/@grpc/grpc-js/src/client-interceptors.ts:462:34)","exitCode":64,"metadata":{"nodeId":{"type":"IdInternal","data":[87,55,165,229,97,241,67,72,200,242,92,11,51,13,82,30,27,139,70,102,159,6,68,80,59,81,102,247,207,223,220,121]},"host":"127.0.0.1","port":37595,"command":"nodesPing"}}}
Normal logger messages remain the same (i.e. are not affected by the format option). This can be addressed later in MatrixAI/js-logger#3.
However the verbosity of the report should be controlled with our --verbosity flag.
For --format=json because we expect this to be processed by machines, we can say that --verbose doesn't affect it, and instead all information is produced.
However for --format=human we can progressively show more information.
Right now without a verbosity flag, our logging level is set to show warnings and up. With the -v we get info logs, and -vv we get debug logs. This means we can think of having 3 levels of error reporting.
The default level without a -v should be assumed to be used by an end-user of the CLI program, who will probably never look at the source code of PK. Which means, any error we report should only really have the error description and error message. The error name can be useful, if they want to report the error to the dev who can identify the exception.
With -v, extra information about the error should be shown, this should probably mean all the properties except the stack property and this applies recursively to the cause chain.
Finally with -vv we should show the stack property as well.
This should apply to exceptions reported on the src/bin/polykey.ts and src/bin/polykey-agent.ts. In the case of PolykeyAgent, this depends on pk agent start -vv, verbosity flags passed from pk agent start subcommand.
Should verbosity flags also control json format? I would argue not atm, but I could be convinced otherwise. Perhaps some additional work on structured logging could help decide Integrate Structured Logging js-logger#3
Tasks
- Parameterise the current error formatter in outputFormatter. Use the verbosity level. It should be a number.
- Apply the verbosity flags to CLI subcommands
- Apply the verbosity flags to pk agent start
- Add tests to ensure that verbosity flags are being respected
- Document the output formatter, and what default means, and -v means and -vv means.
Specification
The
--format=humanor--format=jsonnow controls the STDERR reporting of exceptions. See: MatrixAI/Polykey#323.However the verbosity of the report should be controlled with our
--verbosityflag.For
--format=jsonbecause we expect this to be processed by machines, we can say that--verbosedoesn't affect it, and instead all information is produced.However for
--format=humanwe can progressively show more information.Right now without a verbosity flag, our logging level is set to show warnings and up. With the
-vwe get info logs, and-vvwe get debug logs. This means we can think of having 3 levels of error reporting.The default level without a
-vshould be assumed to be used by an end-user of the CLI program, who will probably never look at the source code of PK. Which means, any error we report should only really have the error description and error message. The error name can be useful, if they want to report the error to the dev who can identify the exception.With
-v, extra information about the error should be shown, this should probably mean all the properties except thestackproperty and this applies recursively to the cause chain.Finally with
-vvwe should show the stack property as well.This should apply to exceptions reported on the
src/bin/polykey.tsandsrc/bin/polykey-agent.ts. In the case ofPolykeyAgent, this depends onpk agent start -vv, verbosity flags passed frompk agent startsubcommand.Additional context
Tasks
outputFormatter. Use the verbosity level. It should be a number.pk agent start-vmeans and-vvmeans.