-
Notifications
You must be signed in to change notification settings - Fork 1
Adds several formatting functions and respective configuration options. #24
base: master
Are you sure you want to change the base?
Conversation
- `pedantic`: End your messages with a `.` or user-specified string - `capitalize`: Begin your message with a capital letter - `normalize`: A shortcut for `pedantic: true` and `capitalize: true` - `formatter`: User-defined function to reformat any message I *think* these are OK, because while the module must be 100% bunyan-compatible, it *can* be a superset, correct? My only other concern is `index.js:427` which is a pretty flimsy attempt to detect an object or array converted into JSON. The alternative is to attempt to `JSON.parse()` it, but that's a fair bit of overhead for a "nice-to-have" feature. Anyway, if you don't like and/or cannot use these changes, is it possible to at least retain `Logger.prototype._formatMessage` as an "abstract" (empty) function + its invocation, so that I can subclass `Logger`? tests + docs
|
Hey man, whilst I like the idea and this has crossed my mind a couple of times, this isn't going to make it in like that, mainly that regexp test. Rather than so many configuration properties, maybe we can have a single The default format function would just call util.format() as it already does in write(). We would then pass the message, parameters, logger instance, etc and the implementation can then call Work for you? |
|
I'm sure that'd work for me, but I don't quite understand what you're proposing here:
This sounds like you need to actually do something like How about an array instead? // in config
{
format: ['pedantic', 'capitalize', function custom1(msg) {}, function custom2(msg) {}]
}Instead of Logger.formatters = {
pedantic: function() {},
capitalize: function() {}
// etc.
};Given this array (or perhaps support singular string/function values as well), if a string is found, look for equivalent key in the Re: the JSON thing; perhaps we can flip a switch to say "this message is stringified", when it happens. But perhaps we don't need the check at all. What say you? |
|
We can solve that particular issue by allowing Allowing the format object to be an array is also useful (multiple formatters), although I wonder if it is necessary, surely whatever formatting you desire can be achieved with a single function? |
|
So if the users wants to use
function(msg, parameters) {
var Logger = require('cli-logger').Logger,
m = Logger.capitalize(Logger.pedantic(msg, '!'));
return require('util').format.apply(null, [m].concat(parameters));
}
|
|
Ok cool, I think I know what you need, let me think about this a little, busy with commercial work today ;) |
|
Sounds good. |
|
FYI, this commit: Tidies the module exports such that you can access it via Apart from those exceptions all dependent modules are exposed as well as various classes from https://github.com/freeformsystems/cli-command/blob/master/index.js#L558 |
|
I prefer this approach:
Does that solve your use case? |
Adds several formatting functions and respective configuration options.
pedantic: End your messages with a.or user-specified stringcapitalize: Begin your message with a capital letternormalize: A shortcut forpedantic: trueandcapitalize: trueformatter: User-defined function to reformat any messageI think these are OK, because while the module must be 100% bunyan-compatible, it can be a superset, correct?
My only other concern is
index.js:427which is a pretty flimsy attempt to detect an object or array converted into JSON. The alternative is to attempt toJSON.parse()it, but that's a fair bit of overhead for a "nice-to-have" feature.Anyway, if you don't like and/or cannot use these changes, is it possible to at least retain
Logger.prototype._formatMessageas an "abstract" (empty) function + its invocation, so that I can subclassLogger?tests + docs