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

@malijs/logger

v0.6.0

Published

Development logging middleware for Mali

Downloads

453

Readme

@malijs/logger

npm version Tests

Development style logger middleware for Mali.

--> GetFeature unary
--> GetFeature unary
<-- GetFeature unary 22ms
<-- GetFeature unary 32ms
--> ListFeatures response_stream
<-- ListFeatures response_stream 21ms
--> RecordRoute request_stream
<-- RecordRoute request_stream 10s
--> RouteChat duplex
<-- RouteChat duplex 10ms

Installation

$ npm install @malijs/logger

Example

import logger from '@malijs/logger'
import Mali from 'mali'

const app = new Mali(path.resolve(__dirname, './helloworld.proto'), 'Greeter')
app.use(logger())
app.use({
  sayHello: ({ res, req }) => (res = `Hello ${req.name}`)
})
app.start('0.0.0.0:50051')

API

logger(options)

options.fullName

To log full name (fullName) from context, otherwise logs just the name. Default: false.

app.use(logger({ fullName: true }))

Output:

--> /routeguide.RouteGuide/GetFeature unary
<-- /routeguide.RouteGuide/GetFeature unary 22ms

options.timestamp

Enables or disables the inclusion of a timestamp in the log message. If a function is supplied, it is passed a Date timestamp and it must synchronously return the string representation to be logged. There are predefined timestamp functions: epochTime (default), unixTime, and isoTime.

Default timestamp:

app.use(logger({timestamp: true}))

Output:

--> 1556325859071 GetFeature unary
<-- 1556325859071 GetFeature unary 6ms

With custom predefined timestamp:

app.use(logger({timestamp: logger.isoTime}))

Output:

--> 2019-04-27T00:44:19.083Z GetFeature unary
<-- 2019-04-27T00:44:19.083Z GetFeature unary 4ms

With custom timestamp function:

app.use(logger({ timestamp: date => `${date.toDateString()} ${date.toLocaleTimeString()}` }))

Output:

--> Fri Apr 26 2019 9:44:19 PM GetFeature unary
<-- Fri Apr 26 2019 9:44:19 PM GetFeature unary 18ms

Timestamp functions

  • logger.epochTime - Milliseconds since Unix epoch. Default. Used when timestamp: true.
  • logger.unixTime - Seconds since Unix epoch.
  • logger.isoTime - Timestamp in ISO time.

options.request

Enables or disables the inclusion of request in the log message. By default JSON.stringify is used. If a function is supplied it is passed the request from the context.

app.use(logger({ request: true }))

Output:

--> GetFeature {"latitude":409146138,"longitude":-746188906} unary
<-- GetFeature unary 2ms

options.response

Enables or disables the inclusion of response in the log message. By default JSON.stringify is used. If a function is supplied it is passed the response from the context.

app.use(logger({ response: true }))

Output:

--> GetFeature unary
<-- GetFeature {"location":{"latitude":409146138,"longitude":-746188906},"name":"Berkshire Valley Management Area Trail, Jefferson, NJ, USA"} unary 3ms

With custom request and response logging functions:

app.use(logger({ 
  request: req => `(${req.latitude}, ${req.longitude})`,
  response: res => `[${res.name}]`
}))

Output:

--> GetFeature (409146138, -746188906) unary
<-- GetFeature [Berkshire Valley Management Area Trail, Jefferson, NJ, USA] unary 4ms

Notes

Recommended that you .use() this middleware near the top to "wrap" all subsequent middleware.

License

Apache 2.0