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

@wedgies/koala

v0.0.8

Published

ready set log

Downloads

1

Readme

🐨

Take some logs and put 'em where we want 'em.

Koala is a small-but-opinonated logger for use in Wedgies apps. Koala was purpose built for two reasons:

  1. standardize the logging interface and usage across Wedgies apps
  2. format those logs according to specifc Wedgies needs.

Koala's features include:

  • Multiple transports
    • Console and Logstash included
  • Express middleware
    • Log requests in JSON
  • Full test suite
    • 100% coverage

Installation

$ npm install @wedgies/koala

Usage

Logging

Koala's api is simple yet powerful.

Default config

By default Koala uses the console transport. This makes it extremely easy to start using without having to deal with any configuration.

var koala = require('@wedgies/koala')

koala.log('Eucalyptus is yummy!')

In this example, 'Eucalyptus is yummy!' will be written to STDOUT.

Logstash config

Writing logs to a Logstash server is also easy with Koala.

var koala = require('@wedgies/koala').config({
  transport: ['logstash'],
  logstash: {
    host: 'koala.logs',
    port: 28777,
    constants: {
      tags: ['koala-app']
    }
  }
})

koala.log('Eucalyptus is yummy')

In this example, the logstash server will receive the followinng JSON object:

{
  "message": "Eucalyptus is yummy",
  "level": "info",
  "tags": ["koala-app"]
}

Multi-transport config

It's also possible to write logs to multiple transports at once.

var koala = require('@wedgies/koala').config({
  transport: ['console', 'logstash'],
  logstash: {
    host: 'koala.logs',
    port: 28777,
    constants: {
      tags: ['koala-app']
    }
  }
})

koala.log('Eucalyptus is yummy')

In this example, 'Eucalyptus is yummy!' will written to STDOUT and the logstash server will receive the followinng JSON object:

{
  "message": "Eucalyptus is yummy",
  "level": "info",
  "tags": ["koala-app"]
}

Express middleware

Koala includes an Express middleware logger. The middleware gathers information on each application request, bundles it up as JSON and ships it to the configured transports.

var express = require('express')
var koala = require('@wedgies/koala')

var app = express()

app.use(koala.middleware())

Now on each request, the following object will be logged:

{
  path: '/wendell',
  method: 'GET',
  statusCode: 200,
  responseTime: '0ms',
  remoteAddr: '1.1.1.1',
  userAgent: 'Chrome',
  referrer: 'dinos.com'
}

When Logstash is set as a transport, the log object will include the level field, as well as the configured constant fields.

Log levels

Koala currently includes conviences methods for two log levels, INFO and ERROR.

var koala = require('@wedgies/koala')

koala.info('Eucalyptus is yummy')
koala.error('Out of Eucalyptus! :(')

When using the console transport, these methods map to the corresponding console method. When using the Logstash transport, these methods set the "level" field to the corresponding value.

It is also possible to use custom levels:

var koala = require('@wedgies/koala')

koala.log('debug', 'Where is the Eucalyptus?')

When using the console transport, the level must be one of the console methods:

  • log
  • info
  • warn
  • error
  • dir
  • time
  • timeEnd
  • trace
  • assert

The Express middleware automatically calculates the log level based on the status code of the response. For a status code under 300, the level will be 'INFO'. Between 300 and 400, the level will be 'WARN', and over 400 the level will be 'ERROR'.

Development

Koala is written using ES2015 syntax. The source is compiled to ES5 standards during testing and distribution. The npm package contains only the compiled source for easy integration into all apps.

When working on Koala, it is recommended to run the npm run watch script. This script will look for changes and automaticaly compile the source and run tests.

When submitting a PR please follow the existing code style and add or improve tests covering the new code.

Continuous integration

Koala uses CircleCI to automatically run the test suite on new commits and PRs. The build history can be viewed at: wediges/koala.

In the future it may be useful to leverage CircleCI to automatically build and publish npm versions.

Publishing to npm

To publish a new version of Koala to npm, simply run npm version [major|minor|patch|premajor|preminor|prepatch|prerelease]. This will kick off the following tasks:

  • run npm test to verify everything is passing.
    • if any tests fail, the versioning/publishing will exit.
  • update the package.json version field.
  • create a git commit and tag with the new version.
  • run npm run build to compile the source.
  • push the version commit and tag to github
  • publish the new version to npm