Registry / observability / typescript-logging-log4ts-style

typescript-logging-log4ts-style

JSON →
library2.2.0jsnpmunverified

typescript-logging-log4ts-style is a logging library for TypeScript projects, providing a Log4TS-inspired flavor built upon the `typescript-logging` core. It allows developers to create hierarchical loggers based on unique names, often corresponding to namespaces or logical groups (e.g., 'service.Account'). The library emphasizes structured output and dynamic control over logging levels. The current stable version is 2.2.0, with regular updates incorporating new features like file logging and rollover support as seen in version 2.2.0. It differentiates itself by offering a familiar log4j-like API and configuration patterns, making it approachable for developers accustomed to enterprise logging solutions, while integrating seamlessly into modern TypeScript environments. Its modular design as a 'flavor' allows users to choose the logging style that best fits their project's needs.

npm install typescript-logging-log4ts-style
INSTALL
IMPORT
SIG · TYPESCRIPT-LOGGING
T
typescript-logging-log4ts-style
observabilityjavascriptv2.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Log4TSProvider
import { Log4TSProvider } from 'typescript-logging-log4ts-style';
const Log4TSProvider = require('typescript-logging-log4ts-style');
The library primarily uses ESM imports for its public API since version 2.x. CommonJS require() is not supported.
LogLevel
import { LogLevel } from 'typescript-logging';
import { LogLevel } from 'typescript-logging-log4ts-style';
LogLevel is part of the core `typescript-logging` package, not the style package itself.
Logger
import { Logger } from 'typescript-logging';
The `Logger` interface and type definitions are exposed by the core `typescript-logging` package, though you primarily interact with it via `provider.getLogger()`.

This quickstart demonstrates setting up a Log4TSProvider, configuring log levels and groups, creating named loggers, and using them across different modules for debugging and error logging.

/*--- config/LogConfig.ts ---*/ import { LogLevel } from "typescript-logging"; import { Log4TSProvider } from "typescript-logging-log4ts-style"; export const log4TSProvider = Log4TSProvider.createProvider("AwesomeLog4TSProvider", { level: LogLevel.Debug, groups: [{ expression: new RegExp(".+") }] }); /*--- model/Account.ts ---*/ import { log4TSProvider } from "../config/LogConfig"; const log = log4TSProvider.getLogger("model.Account"); export interface Account { name: string; } export function createAccount(name: string): Account { log.debug(() => `Creating new account with name '${name}'.`); return {name}; } /*--- service/AccountService.ts ---*/ import { log4TSProvider } from "../config/LogConfig"; import { Account } from "../model/Account"; const log = log4TSProvider.getLogger("service.AccountService"); async function someUpdateHere() { return new Promise(resolve => setTimeout(resolve, 100)); // Simulate async operation } export async function saveAccount(account: Account) { log.debug(() => `Will save account '${account.name}'.`); try { await someUpdateHere(); } catch (e) { log.error(() => `Failed to save account '${account.name}'.`, e); throw e; } } /*--- Main.ts ---*/ import { log4TSProvider } from "../config/LogConfig"; import { createAccount } from "./model/Account"; import { saveAccount } from "./service/AccountService"; // Corrected import path const log = log4TSProvider.getLogger("main"); /* Create an account and save it - log on success/error */ const account = createAccount("My Account"); saveAccount(account) .then(() => { log.debug("Successfully created account.", account.name); }) .catch(e => { log.error("Ooops...", e); });
Debug
Known issues
breakingMajor architectural changes occurred between version 1.x and 2.x of `typescript-logging`. Code written for 1.x is not directly compatible with 2.x and requires a migration.
fix
Refer to the migration guide available in the `typescript-logging` repository for 1.x releases (e.g., `https://github.com/vauxite-org/typescript-logging/tree/release-1.x`) and rewrite logging configuration and calls for the 2.x API.
affects: >=2.0.0
gotchaThe `typescript-logging-log4ts-style` package is an add-on 'flavor' and requires the core `typescript-logging` package to be installed as a separate dependency.
fix
Always install both packages: `npm install --save typescript-logging typescript-logging-log4ts-style`.
affects: >=1.0
gotchaThe `LogLevel.Off` enumeration was introduced in version 2.1.0. While minor, there is a small chance this could affect existing code if custom log level handling or comparisons were in place.
fix
Review existing code that interacts directly with `LogLevel` values or performs custom comparisons to ensure compatibility with the new `LogLevel.Off` value.
affects: >=2.1.0
gotchaTo enable file logging and rollover support, the separate `typescript-logging-node-channel` package must be installed and configured in addition to the core and style packages.
fix
Install `npm install --save typescript-logging-node-channel` and consult its documentation for configuration details to enable file output.
affects: >=2.2.0
Errors
Common errors & fixes
Cannot find module 'typescript-logging-log4ts-style' or its corresponding type declarations.
The package was not installed or installed incorrectly, or TypeScript cannot locate its types.
fix
Ensure both `typescript-logging` and `typescript-logging-log4ts-style` are installed: `npm install --save typescript-logging typescript-logging-log4ts-style`.
TypeError: Cannot read properties of undefined (reading 'getLogger')
The `log4TSProvider` was not initialized or imported correctly, leading to an attempt to call a method on an `undefined` object.
fix
Verify that `Log4TSProvider.createProvider` is called before any `getLogger` calls, and that the provider object is correctly exported and imported across modules.
Logging statements (e.g., `log.debug()`) are not appearing in the console or output.
The configured `LogLevel` for the provider or a specific group is set too high (e.g., `LogLevel.Error`), effectively filtering out lower-level messages.
fix
Adjust the `level` property in your `Log4TSProvider` configuration (e.g., to `LogLevel.Debug` or `LogLevel.Trace`) and ensure group expressions match your logger names.
ReferenceError: require is not defined in ES module scope
Attempting to use CommonJS `require()` syntax in an ESM project, or trying to import an ESM-only library with `require()`.
fix
Use ES Module `import` syntax (e.g., `import { Log4TSProvider } from 'typescript-logging-log4ts-style';`) and ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json`).
Upgrade
Version history
2.2.0latest on npm
Audit
Dependencies
typescript-loggingrequiredCore logging library; this package provides the Log4TS style on top of it.
Agent activity
21 hits · last 30 days
node
20
OpenAI (training)
1
Resources
typescript-logging-log4ts-style — npm install typescript-logging-log4ts-style · libregistry