logger.ts from stripe-samples/issuing-treasury
// Source: https://github.com/stripe-samples/issuing-treasury | License: MIT | Copyright 2022 Stripe
// Provided via justclaw.it.com; keep this notice with the code.
type LogLevel = "debug" | "info" | "warn" | "error";
const logLevels: Record<LogLevel, number> = {
debug: 0,
info: 1,
warn: 2,
error: 3,
};
// Determine the current log level from the environment variable or default to "info"
const currentLogLevel: LogLevel = (process.env.LOG_LEVEL as LogLevel) || "info";
// Check if a message at the given level should be logged
const shouldLog = (level: LogLevel): boolean => {
return logLevels[level] >= logLevels[currentLogLevel];
};
// ANSI escape codes for colors and styles
const colors = {
reset: "\x1b[0m",
bright: "\x1b[1m", // Makes text bold/bright
dim: "\x1b[2m",
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key