LogTape: Zero-Dependency Logging for JavaScript That Just Works
Hong Minhee
Posted on August 16, 2024
Hey there, fellow developers! 👋 Are you tired of wrestling with complex logging libraries that seem to have more dependencies than your entire project? Do you dream of a logging solution that's as easy to use as it is powerful? Well, grab your favorite beverage and get comfortable, because I'm about to introduce you to LogTape—the logging library that's about to make your life a whole lot easier!
What's LogTape?
LogTape is a shiny new logging library for JavaScript and TypeScript that's designed with one goal in mind: to make logging simple, flexible, and hassle-free across all your JavaScript environments. Whether you're building applications for Deno, Node.js, Bun, edge functions, or browsers, LogTape has got you covered.
Why Should You Care?
Let's face it, logging is one of those things that every project needs, but it's rarely the star of the show. That's where LogTape comes in—it handles all the nitty-gritty details of logging so you can focus on what really matters: writing awesome code.
Here's why LogTape deserves a spot in your toolkit:
Zero Dependencies: That's right, zero. Nada. Zilch. LogTape stands on its own two feet, which means no more dependency hell for you!
Runtime Diversity: Use the same logging code everywhere. Deno, Node.js, Bun, edge functions, browsers—LogTape plays nice with all of them.
Structured Logging: Log messages with structured data for easy parsing and analysis.
Hierarchical Categories: Organize your logs with a hierarchical category system, giving you fine-grained control over log verbosity.
-
Template Literals Support: Use familiar template literals for your log messages. It's as easy as:
logger.info`Hello, ${username}! Welcome to LogTape.`;
Dead Simple Sinks: Want to add your own custom log destination? LogTape makes it a breeze!
Show Me the Code!
Alright, let's see LogTape in action. First, you'll need to set it up (don't worry, it's super easy):
import { configure, getConsoleSink } from "@logtape/logtape";
await configure({
sinks: { console: getConsoleSink() },
filters: {},
loggers: [
{ category: "my-awesome-app", level: "debug", sinks: ["console"] }
]
});
Now, let's do some logging:
import { getLogger } from "@logtape/logtape";
const logger = getLogger(["my-awesome-app", "user-service"]);
export function greetUser(username: string): void {
logger.debug`Preparing to greet ${username}`;
logger.info`Hello, ${username}! Welcome to our awesome app.`;
}
That's it! Clean, simple, and powerful logging at your fingertips.
But Wait, There's More!
LogTape isn't just about basic logging. It's packed with features that make it stand out:
- Flexible Sink System: Log to the console, files, or even create your own custom sinks.
- Rotating File Logs: Automatically rotate log files to keep things tidy.
- Fine-grained Filtering: Control exactly what gets logged and where.
- Performance-minded: Lazy evaluation options for when you need to log expensive computations.
Getting Started
Ready to give LogTape a spin? It's as easy as:
For Deno:
deno add @logtape/logtape
For Node.js:
npm add @logtape/logtape
For Bun:
bun add @logtape/logtape
Wrapping Up
LogTape is the logging library you've been waiting for—simple enough for quick projects, powerful enough for complex applications, and flexible enough to grow with your needs. It's time to say goodbye to logging headaches and hello to LogTape!
Give it a try, and let us know what you think. Happy logging, everyone! 🎉📝
Have you tried LogTape yet? What's your favorite feature? Let us know in the comments below!
Posted on August 16, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.