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

frontendlogger

v1.1.1

Published

frontendlogger is a JavaScript library for sending logs of front events and errors to a server.

Downloads

4

Readme

frontendlogger

frontendlogger is a JavaScript library for sending logs of front events and errors to a server.

This library sends logs to the server only when it catches a warning or a critical event. Logs sent to the server are composed of the last events logs.

It integrates easily with an ELK (Elasticsearch-Logstash-Kibana) stack.

Installing

The simplest way to install frontendlogger is to use npm:

npm install frontendlogger

or bower:

bower install frontendlogger

After that, you have to include it with a script tag in your HTML file:

<script src="path_to_bower_components/frontendlogger/frontendlogger.js"></script>

Configuration

setServerUrl (default: "http://10.10.10.10:8080")

To use this library, you have to set the URL of the server to which you want to send your application logs. To do that, simply use the setServerUrl command; for example:

frontendlogger.setServerUrl("http://localhost:8080");

setUser (default: {})

You can also add current user information with the setUser command, for example:

frontendlogger.setUser(user);

setMaxLengthLog (default: 30)

You can also change the default length of the stack trace with the setMaxLengthLog command, for example:

frontendlogger.setMaxLengthLog(100);

addEvent

You can also add your custom event with the addEvent command, for example:

var event = {
  message = "This is a critical event!",
  eventLevel = 2, // 0 for debug events, 1 for warning events, 2 for critical events
  eventType = "myCriticalEvent"
};
frontendlogger.addEvent(event);

frontendlogger adds automagically the current user page URL, a datetime string and the user (if defined) to your custom event.

Logstash configuration

If you want to send your application logs to Logstash, you have to use the input http plugin.

An example of Logstash configuration is the following one:

input {
  http {
    response_headers => {
      "Access-Control-Allow-Origin" => "*"
      "Access-Control-Allow-Headers" => "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"
      "Access-Control-Allow-Methods" => "*"
      "Access-Control-Allow-Credentials" => "*"
    }
    host => "10.10.10.10"
    port => 8080
  }
}
filter {
    if [logType] == "frontendlogger" {
      useragent {
          source => "userAgentUA"
          target => "UA"
      }
    }
}
output {
  elasticsearch {}
}

With this configuration, Logstash creates an HTTP server that will listen on 10.10.10.10:8080 with some custom response headers. Logstash allows you to parse the userAgent string to get information about the user browser and OS (you can find this data in the output UA object). Finally, Logstash sends logs to Elasticsearch and you can visualize this data in the Kibana platform.