@arindam-stack/logify
v0.1.3
Published
Smart, configurable logger for React apps with levels, env defaults, and redaction.
Maintainers
Readme
@arindam-stack/logify
Smart, configurable logging for React applications with log levels, env-aware defaults, and optional redaction.
Install
npm install @arindam-stack/logifyUsage
import createLogger from "@arindam-stack/logify";
const log = createLogger("Auth", {
withTimestamp: true,
redactKeys: ["token"],
});
log.info("User signed in", { userId: "u_123", token: "secret" });
log.warn("Suspicious activity", { ip: "192.0.2.1" });
log.error("Login failed", { reason: "invalid_password" });API
createLogger(namespace?, options?)
Options:
enabled: boolean, defaulttruelevel:"silent" | "error" | "warn" | "info" | "debug"withTimestamp: adds ISO timestamp prefixredactKeys: array of keys to redact from object payloadsdevUx.pretty: enables styled developer-friendly console logsformatter: customize output shapesink: provide a custom console-like sinkdetectEnv: whentrue, usesNODE_ENVto choose a default level (defaultfalse)
Default level behavior when detectEnv is enabled:
NODE_ENV === "production"=>warn- otherwise =>
debug
Global Defaults
import { setLoggerDefaults } from "@arindam-stack/logify";
setLoggerDefaults({ withTimestamp: true, level: "info" });Notes
- For stable loggers, pass a stable options object (memoize in React if needed).
redactKeysperforms a shallow redaction on object payloads.
Log History Buffer
Access recent logs in memory:
const log = createLogger("App", { maxHistorySize: 100 });
log.info("Something happened");
log.error("An error", { code: 500 });
// Get all stored logs
const allLogs = log.getHistory();
// Get last 10 logs
const recent = log.getHistory(10);
// Clear history
log.clearHistory();Configuration:
maxHistorySize: Maximum number of logs to retain (default:50)
Child Logger with Context
Create scoped loggers that automatically include shared metadata:
const log = createLogger("App", { level: "debug" });
const requestLog = log.child({ requestId: "req_123", feature: "auth" });
requestLog.info("Request started");
requestLog.warn("Validation failed", { field: "email" });Behavior:
- Child logger inherits parent configuration.
- Child context is merged with object payloads.
- If both contain the same key, log-call payload value wins.
Performance Logging Helpers
Measure operation duration with built-in timer helpers:
const log = createLogger("Perf", { level: "debug" });
log.time("loadUsers");
// async work...
log.timeEnd("loadUsers", { route: "/users" });Behavior:
time(label): starts a timer for that label.timeEnd(label, data?): logs duration in ms as aninfolog.- If timer does not exist, a warning log is emitted.
Dev UX Layer
Enable styled logs for local debugging:
const log = createLogger("UI", {
withTimestamp: true,
devUx: { pretty: true },
});
log.info("Mounted", { route: "/dashboard" });Behavior:
- Adds styled namespace and level labels in console output.
- Works with existing level filtering, redaction, and history.
- Keeps plain output unless
devUx.prettyis enabled.
