-
Notifications
You must be signed in to change notification settings - Fork 167
Allow apps to control FDC3 for Web JS console logging #1495
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
Closed
Closed
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
19a3aad
Adding support for controlling debug logging in fdc3-agent-proxy and …
kriswest 19a0f8e
CHANGELOG
kriswest a44ec5d
Testing coverage
kriswest dca1f8a
Test coverage
kriswest 1ed86d8
Update website/docs/api/ref/GetAgent.md
kriswest 5dcffda
Merge branch 'fdc3-for-web-impl' into fdc3-for-web-impl-debug-logs
kriswest 0644c81
Merge branch 'fdc3-for-web-impl' into fdc3-for-web-impl-debug-logs
kriswest 3ab5d45
Setup Logger on first call to getAgent
kriswest File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
|
|
||
| //check if color is supported in (node) console; | ||
| let noColor = true; | ||
| //else only occurs in a browser and can't be tested in node | ||
| /* istanbul ignore if */ | ||
| if (typeof process !== 'undefined') { | ||
| const argv = process.argv || /* istanbul ignore next */ []; | ||
| const env = process.env || /* istanbul ignore next */ {}; | ||
| noColor = | ||
| (!!env.NO_COLOR || argv.includes('--no-color')) && | ||
| !( | ||
| !!env.FORCE_COLOR || | ||
| argv.includes('--color') || | ||
| process.platform === 'win32' /* istanbul ignore next */ || | ||
| ((process.stdout || {}).isTTY && env.TERM !== 'dumb') || | ||
| /* istanbul ignore next */ !!env.CI | ||
| ); | ||
| } | ||
|
|
||
| type ColorFn = (aString: string) => string; | ||
|
|
||
| export abstract class AbstractFDC3Logger { | ||
| private static enableDebug: boolean = false; | ||
| private static enableLog: boolean = true; | ||
|
|
||
| /** This should be overridden by sub-classes to change the prefix applied | ||
| * to log messages. */ | ||
| /* istanbul ignore next */ static get prefix(): string { | ||
| return ''; | ||
| } | ||
|
|
||
| public static enableDebugLogs(enable: boolean) { | ||
| this.enableDebug = enable; | ||
| } | ||
|
|
||
| public static enableLogs(enable: boolean) { | ||
| this.enableLog = enable; | ||
| } | ||
|
|
||
| protected static debugColor(value: string): string { | ||
| return noColor ? /* istanbul ignore next */ value : '\x1b[30m\x1b[2m' + value + '\x1b[22m\x1b[39m'; | ||
| } | ||
| protected static logColor(value: string): string { | ||
| return noColor ? /* istanbul ignore next */ value : '\x1b[32m\x1b[2m' + value + '\x1b[22m\x1b[39m'; | ||
| } | ||
| protected static warnColor(value: string): string { | ||
| return noColor ? /* istanbul ignore next */ value : '\x1b[33m' + value + '\x1b[39m'; | ||
| } | ||
| protected static errorColor(value: string): string { | ||
| return noColor ? /* istanbul ignore next */ value : '\x1b[31m' + value + '\x1b[39m'; | ||
| } | ||
|
|
||
| public static debug(...params: any[]) { | ||
| if (this.enableDebug) { | ||
| console.debug(...this.prefixAndColorize(this.prefix, params, this.debugColor)); | ||
| } | ||
| } | ||
|
|
||
| public static log(...params: any[]) { | ||
| if (this.enableLog) { | ||
| console.log(...this.prefixAndColorize(this.prefix, params, this.logColor)); | ||
| } | ||
| } | ||
|
|
||
| public static warn(...params: any[]) { | ||
| console.warn(...this.prefixAndColorize(this.prefix, params, this.warnColor)); | ||
| } | ||
|
|
||
| public static error(...params: any[]) { | ||
| console.error(...this.prefixAndColorize(this.prefix, params, this.errorColor)); | ||
| } | ||
|
|
||
| protected static prefixAndColorize = (prefix: string, params: any[], colorFn: ColorFn): string[] => { | ||
| const prefixed = [prefix, ...params]; | ||
| return prefixed.map(value => { | ||
| if (typeof value === 'string') { | ||
| //just color strings | ||
| return colorFn(value); | ||
| } else if (value && value.stack && value.message) { | ||
| //probably an error | ||
| return colorFn(value.stack); | ||
| } else { | ||
| //something else... lets hope it stringifies | ||
| return colorFn(JSON.stringify(value, null, 2)); | ||
| } | ||
| }); | ||
| }; | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { AbstractFDC3Logger } from './AbstractFDC3Logger'; | ||
|
|
||
| export class Logger extends AbstractFDC3Logger { | ||
| static override get prefix(): string { | ||
| return 'FDC3 DesktopAgentProxy: '; | ||
| } | ||
|
|
||
| private static enableHeartbeatLog: boolean = true; | ||
|
|
||
| public static enableHeartbeatLogs(enable: boolean) { | ||
| this.enableHeartbeatLog = enable; | ||
| } | ||
|
|
||
| public static heartbeatLog(...params: any[]) { | ||
| if (this.enableHeartbeatLog) { | ||
| console.debug(...this.prefixAndColorize(this.prefix, params, this.debugColor)); | ||
| } | ||
| } | ||
| } |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Should this be explicit level for more refined control versus just debug yes or no?
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.
Its does feel a little scrappy this way, but the issue is we've got two scopes to control logging in: the connection phase and the proxy itself + within the proxy there are two types of debug message that we need to keep separate for usability: logging API messages sent/received and logging heartbeat messages. Collectively, that made it a little harder to base purely on a log level.
I suppose one solution would be to move the message logging in the proxy to the log level but set the default level to warn...
The current proposed args are:
By moving message loggimg to the log level we could do: