-
Notifications
You must be signed in to change notification settings - Fork 628
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 implementation #39
Comments
|
|
|
@ry I totally agree. We can expose logging methods in exports, and those methods would call default logger. Those two snippets would then be equivalent. import * as log from "https://deno.land/std/log.ts";
log.debug("blah");
log.info("foo"); import * as log from "https://deno.land/std/log.ts";
const myLogger = log.getLogger();
myLogger.debug("blah");
myLogger.info("foo"); Regarding capturing and sending logs somewhere else, that's where Python's implementation shines. import * as log from "https://deno.land/std/log.ts";
await log.config({
handlers: {
console: {
level: 'debug',
handler: new log.ConsoleHandler(),
},
file: {
level: 'info',
handler: new log.FileHandler(),
},
},
loggers: {
deno: {
level: 'debug',
handlers: ['console', 'file']
}
}
});
const logger = log.getLogger('deno');
logger.debug("blah"); // logged to console only
logger.info("foo"); // logged to both console and file |
@bartlomieju seems good! |
Probably yes, I'm still trying to figure it out. But if you look for example at |
@bartlomieju please share to me how logger will be implemented when decided. I'll fix my PR by the guide if needed. Thanks for your work. |
@djKooks you can track progress in #51 |
During chat conversation with @ry we concluded that logging methods should take only one argument import * as deno from 'deno';
import * as log from 'https://deno.land/x/std/logging/index.ts';
const someNum = 100;
const someObj = { a: 1, b: 2 };
// instead of interpolation ...
log.info("Number: %n, object: %o", someNum, someObj);
// just use template strings
log.info(`Number: ${someNum}, object: ${deno.inspect(someObj)}`) This minimizes the API that has to be implemented. As for output format of each message, Glog's style was proposed (also here). Note: we're not sure why leading bracket Proposed format: [Lmmdd hh:mm:ss.uuuuuu threadid file:line] msg where:
Example line would look like this:
To be honest I'm not a big fan of this format, I'd prefer to output ISO date like this:
|
Would this be configurable? |
Have you thought about how to extract "main.ts:30" ?
If we're going to use glogs format, let's copy it exactly, including the unmatched bracket. It's not a mistake. I just don't know the reason for it.
Your proposed format is longer...
I'd rather we agree on one format... |
My initial idea was to leverage
It is, but glog's format is hard to grep when you see it for first time, especially conjunction of log level and date. But I'm not sticking to it no matter what.
That's fine for me, but it will bring a need for another logging libraries that allow to configure that. |
Hm.. It's possible we could provide |
@ry one more comment on configurable format - tests would be much simpler if format could be manipulated, eg. date could be skipped. Otherwise we'd need some kind of wildcard matching? |
@bartlomieju true good point. |
After some consideration I think we might want to change export interface LogRecord {
msg: string;
args: any[];
datetime: Date;
level: number;
levelName: string;
}
debug(msg: string, ...args: any[]) {
return this._log(LogLevel.DEBUG, msg, ...args);
} to: type LogMetadata = {[key: string]: any};
export interface LogRecord {
msg: string;
metadata?: LogMetadata;
datetime: Date;
level: number;
levelName: string;
}
debug(msg: string, metadata?: LogMetadata) {
return this._log(LogLevel.DEBUG, msg, metadata);
} this object would be placed in |
@bartlomieju That seems like more to type? Or maybe I misunderstand. Can you give some examples of invocation? |
Yeah after all it seems so. My initial idea was that We could keep |
I reckon |
I'm opening this issue to start discussion on vision for
logging
module.Coming from Python world and being familiar with its library, my intent for Deno logging was to emulate Python's approach.
Its mechanism is based on:
loggers
- object to call to log something obviouslyLogRecord
- contains timestamps and metadata about message logged bylogger
handlers
- also known astransports
. Onelogger
may utilize multiple `handlers. Eg. console handler that print output to console, file handler that streams logs to file on disk.filters
- predicates that interact withLogRecords
, allowing for very granular control. Bothloggers
andhandlers
can have filtersformatters
- a function that givenLogRecord
instance returns output stringLoggers are accessed using
getLogger
function, so wherever in code you doconst logger = logging.getLogger('myLogger');
you get the same instance.This page gives a nice overview how to use it in action.
One of more popular node's logging libraries winston takes not so different approach.
I'm really interested what community expects.
The text was updated successfully, but these errors were encountered: