
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@plandek-utils/logging
Advanced tools
TypeScript utils for Logging. Includes prettifying of JSON, logging utils, and colour utils.
TypeScript utils for Logging. Includes prettifying of JSON, logging utils, and colour utils.
npm install @plandek-utils/logging
prettyJSON and colorPrettyJSON or colourPrettyJSONimport { prettyJSON } from "@plandek-utils/logging";
const obj = { name: "John", age: 30 };
console.log(prettyJSON(obj)); // OUTPUT: {\n "name": "John",\n "age": 30\n}
import { colorPrettyJSON } from "@plandek-utils/logging";
const obj = { name: "John", age: 30 };
console.log(colorPrettyJSON(obj));
output:
"\x1b[90m{\x1b[39m\x1b[90m\n" +
' \x1b[39m\x1b[35m"name"\x1b[39m\x1b[90m:\x1b[39m\x1b[90m \x1b[39m\x1b[33m"John"\x1b[39m\x1b[90m,\x1b[39m\x1b[90m\n' +
' \x1b[39m\x1b[35m"age"\x1b[39m\x1b[90m:\x1b[39m\x1b[90m \x1b[39m\x1b[32m30\x1b[39m\x1b[90m\n' +
"\x1b[39m\x1b[90m}\x1b[39m"
You can use colorPrettyJSON or colourPrettyJSON (alias).
makeColourUtils(mode: "with-colour" | "plain"): LogColourUtilsCreates a utility object for colouring log messages using CHALK.
import { makeColourUtils } from "@plandek-utils/logging";
const colorUtils = makeColourUtils("with-colour");
console.log(colorUtils.blue("Hello"));
const plainColorUtils = makeColourUtils("plain");
console.log(plainColorUtils.blue("Hello")); // Output: Hello as is.
buildPinoLogger(level: LevelWithSilent, redactPaths?: string[]): PreparedLoggerbuildSinkLogger(level: LevelWithSilent, bindings?: PlainObject): PreparedLoggerparseLogLevelOrDefault(x: string): LogLevelCreates a Pino logger with common configuration.
import { buildPinoLogger, buildSinkLogger, parseLogLevelOrDefault } from "@plandek-utils/logging";
const level = parseLogLevelOrDefault(process.env.LOG_LEVEL, "info"); // gets the log level if present, otherwise info. If the LOG_LEVEL is not a valid one it will throw.
const logger = buildPinoLogger(level, ["req.headers.authorization"]);
const testLogger = buildSinkLogger(level); // does not send any log -> useful for tests.
logger.info({ req: { headers: { authorization: "Bearer token" } } }, "User logged in");
// {"level":30,"time":"2024-10-28T11:10:58.250Z","pid":18166,"hostname":"044ce1509ebe","req":{"headers":{"authorization":"[REDACTED]"}},"msg":"User logged in"}
logger.info("Hi!");
// {"level":30,"time":"2024-10-28T11:12:48.732Z","pid":18166,"hostname":"044ce1509ebe","msg":"Hi!"}
makeLoggingimport { makeLogging } from "@plandek-utils/logging";
const logger = buildPinoLogger("info");
const logging = makeLogging({ logger, section: "api" });
logging.info("User logged in", { userId: 123 });
// {"level":30,"time":"2024-10-28T11:14:13.519Z","pid":18166,"hostname":"044ce1509ebe","logSections":["api"],"userId":123,"msg":"User logged in"}
logging.withSection("database").debug("Query executed");
// no output since `debug` is not enabled in the logger
logging.withSection("database").error("Query failed");
// {"level":50,"time":"2024-10-28T11:14:59.509Z","pid":18166,"hostname":"044ce1509ebe","logSections":["api"],"logSections":["api","database"],"msg":"Query failed"}
makeLoggingWithRecordSame as makeLogging, but keeping an in-memory record of all messages (and contexts) sent. This is meant for testing
purposes.
import { makeLoggingWithRecord, type PreparedLogger } from "@plandek-utils/logging";
const logger: PreparedLogger = buildPinoLogger("info");
const loggingWithRecords = makeLoggingWithRecord({ logger, section: "api" });
loggingWithRecords.info("User logged in", { userId: 123 });
// {"level":30,"time":"2024-10-28T11:16:49.607Z","pid":18166,"hostname":"044ce1509ebe","logSections":["api"],"userId":123,"msg":"User logged in"}
console.log(loggingWithRecords.messages.info);
// [ [ "User logged in", { userId: 123 } ] ]
This package is developed with TypeScript and uses Vitest for testing.
npm run build: build the packagenpm test: run testsnpm run test:watch: run tests in watch modenpm run test:coverage: run tests with coveragenpm run lint: lint filesnpm run format: format filesMIT License - see LICENSE file
FAQs
TypeScript utils for Logging. Includes prettifying of JSON, logging utils, and colour utils.
We found that @plandek-utils/logging demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.