X-Git-Url: https://git.r.bdr.sh/rbdr/cologne/blobdiff_plain/941d09019e402ac565101fba6d824bd48504c90b..deb2dffd5eff50924d33ebc2ea716c6423588518:/README.md diff --git a/README.md b/README.md index b162346..87f808f 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Example of instantiating a cobalt logger: In node: ``` -Cobalt = require('cobalt-log'); +require('cobalt-log'); ``` In the browser just require the files. Then: @@ -97,6 +97,26 @@ passing the `logObject` and `formatterOpts`. This means that a formatter is any object that responds to `format(logObject, formatterOpts)`. It expects a string to be returned. +### Cobalt.Logger.File ### + +This logger communicates a file via a writable stream, and is intended +only for node. Like the JSConsole logger, you can also initialize it with +a formatter to convert the log object to a string: + +``` + new Cobalt.Logger.File({ + formatter : Cobalt.Formatter.Token, + formatterOpts : { + formatString : "[{{_timestamp}}] {{message}} (@{{_from}})" + } + }) +``` + +What this does is: it will trigger the method `format` on `formatter` +passing the `logObject` and `formatterOpts`. This means that a formatter is +any object that responds to `format(logObject, formatterOpts)`. It expects +a string to be returned. + ### Cobalt.Logger.Socket ### This logger sends the log object to a socket using Socket.IO. It does not @@ -128,15 +148,46 @@ passes the object to every logger it has. However, it is clear that loggers may want to manipulate this object. As shown in the JsConsole, a formatter should respond to the format method and receive a `logObject` and an `optsObject`. However, as this is not a core part of Cobalt, this is only a -recommendation (as this is the way the included JsConsole logger does it) +recommendation (as this is the way the included JsConsole/File loggers do it) and it is up to the logger on how to transform the object it receives. -Cobalt includes a very simple formatter that works well in conjuction -with JsConsole. + +### Cobalt.Formatter.Simple ### + +This is the lazy formatter, it just outputs the string in the following +format: + +``` +'[{{_timestamp}}][{{_logLevelString}}]{{_from}}: {{_message}}' +``` + +Where `_timestamp` is converted to ISO. + +Example output: + +``` +cobalt.log("hello world"); +// -> [2015-01-09T16:02:23.102Z][INFO] Generic Cobalt Logger : hello world +``` ### Cobalt.Formatter.Token ### -The Token formatter is a very simple formatter that uses a formatString to -extract values from the log object and interpolate them in a string. +The Token formatter is a more advanced, but still fairly simple +formatter. It takes a `formatString` and interpolates the properties +of the object. By default it transforms anything inside double curly +braces `{{likeThis}}`, however you can set a custom `replaceRule`. + +#### Accepted Options #### + +* `formatString` : The string used to replace. Defaults to `"{{message}}"` +* `replaceRule` : The regex rule to use for replacement of tokens in the + formatString. Defaults to `/{{(.*?)}}/g` +* `separatorLength` : How long to print separators. Defaults to 60. +* `isoDate` : Whether or not to convert `_timestamp` to ISO + date. Defaults to true. +* `separatorType` : The string to use for the separator. + Defaults to `"="` +* `ansiColor` : Whether to use ANSI colors for output. + Defaults to `false`. This options depends on `colors` #### Options ####