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

@otherguy/elysia-logging

v0.0.17

Published

A flexible logging library for Elysia.js

Downloads

443

Readme

@otherguy/elysia-logging

An advanced logging plugin designed for Elysia.js, prioritizing structured logging tailored for production environments.

npm version npm downloads Snyk Monitored GitHub Workflow Status (with event) GitHub License Code Climate Coverage CodeFactor Grade Sonar CodeSmells


🌈 Features

  • Structured Logging - Log in JSON format for easy parsing and filtering
  • Customizable - Customize the log level, formatter and logger
  • Production First - Designed for production environments first

🚀 Installation

# For bun
bun add @otherguy/elysia-logging

# For npm
npm install @otherguy/elysia-logging

# For yarn
yarn add @otherguy/elysia-logging

📚 Usage

By default, the plugin will log to the console using the console module. The default formatter is json and the default log level is info.

import { Elysia } from "elysia";
import { ElysiaLogging } from "../src/elysiaLogging";

// Create Elysia app
const app = new Elysia()
  .use(ElysiaLogging())
  .get("/", () => {
    return new Response("Welcome to Bun!");
  })
  .listen(3000);

console.log(`Running at http://${app.server?.hostname}:${app.server?.port}`);

Using the default settings, the plugin will log the following for each request. Since the console module is pretty printing the JSON, the output in the console will be formatted slightly differently.

{
  "message": "GET / completed with status 200 in 363.3µs",
  "request": {
    "ip": "127.0.0.1",
    "method": "GET",
    "url": {
      "path": "/",
      "params": {}
    }
  },
  "response": {
    "status_code": 200,
    "time": 363250
  }
}

Custom Logger

Since the console is very limited, you may want to use a custom logger. The recommended logger is pino but you can use any logger that can implement the Logger interface.

See the examples directory for implementation examples.

🪜 Examples

Even more examples are provided in the examples directory.

  • Basic - A basic example of using the plugin with the default settings
  • JSON - A basic example of logging in JSON
  • Custom Function - An example of using a function as custom logging formatter
  • On Error - An example of logging errors in addition to access logging
  • Pino - An example of using the Pino logger
  • Pino Pretty - An example of using the Pino logger with pino-pretty (not recommended for production)
  • TSLog - An example of using the TSLog logger
  • Bunyan - An example of using the Bunyan logger
  • Winston - An example of using the Winston logger

📜 To Do

  • [ ] Add logger format classes
  • [ ] Add whitelist for request parameters

⚖️ License

This project is distributed under the MIT license, allowing for open source distribution and modification, subject to the terms outlined in the LICENSE.md file.

🚧 Contributing

Bug reports, feature requests and Pull Requests are more than welcome on GitHub at otherguy/elysia-logging! Please remember to add test coverage for your code if you are contributing.

♥️ Acknowledgements