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

Implement formatters for log #127

Merged
merged 4 commits into from
Jan 19, 2019
Merged

Implement formatters for log #127

merged 4 commits into from
Jan 19, 2019

Conversation

bartlomieju
Copy link
Member

Based on discussion in #39 I'm making first pass at implementing formatters for log module.

This is already working and here are examples (they have exactly same output)
1.

new FileHandler("INFO", { 
    filename: "log.txt", 
    // simple string-based formatter, interpolates with fields of LogRecord
    formatter: "{levelName} {datetime} {msg}" 
});
new FileHandler("INFO", { 
    filename: "log.txt", 
    // function-based formatter, you can do
    // whatever you want here
    formatter: logRecord => {
         return `${logRecord.levelName} {logRecord.datetime} {logRecord.msg}`;
    }
});

CC @ry @hayd

log/handlers.ts Show resolved Hide resolved
log/handlers.ts Show resolved Hide resolved
log/handlers.ts Outdated
this._filename = filename;
constructor(
levelName: string,
options: FileHandlerOptions = { filename: "log.txt" }
Copy link
Member Author

Choose a reason for hiding this comment

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

this is just placeholder filename, I want to know your opinion

Copy link
Member

Choose a reason for hiding this comment

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

Not so happy with having an options interface with only one item in it. (cc @piscisaureus)
It seems if you're constructing a FileHandler, specifying a filename should be part of the process - i.e. no default value.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually it's two items, because FileHandlerOptions has filename and formatter. +1 for no default value

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

LGTM

@bartlomieju bartlomieju mentioned this pull request Jan 19, 2019
@ry ry merged commit c304ee5 into denoland:master Jan 19, 2019
@bartlomieju bartlomieju deleted the log_format branch January 19, 2019 18:47
ry pushed a commit to ry/deno that referenced this pull request Oct 9, 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.

2 participants