@edsonarios/custom-logger
v1.0.8
Published
Custom logger using winston to CDK and Nest
Downloads
5
Readme
Installation
$ npm install @edsonarios/custom-logger
Api key required
# .env
LOG_SECRET_KEY=SecretKey
LOG_API_KEY=ApiKey
LOG_LEVEL=debug # default debug
STAGE=local # NoLocal or undefined
CDK Implement
import { CDKLogger } from '@edsonarios/custom-logger'
const logger = new CDKLogger(`handlerContext`)
export const handler = async (event?: any) => {
const object = {
key: 'value',
inside: { key2: 'value2', key3: 'value3' },
inside2: { key4: 'value5', key5: 'value5' },
}
logger.log('log message', object, 'string', object)
logger.error('error message')
logger.warn('warn message')
logger.debug('debug message')
logger.verbose('verbose message')
}
Nest Implement
// main.ts
import { NestGroupLogger } from '@edsonarios/custom-logger'
export async function createApp(host?: string) {
const app = await NestFactory.create(AppModule, {
logger: new NestGroupLogger(),
})
return app
}
// api.controller.ts | anyFile
import { NestGroupLogger } from '@edsonarios/custom-logger'
export class ApiController {
private readonly logger = new NestGroupLogger(ApiController.name)
@Post()
create() {
const object = {
key: 'value',
inside: { key2: 'value2', key3: 'value3' },
inside2: { key4: 'value5', key5: 'value5' },
}
this.logger.log('log message', object, 'data', object)
this.logger.error('error message', object, 'data', object)
this.logger.warn('warn message', object, 'data', object)
this.logger.debug('debug message', object, 'data', object)
this.logger.verbose('verbose message', object, 'data', object)
}
}