Permalink
Browse files

Add Redis and jQuery backends

  • Loading branch information...
1 parent a12cea1 commit c3e1c2cfe2c27e78052969ad4012a7c9573ecd2e @mixu committed Jun 9, 2012
Showing with 47 additions and 5 deletions.
  1. +16 −1 backends/jquery.js
  2. +16 −0 backends/redis.js
  3. +15 −4 readme.md
View
@@ -1,9 +1,24 @@
function jqBackend(options) {
- this.url = options.url || 'http://localhost';
+ this.url = options.url || 'http://localhost/';
+ this.cache = [];
+ this.timer = null;
+ this.interval = options.interval || 30*1000;
}
jqBackend.prototype.write = function(str) {
+ if(!this.timer) { this.init(); }
+ this.cache.push(str);
+};
+jqBackend.prototype.init = function() {
+ var self = this;
+ this.timer = setTimeout(function() {
+ var data = this.cache;
+ this.cache = [];
+ window.$.post(self.url, data, function(data, textStatus, jqXHR) {
+ self.init();
+ }, 'json');
+ }, this.interval);
};
jqBackend.prototype.end = function() {};
View
@@ -0,0 +1,16 @@
+function RedisBackend(options) {
+ this.client = options.client;
+ this.key = options.key;
+}
+
+RedisBackend.prototype.write = function(str) {
+ this.client.rpush(this.key, str);
+};
+
+RedisBackend.prototype.end = function() {};
+
+RedisBackend.prototype.clear = function(cb) {
+ this.client.del(this.key, cb);
+};
+
+module.exports = RedisBackend;
View
@@ -1,8 +1,9 @@
# minilog - features
- Works in the browser and on the server
-- Very simple client (no external dependencies; less than 100 lines); looks like a readable stream/eventemitter
+- Very simple client (no external dependencies; less than 80 lines); looks like a readable stream/eventemitter
- Backends are writable streams, simple to write new adapters
+- Formatters/themes and filters are simple functions applied to a particular pipe; ships with multiple options
- Logs are optionally scoped/namespaced to a particular module, like TJ's [debug](https://github.com/visionmedia/debug) and can be enabled/disabled selectively
- log.debug, log.info, log.warn, log.error
@@ -23,10 +24,14 @@ To log into a file:
require('minilog').pipe(fs.createWriteStream('./temp.log'));
-To log every 30s over HTTP via jQuery.ajax:
+To log into Redis:
- var jQueryBackend = require('minilog').backends.jquery;
- require('minilog').pipe(new jQueryBackend({ url: 'http://localhost/'}));
+ var client = require('redis').createClient();
+ require('minilog').pipe(new require('minilog').backends.redis({ client: client, key: 'logs'}));
+
+To log over HTTP via jQuery.ajax:
+
+ require('minilog').pipe(new require('minilog').backends.jquery({ url: 'http://localhost/'}));
You can pipe to more than one pipe if you want.
@@ -75,6 +80,12 @@ Each pipe returns a chainable config object. Formatting can be applied to pipes:
The console logger comes with format functions inspired by [logme](https://github.com/vesln/logme).
The withStack formatter can print the module name and current line number by examining the stack trace.
+## Adding annotations
+
+You can add annotations (like date, user account and so on) during the formatting step
+
+## Logging as JSON over a remote connection
+
## Adding filters

0 comments on commit c3e1c2c

Please sign in to comment.