<commit_before># node-loggly

A client implementation for Loggly in node.js

## Installation

### Installing npm (node package manager)
<pre>
  curl http://npmjs.org/install.sh | sh
</pre>

### Installing winston
<pre>
  [sudo] npm install loggly
</pre>

## Usage

The node-loggly library is compliant with the [Loggly API][0]. Using node-loggly is easy for a variety of scenarios: logging, working with devices and inputs, searching, and facet searching.

### Getting Started
Before we can do anything with loggly, we have to create a client with valid credentials. We will authenticate for you automatically: 
<pre>
  var loggly = require('loggly');
  var config = {
    subdomain: "your-subdomain",
    auth: {
      username: "your-username",
      password: "<PASSWORD>"
    }
  };
  var client = loggly.createClient(config);
</pre>

### Logging
There are two ways to send log information to loggly via node-loggly. The first is to simply call client.log with an appropriate input token:

<pre>
  client.log('your-really-long-input-token', '127.0.0.1 - Theres no place like home', function (err, result) {
    // Do something once you've logged
  });
</pre>

Note that the callback in the above example is optional, if you prefer the 'fire and forget' method of logging:
<pre>
  client.log('your-really-long-input-token', '127.0.0.1 - Theres no place like home');
</pre>

The second way to send log information to loggly is to do so once you've retrieved an input directly from loggly:
<pre>
  client.getInput('your-input-name', function (err, input) {
    input.log('127.0.0.1 - Theres no place like home');
  });
</pre> 

Again the callback in the above example is optional and you can pass it if you'd like to.

### Logging Shallow JSON Object Literals
In addition to logging pure strings it is also possible to pass shallow JSON object literals (i.e. no nested objects) to client.log(..) or input.log(..) methods, which will get converted into the [Loggly recommended string representation][1]. So

<pre>
  var source = {
    foo: 1,
    bar: 2,
    buzz: 3
  };
  
  input.log(source);
</pre>

will be logged as: 

<pre>
  foo=1,bar=2,buzz=3
</pre>

### Searching
[Searching][3] with node-loggly is easy. All you have to do is use the search() method defined on each loggly client:
<pre>
  var util = require('util');
  
  client.search('404', function (err, results) {
    // Inspect the result set
    util.inspect(results.data);
  });
</pre>

The search() exposes a chainable interface that allows you to set additional search parameters such as: ip, input name, rows, start, end, etc. 
<pre>
  var util = require('util');
  
  client.search('404')
        .meta({ ip: '127.0.0.1', inputname: test })
        .context({ rows: 10 })
        .run(function (err, results) {
          // Inspect the result set
          util.inspect(results.data);
        });
</pre>

The context of the search (set using the `.context()` method) represents additional parameters in the Loggly API besides the search query itself. See the [Search API documentation][9] for a list of all options.

Metadata set using the `.meta()` method is data that is set in the query parameter of your Loggly search, but `:` delimited. For more information about search queries in Loggly, check out the [Search Language Guide][4] on the [Loggly Wiki][5].

### Facet Searching
Loggly also exposes searches that can return counts of events over a time range. These are called [facets][6]. The valid facets are 'ip', 'date', and 'input'. Performing a facet search is very similar to a normal search: 
<pre>
  var util = require('util');
  
  client.facet('ip', '404')
        .context({ rows: 10 })
        .run(function (err, results) {
          // Inspect the result set
          util.inspect(results.data);
        });
</pre>
<commit_msg>remove rows key from facet call fixes #7<commit_after># node-loggly

A client implementation for Loggly in node.js

## Installation

### Installing npm (node package manager)
<pre>
  curl http://npmjs.org/install.sh | sh
</pre>

### Installing winston
<pre>
  [sudo] npm install loggly
</pre>

## Usage

The node-loggly library is compliant with the [Loggly API][0]. Using node-loggly is easy for a variety of scenarios: logging, working with devices and inputs, searching, and facet searching.

### Getting Started
Before we can do anything with loggly, we have to create a client with valid credentials. We will authenticate for you automatically: 
<pre>
  var loggly = require('loggly');
  var config = {
    subdomain: "your-subdomain",
    auth: {
      username: "your-username",
      password: "<PASSWORD>"
    }
  };
  var client = loggly.createClient(config);
</pre>

### Logging
There are two ways to send log information to loggly via node-loggly. The first is to simply call client.log with an appropriate input token:

<pre>
  client.log('your-really-long-input-token', '127.0.0.1 - Theres no place like home', function (err, result) {
    // Do something once you've logged
  });
</pre>

Note that the callback in the above example is optional, if you prefer the 'fire and forget' method of logging:
<pre>
  client.log('your-really-long-input-token', '127.0.0.1 - Theres no place like home');
</pre>

The second way to send log information to loggly is to do so once you've retrieved an input directly from loggly:
<pre>
  client.getInput('your-input-name', function (err, input) {
    input.log('127.0.0.1 - Theres no place like home');
  });
</pre> 

Again the callback in the above example is optional and you can pass it if you'd like to.

### Logging Shallow JSON Object Literals
In addition to logging pure strings it is also possible to pass shallow JSON object literals (i.e. no nested objects) to client.log(..) or input.log(..) methods, which will get converted into the [Loggly recommended string representation][1]. So

<pre>
  var source = {
    foo: 1,
    bar: 2,
    buzz: 3
  };
  
  input.log(source);
</pre>

will be logged as: 

<pre>
  foo=1,bar=2,buzz=3
</pre>

### Searching
[Searching][3] with node-loggly is easy. All you have to do is use the search() method defined on each loggly client:
<pre>
  var util = require('util');
  
  client.search('404', function (err, results) {
    // Inspect the result set
    util.inspect(results.data);
  });
</pre>

The search() exposes a chainable interface that allows you to set additional search parameters such as: ip, input name, rows, start, end, etc. 
<pre>
  var util = require('util');
  
  client.search('404')
        .meta({ ip: '127.0.0.1', inputname: test })
        .context({ rows: 10 })
        .run(function (err, results) {
          // Inspect the result set
          util.inspect(results.data);
        });
</pre>

The context of the search (set using the `.context()` method) represents additional parameters in the Loggly API besides the search query itself. See the [Search API documentation][9] for a list of all options.

Metadata set using the `.meta()` method is data that is set in the query parameter of your Loggly search, but `:` delimited. For more information about search queries in Loggly, check out the [Search Language Guide][4] on the [Loggly Wiki][5].

### Facet Searching
Loggly also exposes searches that can return counts of events over a time range. These are called [facets][6]. The valid facets are 'ip', 'date', and 'input'. Performing a facet search is very similar to a normal search: 
<pre>
  var util = require('util');
  
  client.facet('ip', '404')
        .context({ buckets: 10 })
        .run(function (err, results) {
          // Inspect the result set
          util.inspect(results.data);
        });
</pre>

{'fraction_non_alphanumeric': 0.11411058946270214, 'fraction_numerical': 0.013171622326551904, 'mean_word_length': 3.4125431530494823, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 8, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4566256', 'n_tokens_mistral': 2354, 'n_tokens_neox': 2256, 'n_words': 983}