GithubHelp home page GithubHelp logo

query-logentries's Introduction

query-logentries

npm version Build Status dependencies Status devDependency Status Coverage Status

Query logentries.com via their REST API. Returns only the raw log messages you passed to logEntries at the time of logging. Supports both callback and streaming and uses request-retry-stream internally to make requests in order to be more robust in case of network glitches.

Installation

npm install --save query-logentries

Usage

How to initialize and available options:

const queryLogentriesFactory = require('query-logentries');

// Required. Replace with your API KEY
const apiKey = '6971aef7-998f-4cb2-9613-ddb42b9697b8';

// Optional. Defaults to https://rest.logentries.com/query/logs
const queryUrl = 'https://rest.logentries.com/query/logs';

const queryLogentries = queryLogentriesFactory(apiKey, queryUrl);
const opts = {
	// Required. Set it to the id of the log in logEntries you wish
	// to query
	logId: '7d9ff278-3a6d-4c7a-8e65-df89fd3f5a96',

	// Required. Set it to any valid value or stringDate that can
	//be passed to a javascript Date object
	from: '2017-01-01T00:00:00.000',

	// Optional. If empty will default to now. Set it to any valid
	// value or stringDate that can be passed to a javascript Date
	// object
	to: '2017-01-02T23:59:59.999',

	// Optional. Default to 'where()'. The leql query you wish to
	// query with. Please ensure it is a valid leql query or you
	// get statusCode 400 errors from logEntries.
	query: 'where(method=GET)',

	// Optional. Defaults to 50. How many messages should be
	// retrieved per paging request made to logEntries
	perPage: 50,

	// Optional. Defaults to 30000 (30 seconds). How long should
	//the request wait before it times out
	timeout: 30000,

	// Optional. Defaults to 3000 (3 seconds). How long should
	// this module wait when checking if a query response is
	// finished on logEntries
	pollInterval: 3000
};

After initializing, using it with callback:

queryLogentries(opts, (err, messages) => {
	if (err) {
		return; //TODO handle err
	}
	console.log('messages', messages);
});

After initializing, using it with streaming:

const pump = require('pump');
const through2 = require('through2');
const fs = require('fs');

const logEntriesStream = queryLogentries(opts);
const toStringStream = through2.obj(function(message, enc, callback) {
	this.push(JSON.stringify(message) + '\n');
	callback();
});
const toFileStream = fs.createWriteStream('./result.txt');

pump(logEntriesStream, toStringStream, toFileStream, err => {
	if (err) {
		//TODO handle err
	}
});

License

MIT

query-logentries's People

Contributors

eagleeye avatar maliarov avatar oligrand avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.