~ubuntu-branches/ubuntu/vivid/node-log4js/vivid

« back to all changes in this revision

Viewing changes to lib/appenders/loggly.js

  • Committer: Package Import Robot
  • Author(s): Mike Gabriel
  • Date: 2014-08-20 14:19:20 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20140820141920-8cl8s6ak7uzl8jfe
Tags: 0.6.18-1
* New upstream release.
* debian/rules:
  + Add get-orig-source rule.
* debian/control:
  + Bump Standards: to 3.9.5. No changes needed.
  + Move packaging Git to pkg-javascript namespace on Alioth.
* debian/patches:
  + Refresh and update 001_debian-log4js-examples.patch. Make sure
    upstream's new example files find the log4js module when installed
    on Debian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
'use strict';
 
2
var layouts = require('../layouts')
 
3
, loggly = require('loggly')
 
4
, os = require('os')
 
5
, passThrough = layouts.messagePassThroughLayout;
 
6
 
 
7
 
 
8
/**
 
9
 * Loggly Appender. Sends logging events to Loggly using node-loggly 
 
10
 *
 
11
 * @param config object with loggly configuration data
 
12
 * {
 
13
 *   token: 'your-really-long-input-token',
 
14
 *   subdomain: 'your-subdomain',
 
15
 *   tags: ['loggly-tag1', 'loggly-tag2', .., 'loggly-tagn'] 
 
16
 * }
 
17
 * @param layout a function that takes a logevent and returns a string (defaults to objectLayout).
 
18
 */
 
19
function logglyAppender(config, layout) {
 
20
        var client = loggly.createClient(config);
 
21
  if(!layout) layout = passThrough;
 
22
 
 
23
  return function(loggingEvent) {
 
24
                var msg = layout(loggingEvent);
 
25
                client.log({
 
26
                        msg: msg,
 
27
                        level: loggingEvent.level.levelStr,
 
28
                        category: loggingEvent.categoryName,
 
29
                        hostname: os.hostname().toString(),
 
30
                });
 
31
  }
 
32
}
 
33
 
 
34
function configure(config) {
 
35
        var layout;
 
36
        if (config.layout) {
 
37
                layout = layouts.layout(config.layout.type, config.layout);
 
38
        }
 
39
        return logglyAppender(config, layout);
 
40
}
 
41
 
 
42
exports.name      = 'loggly';
 
43
exports.appender  = logglyAppender;
 
44
exports.configure = configure;