-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
35bcef5
commit 7621854
Showing
13 changed files
with
162 additions
and
65 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -22,5 +22,6 @@ SIGN_IN_PREFILLED=true | |
# SUPPORT_DRIVER=front | ||
# SUPPORT_FRONT_HMAC_KEY=replace_me_with_front_chat_verification_secret | ||
# SUPPORT_FRONT_CHAT_ID=replace_me_with_front_chat_id | ||
# LOGGER_DRIVER=console | ||
# SENTRY_DSN=https://[email protected]/xxx | ||
# LOGGER_DRIVER=console | ||
# LOG_LEVEL=error,warn |
This file contains 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
58 changes: 58 additions & 0 deletions
58
...c/integrations/environment/decorators/__tests__/cast-to-log-level-array.decorator.spec.ts
This file contains 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,58 @@ | ||
import { plainToClass } from 'class-transformer'; | ||
|
||
import { CastToLogLevelArray } from 'src/integrations/environment/decorators/cast-to-log-level-array.decorator'; | ||
|
||
class TestClass { | ||
@CastToLogLevelArray() | ||
logLevels?: any; | ||
} | ||
|
||
describe('CastToLogLevelArray Decorator', () => { | ||
it('should cast "log" to ["log"]', () => { | ||
const transformedClass = plainToClass(TestClass, { logLevels: 'log' }); | ||
expect(transformedClass.logLevels).toStrictEqual(['log']); | ||
}); | ||
|
||
it('should cast "error" to ["error"]', () => { | ||
const transformedClass = plainToClass(TestClass, { logLevels: 'error' }); | ||
expect(transformedClass.logLevels).toStrictEqual(['error']); | ||
}); | ||
|
||
it('should cast "warn" to ["warn"]', () => { | ||
const transformedClass = plainToClass(TestClass, { logLevels: 'warn' }); | ||
expect(transformedClass.logLevels).toStrictEqual(['warn']); | ||
}); | ||
|
||
it('should cast "debug" to ["debug"]', () => { | ||
const transformedClass = plainToClass(TestClass, { logLevels: 'debug' }); | ||
expect(transformedClass.logLevels).toStrictEqual(['debug']); | ||
}); | ||
|
||
it('should cast "verbose" to ["verbose"]', () => { | ||
const transformedClass = plainToClass(TestClass, { logLevels: 'verbose' }); | ||
expect(transformedClass.logLevels).toStrictEqual(['verbose']); | ||
}); | ||
|
||
it('should cast "verbose,error,warn" to ["verbose", "error", "warn"]', () => { | ||
const transformedClass = plainToClass(TestClass, { | ||
logLevels: 'verbose,error,warn', | ||
}); | ||
expect(transformedClass.logLevels).toStrictEqual([ | ||
'verbose', | ||
'error', | ||
'warn', | ||
]); | ||
}); | ||
|
||
it('should cast "toto" to undefined', () => { | ||
const transformedClass = plainToClass(TestClass, { logLevels: 'toto' }); | ||
expect(transformedClass.logLevels).toBeUndefined(); | ||
}); | ||
|
||
it('should cast "verbose,error,toto" to undefined', () => { | ||
const transformedClass = plainToClass(TestClass, { | ||
logLevels: 'verbose,error,toto', | ||
}); | ||
expect(transformedClass.logLevels).toBeUndefined(); | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
server/src/integrations/environment/decorators/cast-to-log-level-array.decorator.ts
This file contains 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,20 @@ | ||
import { Transform } from 'class-transformer'; | ||
|
||
export function CastToLogLevelArray() { | ||
return Transform(({ value }: { value: string }) => toLogLevelArray(value)); | ||
} | ||
|
||
const toLogLevelArray = (value: any) => { | ||
if (typeof value === 'string') { | ||
const rawLogLevels = value.split(',').map((level) => level.trim()); | ||
const isInvalid = rawLogLevels.some( | ||
(level) => !['log', 'error', 'warn', 'debug', 'verbose'].includes(level), | ||
); | ||
|
||
if (!isInvalid) { | ||
return rawLogLevels; | ||
} | ||
} | ||
|
||
return undefined; | ||
}; |
This file contains 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 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
2 changes: 1 addition & 1 deletion
2
server/src/integrations/environment/interfaces/logger.interface.ts
This file contains 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,4 +1,4 @@ | ||
export enum LoggerType { | ||
export enum LoggerDriver { | ||
Console = 'console', | ||
Sentry = 'sentry', | ||
} |
This file contains 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 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
6 changes: 3 additions & 3 deletions
6
server/src/integrations/logger/interfaces/logger.interface.ts
This file contains 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 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 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 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