Skip to content

feat: support contextFormatter #51

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

Merged
merged 7 commits into from
Mar 14, 2019
Merged

feat: support contextFormatter #51

merged 7 commits into from
Mar 14, 2019

Conversation

popomore
Copy link
Member

Checklist
  • npm test passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)
Description of change

Ref #46 #37

Sorry, something went wrong.

@popomore popomore requested a review from atian25 March 13, 2019 12:13
@@ -80,7 +80,8 @@ module.exports = {
meta = meta || {};
let message;
let output;
const formatter = meta.formatter || options.formatter;
let formatter = meta.formatter || options.formatter;
if (meta.ctx && options.contextFormatter) formatter = options.contextFormatter;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contextFormatter 没有默认值,如果定义了则用之

@codecov
Copy link

codecov bot commented Mar 13, 2019

Codecov Report

Merging #51 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #51      +/-   ##
==========================================
+ Coverage   99.45%   99.45%   +<.01%     
==========================================
  Files          14       14              
  Lines         368      369       +1     
==========================================
+ Hits          366      367       +1     
  Misses          2        2
Impacted Files Coverage Δ
lib/egg/logger.js 100% <ø> (ø) ⬆️
lib/transports/transport.js 100% <ø> (ø) ⬆️
lib/egg/context_logger.js 100% <ø> (ø) ⬆️
lib/utils.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6b105c3...9b69b14. Read the comment docs.

@codecov
Copy link

codecov bot commented Mar 13, 2019

Codecov Report

Merging #51 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #51      +/-   ##
==========================================
+ Coverage   99.45%   99.45%   +<.01%     
==========================================
  Files          14       14              
  Lines         368      370       +2     
==========================================
+ Hits          366      368       +2     
  Misses          2        2
Impacted Files Coverage Δ
lib/egg/logger.js 100% <ø> (ø) ⬆️
lib/transports/transport.js 100% <ø> (ø) ⬆️
lib/utils.js 100% <100%> (ø) ⬆️
lib/egg/context_logger.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6b105c3...d0826ef. Read the comment docs.

Copy link
Member

@atian25 atian25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README 也补充下

index.d.ts Outdated
@@ -20,6 +20,7 @@ export interface LoggerOptions {
export interface EggLoggerOptions extends LoggerOptions {
file: string;
formatter?: any;
Copy link
Member

@atian25 atian25 Mar 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
formatter?: any;
formatter?: (meta?: object) => string;

Co-Authored-By: popomore <sakura9515@gmail.com>
Copy link
Member

@atian25 atian25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@@ -44,6 +44,7 @@ class ContextLogger {
const meta = {
formatter: contextFormatter,
paddingMessage: this.paddingMessage,
ctx: this.ctx,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

要不要 define 为不可枚举的,避免之前的 logger 有 JSON.stringify 的

@atian25

This comment has been minimized.

@popomore popomore merged commit 0cbbe47 into master Mar 14, 2019
@popomore popomore deleted the contextFormatter branch March 14, 2019 13:19
@popomore
Copy link
Member Author

  • egg-logger@2.4.0

atian25 pushed a commit that referenced this pull request Apr 17, 2019
atian25 pushed a commit that referenced this pull request Apr 17, 2019
atian25 pushed a commit that referenced this pull request May 7, 2019
atian25 pushed a commit that referenced this pull request May 7, 2019
atian25 added a commit that referenced this pull request May 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants