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

good-apache-log

v2.0.0

Published

Apache "combined" log files for Hapi

Downloads

8

Readme

Good-Apache-Log

Apache httpd log files for Hapi web servers

Lead Maintainer: Jason Smith

Overview

Good-Apache-Log makes Hapi write server logs in the server logs in the Apache combined or common log format, via the Good reporting framework.

The Apache format? You know: this one—the ubiquitous format every tool on the Internet can process.

127.0.0.1 - - [07/Aug/2015:14:01:21 +07:00] "GET / HTTP/1.1" 200 39 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/600.7.12 (KHTML, like Gecko) Version/8.0.7 Safari/600.7.12"
127.0.0.1 - - [07/Aug/2015:14:01:21 +07:00] "GET /favicon.ico HTTP/1.1" 200 39 "http://localhost:8080/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/600.7.12 (KHTML, like Gecko) Version/8.0.7 Safari/600.7.12"
127.0.0.1 - - [07/Aug/2015:14:01:31 +07:00] "GET /product/280 HTTP/1.1" 200 45 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.130 Safari/537.36"
127.0.0.1 - - [07/Aug/2015:14:01:31 +07:00] "GET /favicon.ico HTTP/1.1" 200 41 "http://localhost:8080/product/280" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.130 Safari/537.36"

Good-Apache-Log appends to a log file, and it it re-opens the log file when you send SIGHUP. This makes it very easy to implement log rotation, using logrotate, for example.

In other words, Good-Apache-Log makes your Hapi server a much more friendly dev-ops citizen by supporting standard logging formats and behavior.

Usage

Install this package with npm:

$ npm install good-apache-log

Place Good-Apache-Log as a reporter in your Good configuration.

var logFile = "my-server.log"
var reporters = [ {reporter:GoodApacheLog, events:{response:'*'}, config:logFile} ]
var goodPlugin = {register:Good, options:{responsePayload:true, reporters:reporters}}
server.register([goodPlugin], function(er) {
  if (!er)
    console.log('GoodApacheLog is registered.')
})

Now you will see a familiar face in my-server.log.

Note, if you set "responsePayload": true in the Good config, then your logs will show the response payload size (the %b format string). Otherwise, the payload size will be logged as -.

See test/server.js for an example of a very simple Hapi server that uses GoodApacheLog.

Configuration

Usually, you can set the reporter config value to the path to your log file, or to an existing stream (eg: console.stdout). Hapi will now automatically append logs to that file/stream, and for a file if you send a HUP signal to your server, it will re-open that file.

However, for more detailed control, config can be an object with these keys:

  • file - The path to the log file, or an existing stream
  • format - The log format to use, default is "combined"; see Log Formats below
  • separator - The separator between log lines, default is "\n"
  • hup - Boolean; if true, Good-Apache-Log will listen to SIGHUP and re-open its log file; default is true

Log Formats

Similar to the Apache httpd server, the format value allows you to specify your log file format. Either choose a "nickname" or provide your own format string.

Note Not all format strings are supported yet. If you need one, please create an issue or pull request.

For example to make a simple log file of status codes and user-agents:

var reporters = [
  {
    reporter: GoodApacheLog,
    events: {response:'*'},
    config: {file:"httpd.log", format:"%s %{User-agent}i"}
  }
]

Example log file:

200 Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:39.0) Gecko/20100101 Firefox/39.0
404 Mozilla/5.0 (iPhone; CPU iPhone OS 8_4 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12H143 Safari/600.1.4
500 Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.130 Safari/537.36
200 Mozilla/5.0 (iPhone; CPU iPhone OS 8_4 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12H143 Safari/600.1.4
301 Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.130 Safari/537.36

Supported nicknames

These nicknames, taken from from the Apache httpd documentation, expand to the most commonly-used log formats.

  • combined: %h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i"
  • common: %h %l %u %t "%r" %>s %b
  • referer: %{Referer}i -> %U