320x100
320x100
winston을 사용하여 객체를 출력해보면 [Object] 이런 형태로 출력이 된다
사실 JSON.stringify로 객체를 string으로 변환하여 출력해도 되지만 객체가 한줄로 표현되기 때문에 보기힘들다는 단점이 있다
printf(({ level, message, timestamp }) => {
level = level.toUpperCase()
return `${timestamp} [${level}]: ${util.format('%o', message)}`
})
위와 같이 winston의 logger를 설정하면 객체 그대로 출력할 수 있다
var space = JSON.stringify({a: 2}, null, 5);
console.log(space);
// 5칸의 공백
// {
// “a”: 2
// }
아니면 이렇게 JSON.stringify에 옵션을 줘도 모양을 유지하여 출력할 수 있다
Reference
winston format 사용 시, object 출력
백엔드 쪽에서, morgan을 winston으로 교체하는 과정에서 object가 console.log 와는 다른 형태로 출력되는 것을 확인. 여러 웹 사이트를 뒤지다 보니, JSON.stringify() 를 사용하면 된다고도 하고, util.format을
spyrr.tistory.com
JSON.stringify( )란 무엇인가? — Steemit
JSON.stringify( )는 자바스크립트의 값을 JSON 문자열로 변환한다. JSON이란? JSON은 JavaScript Object Notation의 약자로, 브라우저와 서버사이에서 오고가는 데이터의 형식이다. JSON.stringify(value, replacer, space)
steemit.com
300x250
728x90
'Programming > NodeJS' 카테고리의 다른 글
Express의 단점과 해결방법 (0) | 2024.04.27 |
---|---|
NodeJS가 싱글 스레드임에도 동시성을 가진 이유 (1) | 2024.03.16 |
Express response 함수 비교 (0) | 2024.01.20 |
nodejs 프로세스 관리 spawn vs exec (0) | 2024.01.17 |
Express 서버와 Swagger 연동하기 (0) | 2023.08.27 |