Skip to content

Commit 2d177c5

Browse files
authored
Add verbose log level (#316)
1 parent 342e8a9 commit 2d177c5

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

packages/repluggable-core/src/API.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ export interface EntryPointInterceptor {
540540
interceptExtend?(innerExtend?: EntryPoint['extend']): EntryPoint['extend']
541541
}
542542

543-
export type LogSeverity = 'debug' | 'info' | 'event' | 'warning' | 'error' | 'critical'
543+
export type LogSeverity = 'verbose' | 'debug' | 'info' | 'event' | 'warning' | 'error' | 'critical'
544544
export type LogSpanFlag = 'begin' | 'end' //TODO:deprecated-kept-for-backward-compat
545545

546546
export interface HostLogger {
@@ -550,6 +550,7 @@ export interface HostLogger {
550550
}
551551

552552
export interface ShellLogger extends HostLogger {
553+
verbose(messageId: string, keyValuePairs?: Object): void
553554
debug(messageId: string, keyValuePairs?: Object): void
554555
info(messageId: string, keyValuePairs?: Object): void
555556
warning(messageId: string, keyValuePairs?: Object): void

packages/repluggable-core/src/appHost.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ miss: ${memoizedWithMissHit.miss}
390390
}
391391

392392
function addShells(entryPointsOrPackages: EntryPointOrPackage[]): Promise<void> {
393-
host.log.log('debug', `Adding ${entryPointsOrPackages.length} packages.`)
393+
host.log.log('verbose', `Adding ${entryPointsOrPackages.length} packages.`)
394394

395395
const entryPoints = _.flatten(entryPointsOrPackages)
396396
const existingEntryPoints = Object.values(addedShells).map(shell => shell.entryPoint)
@@ -790,7 +790,7 @@ miss: ${memoizedWithMissHit.miss}
790790
action: (shell: PrivateShell) => void,
791791
predicate?: (shell: PrivateShell) => boolean
792792
): void {
793-
host.log.log('debug', `--- ${phase} phase ---`)
793+
host.log.log('verbose', `--- ${phase} phase ---`)
794794

795795
try {
796796
shell.filter(f => !predicate || predicate(f)).forEach(f => invokeShell(f, action, phase))
@@ -799,11 +799,11 @@ miss: ${memoizedWithMissHit.miss}
799799
throw err
800800
}
801801

802-
host.log.log('debug', `--- End of ${phase} phase ---`)
802+
host.log.log('verbose', `--- End of ${phase} phase ---`)
803803
}
804804

805805
function invokeShell(shell: PrivateShell, action: (shell: PrivateShell) => void, phase: string): void {
806-
host.log.log('debug', `${phase} : ${shell.entryPoint.name}`)
806+
host.log.log('verbose', `${phase} : ${shell.entryPoint.name}`)
807807

808808
try {
809809
action(shell)
@@ -838,7 +838,7 @@ miss: ${memoizedWithMissHit.miss}
838838
extensionSlots.delete(ownKey)
839839
slotKeysByName.delete(slotKeyToName(ownKey))
840840

841-
host.log.log('debug', `-- Removed slot keys: ${slotKeyToName(ownKey)} --`)
841+
host.log.log('verbose', `-- Removed slot keys: ${slotKeyToName(ownKey)} --`)
842842
}
843843

844844
function findDependantShells(entryShell: PrivateShell): PrivateShell[] {
@@ -897,12 +897,12 @@ miss: ${memoizedWithMissHit.miss}
897897

898898
slotKeysToDiscard.forEach(discardSlotKey)
899899

900-
host.log.log('debug', `Done uninstalling ${detachedShellsNames}`)
900+
host.log.log('verbose', `Done uninstalling ${detachedShellsNames}`)
901901
}
902902

903903
function executeUninstallShells(names: string[]): void {
904904
batchDeclarationsChangedCallbacks(() => {
905-
host.log.log('debug', `-- Uninstalling ${names} --`)
905+
host.log.log('verbose', `-- Uninstalling ${names} --`)
906906

907907
const shellsCandidatesToBeDetached = _(names)
908908
.map(name => addedShells.get(name))
@@ -1073,7 +1073,7 @@ miss: ${memoizedWithMissHit.miss}
10731073
},
10741074

10751075
contributeAPI<TAPI>(key: SlotKey<TAPI>, factory: () => TAPI, apiOptions?: ContributeAPIOptions<TAPI>): TAPI {
1076-
host.log.log('debug', `Contributing API ${slotKeyToName(key)}.`)
1076+
host.log.log('verbose', `Contributing API ${slotKeyToName(key)}.`)
10771077

10781078
if (!_.includes(_.invoke(entryPoint, 'declareAPIs') || [], key)) {
10791079
throw new Error(

packages/repluggable-core/src/loggers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ export function createShellLogger(host: AppHost, entryPoint: EntryPoint): ShellL
3636
log(severity: LogSeverity, id: string, keyValuePairs?: Object): void {
3737
host.log.log(severity, id, undefined, withEntryPointTags(keyValuePairs))
3838
},
39+
verbose(messageId: string, keyValuePairs?: Object): void {
40+
host.log.log('verbose', messageId, undefined, withEntryPointTags(keyValuePairs))
41+
},
3942
debug(messageId: string, keyValuePairs?: Object): void {
4043
host.log.log('debug', messageId, undefined, withEntryPointTags(keyValuePairs))
4144
},

packages/repluggable-core/test/loggers.spec.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@ describe('ShellLogger', () => {
4242
shellLogger.info('M2')
4343
shellLogger.warning('M3')
4444
shellLogger.error('M4')
45+
shellLogger.verbose('M5')
4546

46-
expect(hostLogger.log).toHaveBeenCalledTimes(4)
47+
expect(hostLogger.log).toHaveBeenCalledTimes(5)
4748
expect(hostLogger.log).toHaveBeenNthCalledWith(1, 'debug', 'M1', undefined, { $ep: 'ep-1' })
4849
expect(hostLogger.log).toHaveBeenNthCalledWith(2, 'info', 'M2', undefined, { $ep: 'ep-1' })
4950
expect(hostLogger.log).toHaveBeenNthCalledWith(3, 'warning', 'M3', undefined, { $ep: 'ep-1' })
5051
expect(hostLogger.log).toHaveBeenNthCalledWith(4, 'error', 'M4', undefined, { $ep: 'ep-1' })
52+
expect(hostLogger.log).toHaveBeenNthCalledWith(5, 'verbose', 'M5', undefined, { $ep: 'ep-1' })
5153
})
5254

5355
it('should log simple message with key-value pairs', () => {
@@ -57,12 +59,14 @@ describe('ShellLogger', () => {
5759
shellLogger.info('M2', { k2: 'v2' })
5860
shellLogger.warning('M3', { k3: 'v3' })
5961
shellLogger.error('M4', undefined, { k4: 'v4' })
62+
shellLogger.verbose('M5', { k5: 'v5' })
6063

61-
expect(hostLogger.log).toHaveBeenCalledTimes(4)
64+
expect(hostLogger.log).toHaveBeenCalledTimes(5)
6265
expect(hostLogger.log).toHaveBeenNthCalledWith(1, 'debug', 'M1', undefined, { $ep: 'ep-1', k1: 'v1' })
6366
expect(hostLogger.log).toHaveBeenNthCalledWith(2, 'info', 'M2', undefined, { $ep: 'ep-1', k2: 'v2' })
6467
expect(hostLogger.log).toHaveBeenNthCalledWith(3, 'warning', 'M3', undefined, { $ep: 'ep-1', k3: 'v3' })
6568
expect(hostLogger.log).toHaveBeenNthCalledWith(4, 'error', 'M4', undefined, { $ep: 'ep-1', k4: 'v4' })
69+
expect(hostLogger.log).toHaveBeenNthCalledWith(5, 'verbose', 'M5', undefined, { $ep: 'ep-1', k5: 'v5' })
6670
})
6771

6872
it('should include entry point tags in key-value pairs', () => {
@@ -72,12 +76,14 @@ describe('ShellLogger', () => {
7276
shellLogger.info('M2', { k2: 'v2' })
7377
shellLogger.warning('M3', { k3: 'v3' })
7478
shellLogger.error('M4', undefined, { k4: 'v4' })
79+
shellLogger.verbose('M5', { k5: 'v5' })
7580

76-
expect(hostLogger.log).toHaveBeenCalledTimes(4)
81+
expect(hostLogger.log).toHaveBeenCalledTimes(5)
7782
expect(hostLogger.log).toHaveBeenNthCalledWith(1, 'debug', 'M1', undefined, { $ep: 'ep-1', k1: 'v1', t1: 'T1', t2: 'T2' })
7883
expect(hostLogger.log).toHaveBeenNthCalledWith(2, 'info', 'M2', undefined, { $ep: 'ep-1', k2: 'v2', t1: 'T1', t2: 'T2' })
7984
expect(hostLogger.log).toHaveBeenNthCalledWith(3, 'warning', 'M3', undefined, { $ep: 'ep-1', k3: 'v3', t1: 'T1', t2: 'T2' })
8085
expect(hostLogger.log).toHaveBeenNthCalledWith(4, 'error', 'M4', undefined, { $ep: 'ep-1', k4: 'v4', t1: 'T1', t2: 'T2' })
86+
expect(hostLogger.log).toHaveBeenNthCalledWith(5, 'verbose', 'M5', undefined, { $ep: 'ep-1', k5: 'v5', t1: 'T1', t2: 'T2' })
8187
})
8288

8389
it('should begin span', () => {

0 commit comments

Comments
 (0)