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 🙏

© 2025 – Pkg Stats / Ryan Hefner

slogged

v1.1.1

Published

socket.io logger middleware inspired by koa-logger

Readme

Slogged

socket.io logger middleware inspired by koa-logger

MIT License XO code style

What is it?

Slogged is a basic logger middleware for socket.io that modifies the Socket class to output colorful logging to display information about client events, acks, emits, and errors. For the appearance it takes koa-logger as an inspiration.

Usage

$ npm install slogged

Then in your io.js (or wherever you're instantiating socket.io),

const io = require('socket.io')()
const slogger = require('slogged')

io.use(slogger())

io.on('connection', (socket) => {
  // ...
})

Types of logs

There are essentially four different types of logs: client events, emit events, acks, and errors.

Client events use <--, emit events use >>>, acks and errors both use --> as those are sent back to the originating client.

Acks and errors also report the overall time taken from the time the server received the packet to when the ack or error is sent back to the client. In addition, the overall connection time for the client is reported on disconnect events.

By default, payloads (both from client events and emits), acks, and error callstacks are included in the logs, but there is an option to disregard this data in the logs. See below.

For emits, if the broadcast flag is added, then the log will also add the client id that initiated the emit.

Finally, an important note about using acks and error logs is that the logging assumes you are using a standard Connect-like signature, with an error as the first argument, followed by the data to ack. If the first argument is not null then slogged will log it as an error. This is how it knows to log an error instead of a successful ack, since under the hood they are both triggered in the socket event's ack.

ack(null, { success: true }) // CORRECT! Will be logged as an OK ack
ack({ success: true }) // WRONG! Will be logged as an ERROR
ack(new Error(), null) // CORRECT! Will be logged as an ERROR

Make sense?

Options

Currently there are two options,

{
  minimal: false, // Set to true to ignore payloads, ack data, and error call stacks
  boring: false // Set to true to log plain jane, uncolorized text
}

Examples

With minimal === false

[socket.io] <-- connection Rquzt8syTkGjMZzyAAAB
[socket.io] <-- join Rquzt8syTkGjMZzyAAAB "[email protected]"
[socket.io] <-- join Rquzt8syTkGjMZzyAAAB "1b9ie86u62"
[socket.io] <-- update-user Rquzt8syTkGjMZzyAAAB {"username":"[email protected]","body":{"currentList":"1b9ie86u62"}}
[socket.io] >>> updated [email protected] broadcast by Rquzt8syTkGjMZzyAAAB {"_id":"58c5658f0a3d0025673bdf89","darkmode":true,"username":"[email protected]","currentList":"1b9ie86u62"}
[socket.io] --> update-user Rquzt8syTkGjMZzyAAAB OK 12ms {"_id":"58c5658f0a3d0025673bdf89","darkmode":true,"username":"[email protected]","currentList":"1b9ie86u62"}
[socket.io] <-- create-item Rquzt8syTkGjMZzyAAAB {"listid":"1b9ie86u62","item":{"_id":"b2oo811us1","item":"Do something","createdBy":"[email protected]","complete":false,"dateCreated":"2017-06-21T14:21:29.182Z","dueDate":null,"dateCompleted":null,"completedBy":"","notes":"","_dueDateDifference":null,"_deleting":false,"_detailsToggled":false},"username":"[email protected]"}
[socket.io] --> create-item Rquzt8syTkGjMZzyAAAB ERR 2ms ERRROOOOOR
Error: ERRROOOOOR
    at Object.create (/Users/patrick/Projects/taskmastr/routes/items.js:10:11)
    at Socket.socket.on (/Users/patrick/Projects/taskmastr/io.js:96:18)
    at emitTwo (events.js:125:13)
    at Socket.emit (events.js:213:7)
    at /Users/patrick/Projects/taskmastr/node_modules/socket.io/lib/socket.js:514:12
    at _combinedTickCallback (internal/process/next_tick.js:95:7)
    at process._tickCallback (internal/process/next_tick.js:161:9)

With minimal === true

[socket.io] <-- connection Rquzt8syTkGjMZzyAAAB
[socket.io] <-- join Rquzt8syTkGjMZzyAAAB "[email protected]"
[socket.io] <-- join Rquzt8syTkGjMZzyAAAB "1b9ie86u62"
[socket.io] <-- update-user Rquzt8syTkGjMZzyAAAB 
[socket.io] >>> updated [email protected] broadcast by Rquzt8syTkGjMZzyAAAB
[socket.io] --> update-user Rquzt8syTkGjMZzyAAAB OK 12ms 
[socket.io] <-- create-item Rquzt8syTkGjMZzyAAAB
[socket.io] --> create-item Rquzt8syTkGjMZzyAAAB ERR 2ms ERRROOOOOR

License

Slogged is freely distributable under the terms of the MIT license.