How fullstack-build/tslog works
Project Type and Purpose
• This is an open-source logging library (tslog) for TypeScript and JavaScript.
• It provides a universal API (Logger, BaseLogger) that runs in both Node.js and browser environments, outputs “pretty” or JSON logs, supports masking, custom transports, custom log levels, and sub-loggers with inheritance.
• Primary consumers are other applications or libraries that import tslog from npm.
High-Level File Structure Analysis
• src/ – Core TypeScript source code:
• BaseLogger.ts – Implements log-lifecycle steps (mask, toLogObj, addMeta, format, transport)
• Logger entry points: index.ts, index.browser.ts
• runtime/browser/ & runtime/nodejs/ – Environment-specific helpers (e.g. util.inspect.polyfill)
• Formatters, style definitions, and interfaces
• build.js, **tsconfig\*.json** – Build and packaging configuration for CJS and ESM outputs
• package.json, npmignore, .npmrc – NPM packaging and publishing settings
• docs/ – Static site for API documentation and demo screenshots
• examples/ – Live sample projects (browser, Node.js CJS/ESM, SvelteKit) showing integration
• tests/ – Jest/Puppeteer test suites verifying browser and Node.js behavior
• .github/ – CI workflow (ci.yml), code coverage, issue templates
Key Architecture Insights from README
• Lifecycle of a log message with five pluggable steps:
1. mask
2. toLogObj
3. addMetaToLogObj
4. format (pretty vs JSON)
5. transport (console, custom)
• Strategy/Plugin pattern for transports and formatters
• Support for CJS & ESM bundling with tree-shaking
• Environment adapters for browser vs Node.js specifics
• Extensibility points: override any step, attach transports, custom log object, custom levels
Main Components
a. Source Modules
• Core API (Logger, BaseLogger)
• Format & Style Engines (prettyFormatLogObj, templates, prettyLogStyles)
• Environment Runtimes (Browser adapter, Node.js adapter)
• Settings & Interfaces (ISettings, ILogObj, hooks for override)
b. Build & Packaging
• TypeScript compiler (tsconfig.cjs.json, tsconfig.esm.json)
• Bundler script (build.js)
• Outputs: CJS (package-cjs.json), ESM (src/index.ts)
• NPM registry (publish process)
c. Testing & CI
• Jest presets (jest-preset.cjs) and Puppeteer config
• Test directories for Node and Browser
• GitHub Actions workflow
d. Documentation & Examples
• Docs site generation (docs/ folder)
• Sample consumer projects under examples/
Relationships and Data Flow
• Developer writes/imports code → tslog API → calls BaseLogger.log()
• Logger.log() triggers the lifecycle pipeline (mask → toLogObj → addMeta → format → transport)
• Transport plugins send output to console, attached transports, or external services
• Build process compiles src/ into CJS and ESM bundles, runs tests, publishes to npm
• Docs generator picks up markdown and assets from docs/ → publishes to GitHub Pages
• Examples illustrate integration in real consumer environments
Architectural Patterns and Design Principles
• Strategy Pattern for transports and formatting strategies
• Template Method Pattern in the log lifecycle with overridable hooks
• Adapter Pattern for browser vs Node.js runtimes
• Builder/Fluent API for configuring logger settings and sub-loggers
• Dependency Injection of settings, transports, and default log objects
Essential Detail
• Lifecycle step and where overrides/injections happen.
• Distinguish between CJS and ESM outputs.
• Both browser and Node.js runtime flows.
• External integration points: console, file system, third-party transports (Slack, rotating file).