Created
June 22, 2020 08:51
-
-
Save HerbertLim/1575a841781cc3b7417ef82c22913657 to your computer and use it in GitHub Desktop.
AWS Lambda 에서도 log4js를 사용하기 위한 configuration
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
// 어떤 프로그램은 상황에 따라 serverless로 실행해야 하다가도 다시 EC2에서 실행해야 할 수도 있다. | |
// 그런데, EC2에서 실행될 때에는 로그를 별도의 파일에 기록해야 하는 반면, AWS Lambda의 경우는 CloudWatch 에서 확인하면 된다. | |
// EC2 에서 실행되는 경우에는 log4js 를 통해 로그를 기록하는 것이 좋고, | |
// AWS Lambda 에서는 기본적으로 console.log 로 출력하는 것이 좋다. | |
// 2 가지 경우에 대해 유연하게 대처하기 위해서는 AWS Lambda 일 때에도 log4js 를 사용하되 | |
// 아래와 같이 appenders 의 type 을 'console' 로 지정하면, console.log로 출력한 것과 동일해진다 | |
import log4js from 'log4js'; | |
log4js.configure({ | |
appenders: { 'out': { type: 'console', layout: { type: 'messagePassThrough' } } }, | |
categories: { default: { appenders: ['out'], level: 'info' } } | |
}); | |
const logger = log4js.getLogger() | |
// type 을 'stdout' 으로 지정하면 더 깔끔해지는 측면도 있으나 객체를 로깅했을 때 오히려 보기 안좋아져서 비추 | |
log4js.configure({ | |
appenders: { 'out': { type: 'stdout', layout: { type: 'messagePassThrough' } } }, | |
categories: { default: { appenders: ['out'], level: 'info' } } | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment