{"id":12242,"library":"typescript-logging","title":"TypeScript Logging Core","description":"TypeScript Logging is a core library designed for adding robust logging capabilities to both web and Node.js projects. It is currently at version 2.2.0 and is actively maintained, with minor releases adding new features such as file logging and rollover support via the `typescript-logging-node-channel` package. This package serves as the foundation; users must also install a specific 'flavor' package (e.g., `typescript-logging-category-style` or `typescript-logging-log4ts-style`) to gain concrete logging implementations and APIs. Version 2.x, a complete rewrite, is not compatible with version 1.x. Key differentiators include offering two distinct API styles: a hierarchical, category-based approach and a style mimicking Log4j/log4ts for familiarity, providing flexibility for different development preferences.","status":"active","version":"2.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/vauxite-org/typescript-logging","tags":["javascript","typescript-logging","typescript logging","typescript-logging core","typescript logger","log4ts","log4ts-like","category","category-like","typescript"],"install":[{"cmd":"npm install typescript-logging","lang":"bash","label":"npm"},{"cmd":"yarn add typescript-logging","lang":"bash","label":"yarn"},{"cmd":"pnpm add typescript-logging","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for the category-style logging API implementation.","package":"typescript-logging-category-style","optional":false},{"reason":"Required for the log4ts-style logging API implementation.","package":"typescript-logging-log4ts-style","optional":false},{"reason":"Optional: Provides file logging and rollover support specifically for Node.js environments.","package":"typescript-logging-node-channel","optional":true}],"imports":[{"note":"Core enum for defining logging thresholds. The library is primarily designed for ESM usage in v2+.","wrong":"const { LogLevel } = require('typescript-logging');","symbol":"LogLevel","correct":"import { LogLevel } from 'typescript-logging';"},{"note":"Essential classes for setting up and utilizing the category-style hierarchical logging API. ESM-first.","wrong":"import CategoryProvider from 'typescript-logging-category-style';\nconst { Category } = require('typescript-logging-category-style');","symbol":"CategoryProvider, Category","correct":"import { CategoryProvider, Category } from 'typescript-logging-category-style';"},{"note":"Primary classes for configuring and using the log4ts-compatible logging API. ESM-first.","wrong":"import Logger from 'typescript-logging-log4ts-style';\nconst { Log4TSProvider } = require('typescript-logging-log4ts-style');","symbol":"Log4TSProvider, Logger","correct":"import { Log4TSProvider, Logger } from 'typescript-logging-log4ts-style';"}],"quickstart":{"code":"/*--- LogConfig.ts ---*/\nimport {CategoryProvider, Category} from \"typescript-logging-category-style\";\n\nconst provider = CategoryProvider.createProvider(\"ExampleProvider\");\n\nexport function getLogger(name: string): Category {\n  return provider.getCategory(name);\n}\n\n/*--- Person.ts ---*/\nimport {getLogger} from \"./LogConfig\";\n\n/* Root categories can and probably will be defined elsewhere, this is just an example */\nconst logModel = getLogger(\"model\");\n\n/* Create child categories based on a parent category, effectively allowing you to create a tree of loggers when needed */\nconst logPerson = logModel.getChildCategory(\"Person\");\n\nfunction example(value: string) {\n  logPerson.debug(() => `Example function called with value ${value}`);\n  try {\n    // Awesome code here...\n    logPerson.getChildCategory(\"example()\").debug(() => \"Child category again\");\n  }\n  catch (e: any) {\n    logPerson.error(() => \"Awesome code failed unexpectedly\", e);\n  }\n  finally {\n    logPerson.debug(() => \"Example function completed\");\n  }\n}\n\n// Example usage call\nexample(\"test-value\");","lang":"typescript","description":"Demonstrates how to configure the Category-style logging provider and obtain hierarchical loggers for different modules, logging messages at various levels."},"warnings":[{"fix":"Refer to the migration guide in the package documentation (`/migration` section) and update all logging logic to conform to the new v2 API structure. This typically involves updating imports and logger initialization.","message":"Version 2.x of `typescript-logging` is a complete rewrite and is not backward compatible with version 1.x APIs. Existing code using v1 will break.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Install your preferred flavor package (e.g., `npm install --save typescript-logging-category-style`) and follow its documentation to set up the logging provider and obtain logger instances.","message":"The `typescript-logging` core package provides only interfaces and basic types. To get functional logging, you must install and configure a specific 'flavor' package (e.g., `typescript-logging-category-style` or `typescript-logging-log4ts-style`) alongside the core library.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Review any log level configurations that might be impacted by the introduction of `LogLevel.Off`. Explicitly use `LogLevel.Off` where logging should be completely disabled, or other specific levels for active logging.","message":"The `LogLevel.Off` value was introduced in version 2.1.0. While it provides an explicit way to disable logging for a category, it might subtly alter behavior or require adjustments in existing configurations that implicitly handled disabled logging.","severity":"deprecated","affected_versions":">=2.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure you are importing the provider from the correct 'flavor' package, e.g., `import {CategoryProvider} from 'typescript-logging-category-style';` and that the flavor package is installed.","cause":"Attempting to instantiate a logging provider (e.g., CategoryProvider or Log4TSProvider) directly from the `typescript-logging` core package, which only exports interfaces and not concrete implementations.","error":"TypeError: Cannot read properties of undefined (reading 'createProvider')"},{"fix":"Install the required flavor package using npm: `npm install --save typescript-logging-category-style` (or your chosen flavor) and verify the import statement correctly references the package name and export.","cause":"The specific logging flavor package (e.g., `typescript-logging-category-style` or `typescript-logging-log4ts-style`) has not been installed, or the import path is incorrect.","error":"Module not found: Can't resolve 'typescript-logging-category-style'"}],"ecosystem":"npm"}