-
Notifications
You must be signed in to change notification settings - Fork 327
[php-wasm-logger] Filter logs by severity in Logger and assign severity based on verbosity argument in CLIs #2436
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
071ffc2
Add quiet and verbose options in Xdebug Bridge
mho22 400999f
Refine README file
mho22 805dc23
Add tests
mho22 d5c3140
Lint
mho22 436e46d
Add verbosity in logger and xdebug-bridge
mho22 f48d972
Merge branch 'trunk' into add-verbose-option-in-xdebug-bridge
mho22 a8a6421
Add verbosity tests in Playground CLI
mho22 bcf694c
Merge branch 'trunk' into add-verbose-option-in-xdebug-bridge
mho22 61908a9
Add verbosity level instead of array of filters in Logger
mho22 1cdcec7
Adjust how quiet is promoted to verbosity
adamziel 00d7e5c
Adjust how debug is promoted to verbosity
adamziel 39c5d90
Support .logMessage() calls without an explicit severity
adamziel ace24c4
Merge branch 'trunk' into add-verbose-option-in-xdebug-bridge
mho22 33dcebb
Merge branch 'add-verbose-option-in-xdebug-bridge' of github.com:Word…
mho22 7350c02
Refactored verbosity and severity use in CLIs and Logger
mho22 a005ce6
correct merge conflicts and add review modifications
mho22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,87 @@ | ||
import { logger } from '../lib/logger'; | ||
import { clearMemoryLogs } from '../lib/log-handlers'; | ||
import { type Log, logger, LogVerbosity } from '../lib/logger'; | ||
import { clearMemoryLogs, type LogHandler } from '../lib/log-handlers'; | ||
|
||
describe('Logger', () => { | ||
beforeEach(async () => { | ||
let output: string[]; | ||
let handlers: LogHandler[]; | ||
|
||
function logToVariable(log: Log, arg?: string) { | ||
output.push(`${log.message}${arg ? arg : ''}`); | ||
} | ||
|
||
beforeAll(() => { | ||
// @ts-ignore | ||
handlers = logger.handlers; | ||
}); | ||
|
||
beforeEach(() => { | ||
output = []; | ||
// @ts-ignore | ||
logger.handlers = [...handlers, logToVariable]; | ||
|
||
clearMemoryLogs(); | ||
}); | ||
|
||
it('Log message should be added', () => { | ||
it('adds message in logs', () => { | ||
logger.warn('test'); | ||
const logs = logger.getLogs(); | ||
expect(logs.length).toBe(1); | ||
expect(logs[0]).toMatch( | ||
/\[\d{2}-[A-Za-z]{3,4}-\d{4} \d{2}:\d{2}:\d{2} UTC\] JavaScript Warn: test/ | ||
/\[\d{2}-[A-Za-z]{3,4}-\d{4} \d{2}:\d{2}:\d{2} UTC\] JavaScript warn: test/ | ||
); | ||
}); | ||
|
||
it('Log event should be dispatched', () => { | ||
it('dispatches log event', () => { | ||
const eventListener = vitest.fn(); | ||
logger.addEventListener('playground-log', eventListener); | ||
logger.warn('test'); | ||
expect(eventListener).toHaveBeenCalled(); | ||
}); | ||
|
||
it('outputs main logs by default', () => { | ||
logger.log('log'); | ||
logger.info('info'); | ||
logger.warn('warn'); | ||
logger.error('error'); | ||
logger.debug('debug'); | ||
const logs = logger.getLogs(); | ||
expect(logs.length).toBe(4); | ||
expect(output).toEqual(['log', 'info', 'warn', 'error']); | ||
}); | ||
|
||
it('outputs main logs when verbosity is set to normal', () => { | ||
logger.filterByVerbosity(LogVerbosity.Normal); | ||
logger.log('log'); | ||
logger.info('info'); | ||
logger.warn('warn'); | ||
logger.error('error'); | ||
logger.debug('debug'); | ||
const logs = logger.getLogs(); | ||
expect(logs.length).toBe(4); | ||
expect(output).toEqual(['log', 'info', 'warn', 'error']); | ||
}); | ||
|
||
it('outputs main and debug logs when verbosity is set to debug', () => { | ||
logger.filterByVerbosity(LogVerbosity.Debug); | ||
logger.log('log'); | ||
logger.info('info'); | ||
logger.warn('warn'); | ||
logger.error('error'); | ||
logger.debug('debug'); | ||
const logs = logger.getLogs(); | ||
expect(logs.length).toBe(5); | ||
expect(output).toEqual(['log', 'info', 'warn', 'error', 'debug']); | ||
}); | ||
mho22 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
it('does not output logs when verbosity is set to quiet', () => { | ||
logger.filterByVerbosity(LogVerbosity.Quiet); | ||
logger.log('log'); | ||
logger.info('info'); | ||
logger.warn('warn'); | ||
logger.error('error'); | ||
logger.debug('debug'); | ||
const logs = logger.getLogs(); | ||
expect(logs.length).toBe(0); | ||
expect(output).toEqual([]); | ||
}); | ||
}); |
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.
Uh oh!
There was an error while loading. Please reload this page.