Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logger outputs empty object for error object #85

Closed
skgndi12 opened this issue Dec 11, 2023 · 1 comment · Fixed by #87
Closed

Logger outputs empty object for error object #85

skgndi12 opened this issue Dec 11, 2023 · 1 comment · Fixed by #87
Assignees
Labels
api bug Something isn't working

Comments

@skgndi12
Copy link
Collaborator

skgndi12 commented Dec 11, 2023

문제 상황

logger 에서 Error 객체를 empty object 로 출력하고 있음. logger 를 구현하기 위해 사용한 winston 에서 Error 객체를 핸들링하는데 문제가 있는 것으로 확인. 관련 이슈

비교 케이스

Note

출력 예시는 가독성을 위해 출력 내용을 다듬은 내용입니다. 데이터는 동일하지만 출력 형식은 상이함을 알립니다.

메시지가 에러인 경우

예시 상황

logger.error(new Error('test'))

TEXT

기대한 내용

[2023-12-14 16:51:26][error]: test {
  "stack": "Error: test\n    at main (/Users/gimseong-won/coding/Mr.C/api/src/main.ts:59:16)\n    at Object.<anonymous> (/Users/gimseong-won/coding/Mr.C/api/src/main.ts:71:3)\n    at Module._compile (node:internal/modules/cjs/loader:1254:14)\n    at Module.m._compile (/Users/gimseong-won/coding/Mr.C/api/node_modules/ts-node/src/index.ts:1618:23)\n    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)\n    at Object.require.extensions.<computed> [as .ts] (/Users/gimseong-won/coding/Mr.C/api/node_modules/ts-node/src/index.ts:1621:12)\n    at Module.load (node:internal/modules/cjs/loader:1117:32)\n    at Function.Module._load (node:internal/modules/cjs/loader:958:12)\n    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)\n    at phase4 (/Users/gimseong-won/coding/Mr.C/api/node_modules/ts-node/src/bin.ts:649:14)",
  "deployment": "dev"
}

실제 내용

[2023-12-14 17:40:45][error]: test {
  "deployment": "dev"
}

JSON

기대한 내용

{
  "deployment": "dev",
  "level": "error",
  "message": "test",
  "stack": "Error: test\n    at main (/Users/gimseong-won/coding/Mr.C/api/src/main.ts:59:16)\n    at Object.<anonymous> (/Users/gimseong-won/coding/Mr.C/api/src/main.ts:71:3)\n    at Module._compile (node:internal/modules/cjs/loader:1254:14)\n    at Module.m._compile (/Users/gimseong-won/coding/Mr.C/api/node_modules/ts-node/src/index.ts:1618:23)\n    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)\n    at Object.require.extensions.<computed> [as .ts] (/Users/gimseong-won/coding/Mr.C/api/node_modules/ts-node/src/index.ts:1621:12)\n    at Module.load (node:internal/modules/cjs/loader:1117:32)\n    at Function.Module._load (node:internal/modules/cjs/loader:958:12)\n    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)\n    at phase4 (/Users/gimseong-won/coding/Mr.C/api/node_modules/ts-node/src/bin.ts:649:14)",
  "timestamp": "2023-12-14 16:52:15"
}

실제 내용

{
  "deployment": "dev",
  "level": "error",
  "timestamp": "2023-12-14 17:41:41"
}

비교 결과

TEXT 에서는 에러의 메시지만 출력되고 stack 이 없는 채로 출력됨. JSON 형식에서는 에러 정보가 완전히 누락된 채로 출력됨.

메타 정보가 에러인 경우

예시 상황

logger.error('meta include error', new Error('test'));

TEXT

기대한 내용

