cenglu

Installation

Install and set up cenglu in your Node.js project

Installation

Requirements

Cenglu requires Node.js 18.0.0 or higher. It works with any modern Node.js runtime including:

  • Node.js (18+)
  • Bun
  • Deno (with Node compatibility)

Package Manager

Install cenglu using your preferred package manager:

npm install cenglu
yarn add cenglu
pnpm add cenglu
bun add cenglu

Verify Installation

Create a simple test file to verify the installation:

test-logger.ts
import { createLogger } from "cenglu";

const logger = createLogger({
  service: "test-app",
  level: "info",
});

logger.info("Cenglu installed successfully!", { version: "2.2.0" });

Run the file:

node test-logger.ts
# or
bun test-logger.ts

You should see output similar to:

{"time":1704067200000,"level":"info","msg":"Cenglu installed successfully!","context":{"version":"2.2.0"},"service":"test-app"}

TypeScript Configuration

Cenglu is written in TypeScript and includes comprehensive type definitions. For the best experience, ensure your tsconfig.json includes:

tsconfig.json
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "ES2022",
    "moduleResolution": "bundler",
    "strict": true,
    "esModuleInterop": true,
    "types": ["node"]
  }
}

Import Paths

Cenglu exports different modules through subpath imports:

// Core logger
import { createLogger, Logger } from "cenglu";

// Middleware
import { expressMiddleware } from "cenglu/middleware";
import { nestjsMiddleware } from "cenglu/middleware";

// Plugins
import { samplingPlugin, rateLimitPlugin } from "cenglu/plugins";

// Transports
import { createFileTransport, createConsoleTransport } from "cenglu/transports";

// Redaction
import { createRedactor, createPCIRedactor } from "cenglu/redaction";

// Context utilities
import { withContext, createRequestContext } from "cenglu/context";

// Format utilities
import { formatEcs, formatDatadog } from "cenglu/format";

Bundle Size

Cenglu is designed to be lightweight with zero external dependencies:

  • Production bundle: < 500KB
  • Tree-shakeable: Only import what you use
  • No transitive dependencies: No hidden dependency bloat

Check bundle size in your project:

npm install -g size-limit
size-limit

On this page