Skip to content
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

log component name #683

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/services/helpers/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ export const getLogger = (params: LoggerParams): PubLogger => {
}
toLog.push(params.appName)
}
if (params.component) {
if (disabledComponents.includes(params.component)) {
return
}
toLog.push(params.component)
}
if (params.userId) {
toLog.push(params.userId)
}
Expand All @@ -87,7 +93,13 @@ export const getLogger = (params: LoggerParams): PubLogger => {
writers.forEach(w => w(final))
}
}
const disabledApps: string[] = []
export const disableLoggers = (appNamesToDisable: string[]) => {
let disabledApps: string[] = []
let disabledComponents: string[] = []
export const resetDisabledLoggers = () => {
disabledApps = []
disabledComponents = []
}
export const disableLoggers = (appNamesToDisable: string[], componentsToDisable: string[]) => {
disabledApps.push(...appNamesToDisable)
disabledComponents.push(...componentsToDisable)
}
2 changes: 1 addition & 1 deletion src/tests/spamExternalPayments.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Describe, expect, expectThrowsAsync, runSanityCheck, safelySetUserBalan
export const ignore = false

export default async (T: TestBase) => {
disableLoggers(["EventsLogManager", "htlcTracker", "watchdog"])
disableLoggers([], ["EventsLogManager", "htlcTracker", "watchdog"])
await safelySetUserBalance(T, T.user1, 2000)
await testSpamExternalPayment(T)
await runSanityCheck(T)
Expand Down
2 changes: 1 addition & 1 deletion src/tests/spamMixedPayments.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as Types from '../../proto/autogenerated/ts/types.js'
export const ignore = false

export default async (T: TestBase) => {
disableLoggers(["EventsLogManager", "htlcTracker", "watchdog"])
disableLoggers([], ["EventsLogManager", "htlcTracker", "watchdog"])
await safelySetUserBalance(T, T.user1, 2000)
await testSpamExternalPayment(T)
await runSanityCheck(T)
Expand Down
2 changes: 2 additions & 0 deletions src/tests/testBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import chaiString from 'chai-string'
import { defaultInvoiceExpiry } from '../services/storage/paymentStorage.js'
import SanityChecker from '../services/main/sanityChecker.js'
import LND from '../services/lnd/lnd.js'
import { resetDisabledLoggers } from '../services/helpers/logger.js'
chai.use(chaiString)
export const expect = chai.expect
export type Describe = (message: string, failure?: boolean) => void
Expand Down Expand Up @@ -69,6 +70,7 @@ export const teardown = async (T: TestBase) => {
T.externalAccessToMainLnd.Stop()
T.externalAccessToOtherLnd.Stop()
T.externalAccessToThirdLnd.Stop()
resetDisabledLoggers()
console.log("teardown")
}

Expand Down
Loading