DEV Community

Cover image for LogTape: Zero-Dependency Logging for JavaScript That Just Works
Hong Minhee
Hong Minhee

Posted on • Edited on

LogTape: Zero-Dependency Logging for JavaScript That Just Works

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:

  1. Zero Dependencies: That's right, zero. Nada. Zilch. LogTape stands on its own two feet, which means no more dependency hell for you!

  2. Runtime Diversity: Use the same logging code everywhere. Deno, Node.js, Bun, edge functions, browsers—LogTape plays nice with all of them.

  3. Structured Logging: Log messages with structured data for easy parsing and analysis.

  4. Hierarchical Categories: Organize your logs with a hierarchical category system, giving you fine-grained control over log verbosity.

  5. Template Literals Support: Use familiar template literals for your log messages. It's as easy as:

     logger.info`Hello, ${username}! Welcome to LogTape.`;
    
  6. 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"] }
  ]
});
Enter fullscreen mode Exit fullscreen mode

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.`;
}
Enter fullscreen mode Exit fullscreen mode

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:

Getting Started

Ready to give LogTape a spin? It's as easy as:

For Deno:

deno add jsr:@logtape/logtape
Enter fullscreen mode Exit fullscreen mode

For Node.js:

npm add @logtape/logtape
Enter fullscreen mode Exit fullscreen mode

For Bun:

bun add @logtape/logtape
Enter fullscreen mode Exit fullscreen mode

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!

Top comments (1)

Collapse
 
reggi profile image
Tea Reggi

Congrats on your first article! 🎉