Skip to content

0xrasla/logify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Logify

License: MIT

A beautiful, fast, and type-safe logging middleware for Node.js web applications. Get instant insights into your HTTP requests with colorized console output and structured file logging.

📦 Packages

This monorepo contains the following packages:

✨ Features

  • 🎨 Beautiful console output with color-coded log levels
  • ⚡ Zero-config with smart defaults
  • 📊 Request duration and status code tracking
  • 🌐 IP address logging with proxy support
  • 📝 Structured logging with TypeScript support
  • 🎯 Path-based request filtering
  • 🔄 Automatic log directory creation
  • 🎛️ Fully customizable log formats
  • 🌍 Global logger instance for application-wide logging
  • 📝 Convenient logging functions: debug(), info(), warn(), and error()

📥 Installation

Choose the package that matches your framework:

For Elysia.js

bun add @rasla/logify

For Express.js

npm install @rasla/express-logify
# or
yarn add @rasla/express-logify
# or
pnpm add @rasla/express-logify

🚀 Quick Start

Elysia.js

import { Elysia } from "elysia";
import { logger } from "@rasla/logify";

const app = new Elysia()
  .use(logger())
  .get("/", () => "Hello World!")
  .listen(3000);

Express.js

import express from "express";
import { logger } from "@rasla/express-logify";

const app = express();

app.use(logger());
app.get("/", (req, res) => res.send("Hello World!"));

app.listen(3000);

🌍 Global Logger

Both packages now include a global logger that can be accessed from anywhere in your application:

// Elysia.js
import {
  initializeLogger,
  debug,
  info,
  warn,
  error
} from "@rasla/logify";

// Express.js
import {
  initializeLogger,
  debug,
  info,
  warn,
  error
} from "@rasla/express-logify";

// Configure once at startup
initializeLogger({
  level: "debug",
  file: true,
  filePath: "./logs/app.log"
});

// Use anywhere in your code
debug("This is a debug message");
info("This is an info message");
warn("This is a warning message");
error("This is an error message");
| `{statusCode}` | HTTP status | `200`, `404` |
| `{duration}` | Request time | `123ms` |
| `{ip}` | Client IP | `127.0.0.1` |

🎯 Examples

Check out the examples in each package:

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

🎨 Configuration

Both packages support the same configuration options:

{
  // Console logging (default: true)
  console: true,

  // File logging (default: false)
  file: true,
  filePath: './logs/app.log',

  // Log level (default: "info")
  level: 'debug', // "debug" | "info" | "warn" | "error"

  // Skip certain paths
  skip: ['/health', '/metrics'],

  // Include IP address (default: false)
  includeIp: true,

  // Custom format (see Format Tokens below)
  format: '[{timestamp}] {level} [{method}] {path} - {statusCode} {duration}ms{ip}',
}

📝 Format Tokens

Customize your log format using these tokens:

Token Description Example
{timestamp} ISO timestamp 2024-12-03T17:48:54.721Z
{level} Log level INFO, ERROR
{method} HTTP method GET, POST
{path} Request path /api/users
{statusCode} HTTP status 200, 404
{duration} Request time 123ms
{ip} Client IP 127.0.0.1

🎯 Examples

Check out the examples in each package:

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

MIT License - Created by 0xRasla