Registry /
observability / typescript-logging-category-style
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
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
LogLevel
✓ import { LogLevel } from 'typescript-logging';
✗ import { LogLevel } from 'typescript-logging-category-style';
LogLevel is part of the core `typescript-logging` package, not the style package.
CategoryProvider
✓ import { CategoryProvider } from 'typescript-logging-category-style';
✗ const { CategoryProvider } = require('typescript-logging-category-style');
Primary way to configure and retrieve categories. While CommonJS might work with transpilation, ESM imports are the idiomatic approach for this TypeScript-first library.
Category
✓ import { Category } from 'typescript-logging-category-style';
✗ import { Category } from 'typescript-logging';
Represents a logger instance within the topological structure, belonging to the specific category style.
Demonstrates configuring a `CategoryProvider`, creating root and child categories, and logging messages at different levels, including error handling, to build a hierarchical logging structure.
import {LogLevel} from "typescript-logging";
import {CategoryProvider, Category} from "typescript-logging-category-style";
// --- Configuration (LogConfig.ts logic) ---
const provider = CategoryProvider.createProvider("ExampleProvider", {
level: LogLevel.Debug,
// Optional: Add a simple appender for console output if not already configured globally
// appenders: { default: { type: 'console' } }
});
// Create some root categories for this example
const rootModel = provider.getCategory("model");
const rootService = provider.getCategory("service");
const rootMain = provider.getCategory("main");
// --- Model (Account.ts logic) ---
const modelLog = rootModel.getChildCategory("Account");
interface Account {
name: string;
}
function createAccount(name: string): Account {
modelLog.debug(() => `Creating new account with name '${name}'.`);
return {name};
}
// --- Service (AccountService.ts logic) ---
const serviceLog = rootService.getChildCategory("AccountService");
// Mock function for demonstration
async function someExternalApiCall(): Promise<void> {
return new Promise(resolve => setTimeout(resolve, 50)); // Simulate async work
}
async function saveAccount(account: Account) {
serviceLog.debug(() => `Will save account '${account.name}'.`);
try {
await someExternalApiCall();
serviceLog.info(() => `Account '${account.name}' saved successfully.`);
}
catch (e) {
serviceLog.error(() => `Failed to save account '${account.name}'.`, e);
throw e;
}
}
// --- Main Application Logic (Main.ts logic) ---
(async () => {
rootMain.info(() => "Application starting...");
const newAccount = createAccount("JaneDoe");
try {
await saveAccount(newAccount);
} catch (error) {
rootMain.error(() => "Error during account operations.", error);
}
rootMain.info(() => "Application finished.");
})();
Errors
Common errors & fixes
Error: Cannot find module 'typescript-logging' or 'typescript-logging-category-style'
One of the required packages (`typescript-logging` or `typescript-logging-category-style`) is not installed.
fixRun `npm install --save typescript-logging typescript-logging-category-style` to install both packages.
TypeError: (0 , typescript_logging_1.CategoryProvider).createProvider is not a function
This error typically occurs when trying to use CommonJS `require()` syntax with an ES Module, or if the module is not correctly imported/transpiled in your environment (e.g., Node.js without proper ESM setup or bundler issues).
fixEnsure you are using ES Module `import` syntax (`import { CategoryProvider } from 'typescript-logging-category-style';`) and that your project is configured for ESM, especially in Node.js environments (e.g., `"type": "module"` in `package.json`). No log messages appear in the console/output.
The configured log level for a `CategoryProvider` or individual `Category` is too high, or no appender is configured to process the log events.
fixCheck the `level` option in `CategoryProvider.createProvider` (e.g., `level: LogLevel.Debug`). Ensure at least one appender is configured for your `CategoryProvider` or globally in `typescript-logging` to output logs (e.g., a console appender).
Audit
Dependencies
typescript-loggingrequiredCore logging functionality; required peer dependency for all `typescript-logging` style packages.