Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[refactor] add comments, etc.

  • Loading branch information...
commit 7afd56e284fa16fb09b2b64ba54c0efbc6bf21d3 1 parent c0875a9
Christopher Jeffrey chjj authored

Showing 1 changed file with 39 additions and 10 deletions. Show diff stats Hide diff stats

  1. +39 10 lib/winston-nssocket.js
49 lib/winston-nssocket.js
... ... @@ -1,6 +1,14 @@
  1 +/*
  2 + * winston-nssocket.js: Transport for logging to Nssocket
  3 + *
  4 + * (C) 2011 Maciej Małecki
  5 + * MIT LICENSE
  6 + *
  7 + */
  8 +
1 9 var util = require('util'),
2   - winston = require('../../winston'),
3   - nssocket = require('nssocket')
  10 + winston = require('winston'),
  11 + nssocket = require('nssocket'),
4 12 Stream = require('stream').Stream;
5 13
6 14 //
@@ -18,11 +26,26 @@ var NsSocket = exports.Nssocket = function (options) {
18 26 this.socket = new nssocket.NsSocket(options.socket || {
19 27 reconnect: true
20 28 });
  29 +
21 30 this.socket.connect(options.host, options.port);
22 31 };
23 32
24 33 util.inherits(NsSocket, winston.Transport);
25 34
  35 +//
  36 +// Expose the name of this Transport on the prototype
  37 +//
  38 +NsSocket.prototype.name = 'nssocket';
  39 +
  40 +//
  41 +// Define a getter so that `winston.transports.Nssocket`
  42 +// is available and thus backwards compatible.
  43 +//
  44 +winston.transports.Nssocket = NsSocket;
  45 +
  46 +//
  47 +// Keep uid counter for query requests.
  48 +//
26 49 NsSocket.uid = 0;
27 50
28 51 //
@@ -64,14 +87,20 @@ NsSocket.prototype.log = function (level, msg, meta, callback) {
64 87 };
65 88
66 89 //
67   -// ### function query ()
68   -// Query the transport.
  90 +// ### function query (options, callback)
  91 +// #### @options {Object} Loggly-like query options for this instance.
  92 +// #### @callback {function} Continuation to respond to when complete.
  93 +// Query the transport. Options object is optional.
69 94 //
70 95 NsSocket.prototype.query = function (options, callback) {
71   - var self = this,
72   - options = options || {};
  96 + if (typeof options === 'function') {
  97 + callback = options;
  98 + options = {};
  99 + }
73 100
74   - var id = NsSocket.uid++ + '';
  101 + var self = this,
  102 + options = this.normalizeQuery(options),
  103 + id = NsSocket.uid++ + '';
75 104
76 105 this.socket.send(['query', id], options);
77 106
@@ -84,10 +113,10 @@ NsSocket.prototype.query = function (options, callback) {
84 113 });
85 114 };
86 115
87   -
88 116 //
89   -// ### function stream ()
90   -// Return a log stream.
  117 +// ### function stream (options)
  118 +// #### @options {Object} Stream options for this instance.
  119 +// Returns a log stream for this transport. Options object is optional.
91 120 //
92 121 NsSocket.prototype.stream = function (options) {
93 122 var self = this,

0 comments on commit 7afd56e

Please sign in to comment.
Something went wrong with that request. Please try again.