LogTape integration for Elysia #1678
dahlia
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've built an Elysia plugin that integrates LogTape, a structured logging library designed for JavaScript/TypeScript runtimes. The plugin provides HTTP request logging with a familiar Morgan-compatible API while taking advantage of LogTape's structured logging capabilities.
What is LogTape?
LogTape is a zero-dependency logging library that works across Deno, Node.js, Bun, browsers, and edge functions. It focuses on structured logging, which means instead of just logging plain text strings, you can log data as key–value pairs that are easier to search, filter, and analyze later. Think of it as bringing some of the best practices from Python's logging module to the JavaScript ecosystem.
Why use it with Elysia?
The
@logtape/elysiaplugin makes it straightforward to add HTTP request logging to your Elysia applications. You get automatic logging of requests with information like method, URL, status code, response time, and more. The plugin supports several predefined formats if you want something simple, or you can write your own format function if you need custom logging.Installation
Also available on npm, pnpm, and Yarn if needed.
Basic usage
Here's a minimal example:
This gives you request logs like:
Predefined formats
The plugin ships with Morgan-compatible formats:
"combined"(default): Full Apache Combined Log Format with structured data"common": Apache Common Log Format without referrer/user agent"dev": Concise output great for development"short": Shorter format with remote address"tiny": Minimal outputCustom formatting
You can write your own format function when you need specific logging:
Other features
The plugin includes a few other useful options:
Error logging happens automatically through Elysia's
onErrorhook, so failed requests get logged at the error level with the error message and code.Why structured logging matters
With structured logging, each request is logged as an object with properties like
method,url,status,responseTime, etc. This makes it much easier to work with logs later. You can send logs to services like Datadog or Elasticsearch, filter by status code, calculate average response times, or search for specific paths without writing complex regex patterns against text logs.Links
Let me know if you have questions or suggestions for improvements!
Beta Was this translation helpful? Give feedback.
All reactions