npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

elastic-search-rest-log

v0.3.0

Published

Logger class for logging to elastic search without any driver dependencies

Downloads

8

Readme

elastic-search-rest-log

Dependency-less http methods for pure nodejs. The motive for this project was for have a simple logger with elastic search without depending on any driver o special software.

How to install

npm install --save elastic-search-rest-log

ElasticSearchRestLogger

Logger class

Options

  • host: Url where the elastic search server is hosted. Default: localhost.
  • port: port throught which the elastic search server is exposed. Default: 9200.
  • logType: Used to create the index name. It's objective is to identify the project using the logger.
  • logIndexTemplate: The template object used to create the Elastic Search template.
  • logIndexTemplateName: Name for the template to be created on Elastic Search.
  • consoleLogger: Enables a console logger that prints on the console in parallel to the Elastic Search logging. Default: True.

Methods

  • init(): Verifies that the index and the template for the logs exist

  • getIndexName(): Obtains the log index name. By default, it follows the following format log-${this.logType}-${day}-${month}-${year}, if it does not satisfy your requirements, this method should be overriden.

  • verifyTemplateExists(): Verifies if the template exists. If not, it calls the createTemplate() method.

  • createTemplate(): Creates the elastic Search template.

  • verifyIndexExists(): Verifies if the index exists. If not, it calls the createIndex() method.

  • createIndex(): Creates the elastic Search index.

  • log(level, data): Makes a post call to create the log in elastic search. If data is a simple string, it will be included in the message property of the log. If not, it will merge data with the default logger object.

  • info(data): Alias for the log method with info as the log level.

  • warn(data): Alias for the log method with warn as the log level.

  • error(data): Alias for the log method with error as the log level.

Examples

Initialization

const ElasticSearchRestLogger = require('elastic-search-rest-log');

const logger = new ElasticSearchRestLogger(loggerOptions);
logger.init().then(() => {
    server.listen(port);
    server.on('error', onError);
    server.on('listening', () => {
        var addr = server.address();
        var bind = typeof addr === 'string' ?
            'pipe ' + addr :
            'port ' + addr.port;
        logger.info(`Listening on ${bind}`);
    });
})

Output

If the passed to the log method was a string:

{
"message": "Listening on port 3000",
"level": "info",
"timestamp": "2018-10-11T07:54:50.906Z"
}



If the passed to the log method was { "foo": "fighter", "bohemian": "rhapsody" } :
```json
{
"foo": "fighter",
"bohemian": "rhapsody",
"level": "info",
"timestamp": "2018-10-11T07:54:50.906Z"
}