[2023-12-14 16:57:16][error]: meta include error test {
  "deployment": "dev",
  "stack": "Error: test\n    at main (/Users/gimseong-won/coding/Mr.C/api/src/main.ts:59:38)\n    at Object.<anonymous> (/Users/gimseong-won/coding/Mr.C/api/src/main.ts:71:3)\n    at Module._compile (node:internal/modules/cjs/loader:1254:14)\n    at Module.m._compile (/Users/gimseong-won/coding/Mr.C/api/node_modules/ts-node/src/index.ts:1618:23)\n    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)\n    at Object.require.extensions.<computed> [as .ts] (/Users/gimseong-won/coding/Mr.C/api/node_modules/ts-node/src/index.ts:1621:12)\n    at Module.load (node:internal/modules/cjs/loader:1117:32)\n    at Function.Module._load (node:internal/modules/cjs/loader:958:12)\n    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)\n    at phase4 (/Users/gimseong-won/coding/Mr.C/api/node_modules/ts-node/src/bin.ts:649:14)"
}

실제 내용

[2023-12-14 17:43:33][error]: meta include error test {
  "deployment": "dev",
  "stack": "Error: test\n    at main (/Users/gimseong-won/coding/Mr.C/api/src/main.ts:62:38)\n    at Object.<anonymous> (/Users/gimseong-won/coding/Mr.C/api/src/main.ts:82:3)\n    at Module._compile (node:internal/modules/cjs/loader:1254:14)\n    at Module.m._compile (/Users/gimseong-won/coding/Mr.C/api/node_modules/ts-node/src/index.ts:1618:23)\n    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)\n    at Object.require.extensions.<computed> [as .ts] (/Users/gimseong-won/coding/Mr.C/api/node_modules/ts-node/src/index.ts:1621:12)\n    at Module.load (node:internal/modules/cjs/loader:1117:32)\n    at Function.Module._load (node:internal/modules/cjs/loader:958:12)\n    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)\n    at phase4 (/Users/gimseong-won/coding/Mr.C/api/node_modules/ts-node/src/bin.ts:649:14)"
}

JSON

기대한 내용

{
  "deployment": "dev",
  "level": "error",
  "message": "meta include error test",
  "stack": "Error: test\n    at main (/Users/gimseong-won/coding/Mr.C/api/src/main.ts:59:38)\n    at Object.<anonymous> (/Users/gimseong-won/coding/Mr.C/api/src/main.ts:71:3)\n    at Module._compile (node:internal/modules/cjs/loader:1254:14)\n    at Module.m._compile (/Users/gimseong-won/coding/Mr.C/api/node_modules/ts-node/src/index.ts:1618:23)\n    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)\n    at Object.require.extensions.<computed> [as .ts] (/Users/gimseong-won/coding/Mr.C/api/node_modules/ts-node/src/index.ts:1621:12)\n    at Module.load (node:internal/modules/cjs/loader:1117:32)\n    at Function.Module._load (node:internal/modules/cjs/loader:958:12)\n    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)\n    at phase4 (/Users/gimseong-won/coding/Mr.C/api/node_modules/ts-node/src/bin.ts:649:14)",
  "timestamp": "2023-12-14 16:53:48"
}

실제 내용

{
  "deployment": "dev",
  "level": "error",
  "message": "meta include error test",
  "stack": "Error: test\n    at main (/Users/gimseong-won/coding/Mr.C/api/src/main.ts:62:38)\n    at Object.<anonymous> (/Users/gimseong-won/coding/Mr.C/api/src/main.ts:82:3)\n    at Module._compile (node:internal/modules/cjs/loader:1254:14)\n    at Module.m._compile (/Users/gimseong-won/coding/Mr.C/api/node_modules/ts-node/src/index.ts:1618:23)\n    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)\n    at Object.require.extensions.<computed> [as .ts] (/Users/gimseong-won/coding/Mr.C/api/node_modules/ts-node/src/index.ts:1621:12)\n    at Module.load (node:internal/modules/cjs/loader:1117:32)\n    at Function.Module._load (node:internal/modules/cjs/loader:958:12)\n    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)\n    at phase4 (/Users/gimseong-won/coding/Mr.C/api/node_modules/ts-node/src/bin.ts:649:14)",
  "timestamp": "2023-12-14 17:42:25"
}

비교 결과

TEXT 및 JSON 형식 모두 기대한대로 에러가 포함되어서 출력됨.

메타 정보의 어트리뷰트가 에러를 포함하고 있는 오브젝트인 경우

예시 상황

 logger.error('attribute in meta include error', { error: new Error('test') });

TEXT

기대한 내용

[2023-12-14 17:45:56][error]: attribute in meta include error test {
  "deployment": "dev",
  "error": {
    "stack": "Error: test\n    at main (/Users/gimseong-won/coding/Mr.C/api/src/main.ts:62:50)\n    at Object.<anonymous> (/Users/gimseong-won/coding/Mr.C/api/src/main.ts:82:3)\n    at Module._compile (node:internal/modules/cjs/loader:1254:14)\n    at Module.m._compile (/Users/gimseong-won/coding/Mr.C/api/node_modules/ts-node/src/index.ts:1618:23)\n    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)\n    at Object.require.extensions.<computed> [as .ts] (/Users/gimseong-won/coding/Mr.C/api/node_modules/ts-node/src/index.ts:1621:12)\n    at Module.load (node:internal/modules/cjs/loader:1117:32)\n    at Function.Module._load (node:internal/modules/cjs/loader:958:12)\n    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)\n    at phase4 (/Users/gimseong-won/coding/Mr.C/api/node_modules/ts-node/src/bin.ts:649:14)"
  }
}

실제 내용

[2023-12-14 17:39:12][error]: attribute in meta include error {
  "deployment": "dev",
  "error": {}
}

JSON

기대한 내용

{
  "deployment": "dev",
  "level": "error",
  "message": "attribute in meta include error test",
  "error": {
    "stack": "Error: test\n    at main (/Users/gimseong-won/coding/Mr.C/api/src/main.ts:62:50)\n    at Object.<anonymous> (/Users/gimseong-won/coding/Mr.C/api/src/main.ts:82:3)\n    at Module._compile (node:internal/modules/cjs/loader:1254:14)\n    at Module.m._compile (/Users/gimseong-won/coding/Mr.C/api/node_modules/ts-node/src/index.ts:1618:23)\n    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)\n    at Object.require.extensions.<computed> [as .ts] (/Users/gimseong-won/coding/Mr.C/api/node_modules/ts-node/src/index.ts:1621:12)\n    at Module.load (node:internal/modules/cjs/loader:1117:32)\n    at Function.Module._load (node:internal/modules/cjs/loader:958:12)\n    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)\n    at phase4 (/Users/gimseong-won/coding/Mr.C/api/node_modules/ts-node/src/bin.ts:649:14)"
  },
  "timestamp": "2023-12-14 17:48:01"
}

실제 내용

{
  "deployment": "dev",
  "error": {},
  "level": "error",
  "message": "attribute in meta include error",
  "timestamp": "2023-12-14 17:37:18"
}

비교 결과

TEXT 및 JSON 형식 모두 에러가 비어있는 객체로 출력됨.

@skgndi12 skgndi12 added bug Something isn't working api labels Dec 11, 2023
@skgndi12 skgndi12 self-assigned this Dec 11, 2023
@skgndi12 skgndi12 added this to Alpha Dec 11, 2023
@skgndi12 skgndi12 changed the title Fix Logger Error Object Printing Bug Logger is not printing the error object Dec 11, 2023
@skgndi12 skgndi12 changed the title Logger is not printing the error object Logger Outputs Empty Object for Error Objects Dec 11, 2023
@skgndi12 skgndi12 changed the title Logger Outputs Empty Object for Error Objects Logger outputs empty object for error objects Dec 11, 2023
@skgndi12 skgndi12 moved this to Todo in Alpha Dec 11, 2023
@skgndi12 skgndi12 changed the title Logger outputs empty object for error objects Logger outputs empty object for error object Dec 11, 2023
@skgndi12 skgndi12 moved this from Todo to In Progress in Alpha Dec 19, 2023
skgndi12 added a commit that referenced this issue Dec 20, 2023
…y-object-for-error-object

[#85] Fix empty object output for Error objects
@github-project-automation github-project-automation bot moved this from In Progress to Done in Alpha Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant