This commit is contained in:
einhornimmond 2025-06-17 15:43:06 +02:00
parent 6cf82ad87c
commit 6258774530
22 changed files with 142 additions and 210 deletions

View File

@ -12,7 +12,9 @@ import { clearLogs, getLogger, printLogs } from 'config-schema/test/testSetup'
import { validateCommunities } from './validateCommunities'
const logger = getLogger(`${LOG4JS_FEDERATION_CATEGORY_NAME}.validateCommunities`)
const federationClientLogger = getLogger(`${LOG4JS_FEDERATION_CLIENT1_0_CATEGORY_NAME}.FederationClient`)
const federationClientLogger = getLogger(
`${LOG4JS_FEDERATION_CLIENT1_0_CATEGORY_NAME}.FederationClient`,
)
let con: DataSource
let testEnv: {
@ -88,8 +90,9 @@ describe('validate Communities', () => {
})
it('logs requestGetPublicKey missing response data ', () => {
expect(federationClientLogger.warn).toBeCalledWith(
'getPublicKey without response data from endpoint', 'http//localhost:5001/api/1_0/'
)
'getPublicKey without response data from endpoint',
'http//localhost:5001/api/1_0/',
)
})
})
@ -160,7 +163,10 @@ describe('validate Communities', () => {
expect(logger.debug).toBeCalledWith(`found 1 dbCommunities`)
})
it('logs requestGetPublicKey for community api 1_0 ', () => {
expect(federationClientLogger.debug).toBeCalledWith('getPublicKey from endpoint', 'http//localhost:5001/api/1_0/')
expect(federationClientLogger.debug).toBeCalledWith(
'getPublicKey from endpoint',
'http//localhost:5001/api/1_0/',
)
})
it('logs not matching publicKeys', () => {
expect(logger.debug).toBeCalledWith(
@ -279,7 +285,10 @@ describe('validate Communities', () => {
)
})
it('logs requestGetPublicKey for community api 1_1 ', () => {
expect(federationClientLogger.debug).toBeCalledWith('getPublicKey from endpoint', 'http//localhost:5001/api/1_1/')
expect(federationClientLogger.debug).toBeCalledWith(
'getPublicKey from endpoint',
'http//localhost:5001/api/1_1/',
)
})
})
describe('with three Communities of api 1_0, 1_1 and 2_0', () => {
@ -328,10 +337,17 @@ describe('validate Communities', () => {
)
})
it('logs requestGetPublicKey for community api 1_1 ', () => {
expect(federationClientLogger.debug).toBeCalledWith('getPublicKey from endpoint', 'http//localhost:5001/api/1_1/')
expect(federationClientLogger.debug).toBeCalledWith(
'getPublicKey from endpoint',
'http//localhost:5001/api/1_1/',
)
})
it('logs unsupported api for community with api 2_0 ', () => {
expect(logger.debug).toBeCalledWith('dbCom with unsupported apiVersion', dbCom.endPoint, '2_0')
expect(logger.debug).toBeCalledWith(
'dbCom with unsupported apiVersion',
dbCom.endPoint,
'2_0',
)
})
})
})

View File

@ -6,6 +6,7 @@ import { DataSource } from 'typeorm'
import { cleanDB, resetToken, testEnvironment } from '@test/helpers'
import { LOG4JS_BASE_CATEGORY_NAME } from '@/config/const'
import { EventType } from '@/event/Events'
import { userFactory } from '@/seeds/factory/user'
import {
@ -17,13 +18,10 @@ import {
import { listContributionLinks } from '@/seeds/graphql/queries'
import { bibiBloxberg } from '@/seeds/users/bibi-bloxberg'
import { peterLustig } from '@/seeds/users/peter-lustig'
import { clearLogs, getLogger, printLogs } from 'config-schema/test/testSetup'
import { LOG4JS_BASE_CATEGORY_NAME } from '@/config/const'
import { LOG4JS_RESOLVER_CATEGORY_NAME } from '.'
import { getLogger } from 'config-schema/test/testSetup'
jest.mock('@/password/EncryptorUtils')
const logger = getLogger(`${LOG4JS_RESOLVER_CATEGORY_NAME}.ContributionLinkResolver`)
const logErrorLogger = getLogger(`${LOG4JS_BASE_CATEGORY_NAME}.server.LogError`)
let mutate: ApolloServerTestClient['mutate']

View File

@ -7,8 +7,10 @@ import { ContributionStatus } from '@enum/ContributionStatus'
import { cleanDB, resetToken, testEnvironment } from '@test/helpers'
import { i18n as localization } from '@test/testSetup'
import { LOG4JS_BASE_CATEGORY_NAME } from '@/config/const'
import { sendAddedContributionMessageEmail } from '@/emails/sendEmailVariants'
import { EventType } from '@/event/Events'
import { LOG4JS_INTERACTION_CATEGORY_NAME } from '@/interactions'
import { userFactory } from '@/seeds/factory/user'
import {
adminCreateContributionMessage,
@ -22,12 +24,12 @@ import { bobBaumeister } from '@/seeds/users/bob-baumeister'
import { peterLustig } from '@/seeds/users/peter-lustig'
import { clearLogs, getLogger, printLogs } from 'config-schema/test/testSetup'
import { LOG4JS_RESOLVER_CATEGORY_NAME } from '.'
import { LOG4JS_BASE_CATEGORY_NAME } from '@/config/const'
import { LOG4JS_INTERACTION_CATEGORY_NAME } from '@/interactions'
const logger = getLogger(`${LOG4JS_RESOLVER_CATEGORY_NAME}.ContributionMessageResolver`)
const logErrorLogger = getLogger(`${LOG4JS_BASE_CATEGORY_NAME}.server.LogError`)
const interactionLogger = getLogger(`${LOG4JS_INTERACTION_CATEGORY_NAME}.updateUnconfirmedContribution`)
const interactionLogger = getLogger(
`${LOG4JS_INTERACTION_CATEGORY_NAME}.updateUnconfirmedContribution`,
)
jest.mock('@/password/EncryptorUtils')
jest.mock('@/emails/sendEmailVariants', () => {
@ -156,7 +158,9 @@ describe('ContributionMessageResolver', () => {
message: 'Test',
},
})
expect(interactionLogger.debug).toBeCalledWith('use UnconfirmedContributionUserAddMessageRole')
expect(interactionLogger.debug).toBeCalledWith(
'use UnconfirmedContributionUserAddMessageRole',
)
expect(mutationResult).toEqual(
expect.objectContaining({
data: {
@ -350,7 +354,9 @@ describe('ContributionMessageResolver', () => {
},
})
expect(interactionLogger.debug).toBeCalledWith('use UnconfirmedContributionAdminAddMessageRole')
expect(interactionLogger.debug).toBeCalledWith(
'use UnconfirmedContributionAdminAddMessageRole',
)
expect(mutationResult).toEqual(
expect.objectContaining({
@ -380,7 +386,9 @@ describe('ContributionMessageResolver', () => {
message: 'Test',
},
})
expect(interactionLogger.debug).toBeCalledWith('use UnconfirmedContributionAdminAddMessageRole')
expect(interactionLogger.debug).toBeCalledWith(
'use UnconfirmedContributionAdminAddMessageRole',
)
expect(mutationResult).toEqual(
expect.objectContaining({

View File

@ -16,6 +16,7 @@ import {
} from '@test/helpers'
import { i18n as localization } from '@test/testSetup'
import { LOG4JS_BASE_CATEGORY_NAME } from '@/config/const'
import {
sendContributionConfirmedEmail,
sendContributionDeletedEmail,
@ -50,14 +51,13 @@ import { peterLustig } from '@/seeds/users/peter-lustig'
import { raeuberHotzenplotz } from '@/seeds/users/raeuber-hotzenplotz'
import { stephenHawking } from '@/seeds/users/stephen-hawking'
import { getFirstDayOfPreviousNMonth } from '@/util/utilities'
import { getLogger, clearLogs, printLogs } from 'config-schema/test/testSetup'
import { clearLogs, getLogger, printLogs } from 'config-schema/test/testSetup'
import { getLogger as originalGetLogger } from 'log4js'
import { LOG4JS_BASE_CATEGORY_NAME } from '@/config/const'
jest.mock('@/emails/sendEmailVariants')
jest.mock('@/password/EncryptorUtils')
const logger = getLogger(`${LOG4JS_BASE_CATEGORY_NAME}.server.LogError` )
const logger = getLogger(`${LOG4JS_BASE_CATEGORY_NAME}.server.LogError`)
let mutate: ApolloServerTestClient['mutate']
let query: ApolloServerTestClient['query']

View File

@ -34,12 +34,10 @@ import { bibiBloxberg } from '@/seeds/users/bibi-bloxberg'
import { peterLustig } from '@/seeds/users/peter-lustig'
import { TRANSACTIONS_LOCK } from '@/util/TRANSACTIONS_LOCK'
import { getLogger } from 'config-schema/test/testSetup'
import { LOG4JS_BASE_CATEGORY_NAME } from '@/config/const'
import { LOG4JS_RESOLVER_CATEGORY_NAME } from '.'
import { getLogger } from 'config-schema/test/testSetup'
import { transactionLinkCode } from './TransactionLinkResolver'
const logger = getLogger(`${LOG4JS_RESOLVER_CATEGORY_NAME}.TransactionLinkResolver`)
const logErrorLogger = getLogger(`${LOG4JS_BASE_CATEGORY_NAME}.server.LogError`)
jest.mock('@/password/EncryptorUtils')
@ -322,7 +320,10 @@ describe('TransactionLinkResolver', () => {
})
it('logs the error "Contribution link is not valid yet"', () => {
expect(logErrorLogger.error).toBeCalledWith('Contribution link is not valid yet', validFrom)
expect(logErrorLogger.error).toBeCalledWith(
'Contribution link is not valid yet',
validFrom,
)
expect(logErrorLogger.error).toBeCalledWith(
'Creation from contribution link was not successful',
new Error('Contribution link is not valid yet'),
@ -361,7 +362,10 @@ describe('TransactionLinkResolver', () => {
})
it('logs the error "Contribution link has unknown cycle"', () => {
expect(logErrorLogger.error).toBeCalledWith('Contribution link has unknown cycle', 'INVALID')
expect(logErrorLogger.error).toBeCalledWith(
'Contribution link has unknown cycle',
'INVALID',
)
expect(logErrorLogger.error).toBeCalledWith(
'Creation from contribution link was not successful',
new Error('Contribution link has unknown cycle'),
@ -400,7 +404,10 @@ describe('TransactionLinkResolver', () => {
})
it('logs the error "Contribution link is no longer valid"', () => {
expect(logErrorLogger.error).toBeCalledWith('Contribution link is no longer valid', validTo)
expect(logErrorLogger.error).toBeCalledWith(
'Contribution link is no longer valid',
validTo,
)
expect(logErrorLogger.error).toBeCalledWith(
'Creation from contribution link was not successful',
new Error('Contribution link is no longer valid'),

View File

@ -14,6 +14,7 @@ import { v4 as uuidv4 } from 'uuid'
import { cleanDB, testEnvironment } from '@test/helpers'
import { CONFIG } from '@/config'
import { LOG4JS_BASE_CATEGORY_NAME } from '@/config/const'
import { EventType } from '@/event/Events'
import { SendCoinsClient } from '@/federation/client/1_0/SendCoinsClient'
import { SendCoinsArgs } from '@/federation/client/1_0/model/SendCoinsArgs'
@ -32,7 +33,6 @@ import { garrickOllivander } from '@/seeds/users/garrick-ollivander'
import { peterLustig } from '@/seeds/users/peter-lustig'
import { stephenHawking } from '@/seeds/users/stephen-hawking'
import { getLogger } from 'config-schema/test/testSetup'
import { LOG4JS_BASE_CATEGORY_NAME } from '@/config/const'
jest.mock('@/password/EncryptorUtils')

View File

@ -67,10 +67,10 @@ import { stephenHawking } from '@/seeds/users/stephen-hawking'
import { printTimeDuration } from '@/util/time'
import { objectValuesToArray } from '@/util/utilities'
import { LOG4JS_BASE_CATEGORY_NAME } from '@/config/const'
import { clearLogs, getLogger, printLogs } from 'config-schema/test/testSetup'
import { LOG4JS_RESOLVER_CATEGORY_NAME } from '.'
import { Location2Point } from './util/Location2Point'
import { LOG4JS_BASE_CATEGORY_NAME } from '@/config/const'
jest.mock('@/apis/humhub/HumHubClient')
jest.mock('@/password/EncryptorUtils')
@ -709,7 +709,9 @@ describe('UserResolver', () => {
})
it('logs the error found', () => {
expect(logger.warn).toBeCalledWith(`findUserByEmail failed, user with email=${variables.email} not found`)
expect(logger.warn).toBeCalledWith(
`findUserByEmail failed, user with email=${variables.email} not found`,
)
})
})
@ -1114,7 +1116,9 @@ describe('UserResolver', () => {
})
it('logs warning before throwing error', () => {
expect(logger.warn).toBeCalledWith('email already sent 0 minutes ago, min wait time: 10 minutes')
expect(logger.warn).toBeCalledWith(
'email already sent 0 minutes ago, min wait time: 10 minutes',
)
})
})
})
@ -1762,7 +1766,10 @@ describe('UserResolver', () => {
})
it('logs the error thrown', () => {
expect(logErrorLogger.error).toBeCalledWith('Could not find user with given ID', admin.id + 1)
expect(logErrorLogger.error).toBeCalledWith(
'Could not find user with given ID',
admin.id + 1,
)
})
})
@ -1878,7 +1885,9 @@ describe('UserResolver', () => {
)
})
it('logs the error thrown', () => {
expect(logErrorLogger.error).toBeCalledWith('Administrator can not change his own role')
expect(logErrorLogger.error).toBeCalledWith(
'Administrator can not change his own role',
)
})
})
@ -1923,7 +1932,10 @@ describe('UserResolver', () => {
})
it('logs the error thrown', () => {
expect(logErrorLogger.error).toBeCalledWith('User already has role=', RoleNames.ADMIN)
expect(logErrorLogger.error).toBeCalledWith(
'User already has role=',
RoleNames.ADMIN,
)
})
})
@ -1947,7 +1959,10 @@ describe('UserResolver', () => {
})
it('logs the error thrown', () => {
expect(logErrorLogger.error).toBeCalledWith('User already has role=', RoleNames.MODERATOR)
expect(logErrorLogger.error).toBeCalledWith(
'User already has role=',
RoleNames.MODERATOR,
)
})
})
@ -2041,7 +2056,10 @@ describe('UserResolver', () => {
})
it('logs the error thrown', () => {
expect(logErrorLogger.error).toBeCalledWith('Could not find user with given ID', admin.id + 1)
expect(logErrorLogger.error).toBeCalledWith(
'Could not find user with given ID',
admin.id + 1,
)
})
})
@ -2111,7 +2129,10 @@ describe('UserResolver', () => {
})
it('logs the error thrown', () => {
expect(logErrorLogger.error).toBeCalledWith('Could not find user with given ID', user.id)
expect(logErrorLogger.error).toBeCalledWith(
'Could not find user with given ID',
user.id,
)
})
})
})
@ -2187,7 +2208,9 @@ describe('UserResolver', () => {
})
it('logs the error thrown', () => {
expect(logger.warn).toBeCalledWith('findUserByEmail failed, user with email=invalid not found')
expect(logger.warn).toBeCalledWith(
'findUserByEmail failed, user with email=invalid not found',
)
})
})
@ -2331,7 +2354,10 @@ describe('UserResolver', () => {
})
it('logs the error thrown', () => {
expect(logErrorLogger.error).toBeCalledWith('Could not find user with given ID', admin.id + 1)
expect(logErrorLogger.error).toBeCalledWith(
'Could not find user with given ID',
admin.id + 1,
)
})
})

View File

@ -525,8 +525,13 @@ export class UserResolver {
return true
}
if (!canEmailResend(user.emailContact.updatedAt || user.emailContact.createdAt)) {
const diff = durationInMinutesFromDates(user.emailContact.updatedAt || user.emailContact.createdAt, new Date())
logger.warn(`email already sent ${printTimeDuration(diff)} ago, min wait time: ${printTimeDuration(CONFIG.EMAIL_CODE_REQUEST_TIME)}`)
const diff = durationInMinutesFromDates(
user.emailContact.updatedAt || user.emailContact.createdAt,
new Date(),
)
logger.warn(
`email already sent ${printTimeDuration(diff)} ago, min wait time: ${printTimeDuration(CONFIG.EMAIL_CODE_REQUEST_TIME)}`,
)
throw new LogError(
`Email already sent less than ${printTimeDuration(CONFIG.EMAIL_CODE_REQUEST_TIME)} ago`,
)
@ -751,7 +756,7 @@ export class UserResolver {
'Please enter a valid password with at least 8 characters, upper and lower case letters, at least one number and one special character!',
)
}
if (!(await verifyPassword(user, password))) {
logger.debug('old password is invalid')
throw new LogError(`Old password is invalid`)
@ -1095,13 +1100,13 @@ export class UserResolver {
): Promise<boolean> {
const logger = createLogger()
email = email.trim().toLowerCase()
const user = await findUserByEmail(email)
const user = await findUserByEmail(email)
logger.addContext('user', user.id)
logger.info('sendActivationEmail...')
if (user.deletedAt || user.emailContact.deletedAt) {
logger.warn('call for activation of deleted user')
throw new Error('User with given email contact is deleted')
}
}
user.emailContact.emailResendCount++
await user.emailContact.save()
@ -1165,7 +1170,7 @@ export async function findUserByEmail(email: string): Promise<DbUser> {
relations: { userRoles: true, emailContact: true },
})
return dbUser
} catch(e) {
} catch (e) {
const logger = createLogger()
if (e instanceof EntityNotFoundError) {
// TODO: discuss if it is ok to print email in log for this case

View File

@ -1,131 +0,0 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"vcs": { "enabled": false, "clientKind": "git", "useIgnoreFile": false },
"files": {
"ignoreUnknown": false,
"ignore": ["build", "node_modules", "testSetup.ts"],
"include": ["./src/**/*.js", "./src/**/*.ts"]
},
"formatter": {
"enabled": true,
"useEditorconfig": true,
"formatWithErrors": false,
"indentStyle": "space",
"indentWidth": 2,
"lineEnding": "lf",
"lineWidth": 100,
"attributePosition": "auto",
"bracketSpacing": true
},
"organizeImports": { "enabled": true },
"linter": {
"enabled": true,
"rules": {
"recommended": false,
"complexity": {
"noExtraBooleanCast": "error",
"noMultipleSpacesInRegularExpressionLiterals": "error",
"noUselessCatch": "error",
"noUselessConstructor": "error",
"noUselessLoneBlockStatements": "error",
"noUselessRename": "error",
"noUselessTernary": "error",
"noUselessUndefinedInitialization": "error",
"noVoid": "error",
"noWith": "error",
"useLiteralKeys": "error",
"useRegexLiterals": "error"
},
"correctness": {
"noConstAssign": "error",
"noConstantCondition": "error",
"noEmptyCharacterClassInRegex": "error",
"noEmptyPattern": "error",
"noGlobalObjectCalls": "error",
"noInnerDeclarations": "error",
"noInvalidConstructorSuper": "error",
"noInvalidUseBeforeDeclaration": "error",
"noNewSymbol": "error",
"noNodejsModules": "off",
"noNonoctalDecimalEscape": "error",
"noPrecisionLoss": "error",
"noSelfAssign": "error",
"noSetterReturn": "error",
"noSwitchDeclarations": "error",
"noUndeclaredVariables": "error",
"noUnreachable": "error",
"noUnreachableSuper": "error",
"noUnsafeFinally": "error",
"noUnsafeOptionalChaining": "error",
"noUnusedLabels": "error",
"noUnusedVariables": "error",
"useArrayLiterals": "error",
"useIsNan": "error",
"useValidForDirection": "error",
"useYield": "error"
},
"security": { "noGlobalEval": "error" },
"style": {
"noCommaOperator": "error",
"noDefaultExport": "error",
"noVar": "warn",
"noYodaExpression": "error",
"useBlockStatements": "error",
"useConsistentBuiltinInstantiation": "error",
"useConst": "error",
"useSingleVarDeclarator": "error"
},
"suspicious": {
"noAsyncPromiseExecutor": "error",
"noCatchAssign": "error",
"noClassAssign": "error",
"noCompareNegZero": "error",
"noConsole": "error",
"noControlCharactersInRegex": "error",
"noDebugger": "error",
"noDoubleEquals": "error",
"noDuplicateCase": "error",
"noDuplicateClassMembers": "error",
"noDuplicateObjectKeys": "error",
"noDuplicateParameters": "error",
"noEmptyBlockStatements": "error",
"noFallthroughSwitchClause": "error",
"noFunctionAssign": "error",
"noGlobalAssign": "error",
"noImportAssign": "error",
"noMisleadingCharacterClass": "error",
"noPrototypeBuiltins": "error",
"noRedeclare": "error",
"noSelfCompare": "error",
"noShadowRestrictedNames": "error",
"noSparseArray": "error",
"noUnsafeNegation": "error",
"useDefaultSwitchClauseLast": "error",
"useGetterReturn": "error",
"useValidTypeof": "error"
}
},
"ignore": ["**/node_modules", "**/*.min.js", "**/build", "**/coverage"]
},
"javascript": {
"formatter": {
"jsxQuoteStyle": "single",
"quoteProperties": "asNeeded",
"trailingCommas": "all",
"semicolons": "asNeeded",
"arrowParentheses": "always",
"bracketSameLine": false,
"quoteStyle": "single",
"attributePosition": "auto",
"bracketSpacing": true
},
"globals": ["document", "navigator", "window"]
},
"overrides": [
{
"include": ["*.ts", "*.tsx"],
"linter": { "rules": { "complexity": { "noVoid": "error" } } }
},
{ "include": ["*.test.ts"], "linter": { "rules": {} } }
]
}

View File

@ -127,7 +127,9 @@ export const LOG4JS_CONFIG = Joi.string()
export const LOG4JS_CONFIG_PLACEHOLDER = Joi.string()
.pattern(/^[a-zA-Z0-9-_]+(%v)?\.json$/)
.message('LOG4JS_CONFIG_PLACEHOLDER must be a valid filename ending with .json can contain %v as API Version placeholder before ending')
.message(
'LOG4JS_CONFIG_PLACEHOLDER must be a valid filename ending with .json can contain %v as API Version placeholder before ending',
)
.description('config file name for log4js config file')
.default('log4js-config.json')
.required()

View File

@ -1 +1 @@
export const DECAY_START_TIME = new Date('2021-05-13T17:46:31Z')
export const DECAY_START_TIME = new Date('2021-05-13T17:46:31Z')

View File

@ -1,6 +1,6 @@
import { createColoredContextLayout } from './coloredContext'
import { levels, LoggingEvent } from 'log4js'
import { LoggingEvent, levels } from 'log4js'
import colors from 'yoctocolors-cjs'
import { createColoredContextLayout } from './coloredContext'
let defaultLogEvent: LoggingEvent
let colorFn: (input: string) => string
@ -76,13 +76,13 @@ describe('createColoredContextLayout', () => {
})
it('format withStack: error, withLine: true, withFile: warn', () => {
const coloredString = colorFn(`[${startTimeString}] [${levels.INFO}] config:1 -`)
expect(createColoredContextLayout({
withStack: 'error',
withFile: 'warn',
withLine: true
})(defaultLogEvent)).toBe(
`${coloredString} user=1 message`,
)
expect(
createColoredContextLayout({
withStack: 'error',
withFile: 'warn',
withLine: true,
})(defaultLogEvent),
).toBe(`${coloredString} user=1 message`)
})
})
@ -123,13 +123,13 @@ describe('createColoredContextLayout', () => {
})
it('format withStack: error, withLine: true, withFile: warn', () => {
const coloredString = colorFn(`[${startTimeString}] [${levels.ERROR}] config -`)
expect(createColoredContextLayout({
withStack: 'error',
withFile: 'warn',
withLine: true
})(defaultLogEvent)).toBe(
`${coloredString} user=1 message \nstack`,
)
expect(
createColoredContextLayout({
withStack: 'error',
withFile: 'warn',
withLine: true,
})(defaultLogEvent),
).toBe(`${coloredString} user=1 message \nstack`)
})
})
})

View File

@ -1,6 +1,6 @@
import { Level, LoggingEvent } from 'log4js'
import colors from 'yoctocolors-cjs'
import { LogLevel, ColoredContextLayoutConfig } from './types'
import { ColoredContextLayoutConfig, LogLevel } from './types'
function colorize(str: string, level: Level): string {
switch (level.colour) {
@ -68,7 +68,10 @@ enum DetailKind {
File = 'file',
Line = 'line',
}
function resolveDetailKind(logEvent: LoggingEvent, config: ColoredContextLayoutConfig): DetailKind | undefined {
function resolveDetailKind(
logEvent: LoggingEvent,
config: ColoredContextLayoutConfig,
): DetailKind | undefined {
if (logEvent.callStack && isEnabledByLogLevel(logEvent.level, config.withStack)) {
return DetailKind.Callstack
}
@ -99,7 +102,7 @@ export function createColoredContextLayout(config: ColoredContextLayoutConfig) {
result.push(composeContextString(logEvent.context))
}
result.push(composeDataString(logEvent.data))
if (detailKind === DetailKind.File) {
result.push(`\n at ${logEvent.fileName}:${logEvent.lineNumber}`)
}

View File

@ -2,9 +2,7 @@ import { createLog4jsConfig, defaultCategory } from '.'
describe('createLog4jsConfig', () => {
it('should create a log4js config', () => {
const config = createLog4jsConfig([
defaultCategory('test', 'debug')
])
const config = createLog4jsConfig([defaultCategory('test', 'debug')])
expect(config).toBeDefined()
expect(config.appenders).toBeDefined()
expect(config.categories).toBeDefined()
@ -21,8 +19,8 @@ describe('createLog4jsConfig', () => {
layout: {
type: 'coloredContext',
withStack: 'error',
withLine: true
}
withLine: true,
},
})
})
})
})

View File

@ -1,5 +1,5 @@
import { LogLevel } from './LogLevel'
import { ColoredContextLayoutConfig } from './ColoredContextLayoutConfig'
import { LogLevel } from './LogLevel'
/**
* Configuration for a log4js category.

View File

@ -4,4 +4,4 @@ export type ColoredContextLayoutConfig = {
withStack?: LogLevel | boolean
withFile?: LogLevel | boolean
withLine?: LogLevel | boolean
}
}

View File

@ -1,5 +1,5 @@
import { LogLevel } from './LogLevel'
import { ColoredContextLayoutConfig } from './ColoredContextLayoutConfig'
import { LogLevel } from './LogLevel'
/**
* use default dateFile Template for custom file appenders
*

View File

@ -2,8 +2,8 @@ import { CONFIG } from '@/config'
import { LOG4JS_BASE_CATEGORY_NAME } from '@/config/const'
import { createServer } from '@/server/createServer'
import { createTestClient } from 'apollo-server-testing'
import { getLogger } from 'log4js'
import { Community as DbCommunity } from 'database'
import { getLogger } from 'log4js'
import { DataSource } from 'typeorm'
let query: any

View File

@ -2,8 +2,8 @@ import { CONFIG } from '@/config'
import { LOG4JS_BASE_CATEGORY_NAME } from '@/config/const'
import { createServer } from '@/server/createServer'
import { createTestClient } from 'apollo-server-testing'
import { getLogger } from 'log4js'
import { FederatedCommunity as DbFederatedCommunity } from 'database'
import { getLogger } from 'log4js'
let query: any

View File

@ -3,10 +3,10 @@ import { LOG4JS_BASE_CATEGORY_NAME } from '@/config/const'
import { fullName } from '@/graphql/util/fullName'
import { cleanDB, testEnvironment } from '@test/helpers'
import { ApolloServerTestClient } from 'apollo-server-testing'
import { getLogger } from 'log4js'
import { Community as DbCommunity, User as DbUser, UserContact as DbUserContact } from 'database'
import Decimal from 'decimal.js-light'
import { GraphQLError } from 'graphql'
import { getLogger } from 'log4js'
import { DataSource } from 'typeorm'
import { SendCoinsArgs } from '../model/SendCoinsArgs'

View File

@ -2,8 +2,8 @@ import { CONFIG } from '@/config'
import { LOG4JS_BASE_CATEGORY_NAME } from '@/config/const'
import { createServer } from '@/server/createServer'
import { createTestClient } from 'apollo-server-testing'
import { getLogger } from 'log4js'
import { FederatedCommunity as DbFederatedCommunity } from 'database'
import { getLogger } from 'log4js'
let query: any

View File

@ -8,7 +8,7 @@ import { CONFIG } from './config'
import { LOG4JS_BASE_CATEGORY_NAME } from './config/const'
async function main() {
// init logger
// init logger
const log4jsConfigFileName = CONFIG.LOG4JS_CONFIG_PLACEHOLDER.replace('%v', CONFIG.FEDERATION_API)
initLogger(
[defaultCategory('federation', CONFIG.LOG_LEVEL), defaultCategory('apollo', CONFIG.LOG_LEVEL)],