Agent skill
typescript-winston-setup
Install, repair, and verify Winston logging in NestJS TypeScript backends with ConfigService-driven settings, DI-based logger wiring, and deterministic development/production outputs. Use when users ask to add Winston, replace Nest default logging, fix broken structured logs, or standardize JSON file logging behavior.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/typescript-winston-setup
SKILL.md
Setup Winston For NestJS
Use this workflow to install or repair Winston-backed logging in a NestJS application.
Prerequisites
- Existing NestJS TypeScript backend with
AppModuleandmain.ts - Node.js 20 or later
- Package manager available (
npm,pnpm, oryarn)
Step 1: Preflight checks
- Confirm the project root contains
package.json. - Confirm Nest entry files exist:
src/app.module.tsandsrc/main.ts. - If either file is missing, stop and ask for the correct Nest app path.
- Check whether
@nestjs/configis already installed.
Step 2: Install required packages
Install winston with the active package manager:
npm:npm install winstonpnpm:pnpm add winstonyarn:yarn add winston
If @nestjs/config is missing, install it:
npm:npm install @nestjs/configpnpm:pnpm add @nestjs/configyarn:yarn add @nestjs/config
Do not install @types/winston because Winston v3 ships TypeScript types.
Step 3: Add logger implementation files
Create the logger library under src/libs/logger/:
src/libs/logger/logger.module.tssrc/libs/logger/logger.service.ts
Use the implementation in reference.md. It provides:
- Required env validation for
LOGGER_LEVEL,LOGGER_SERVICE_NAME, andLOGGER_PATH - Pretty colorized console logs in development
- JSON console logs in production
- JSON file transports:
combined.loganderror.log - Exception and rejection transports:
exceptions.logandrejections.log OnModuleDestroycleanup (exceptions.unhandle(),rejections.unhandle(),logger.close())- Automatic log-directory creation
Step 4: Wire logger into Nest
- Add
LoggerModuletoAppModule.imports. - Ensure
ConfigModule.forRoot({ isGlobal: true })is present (or importConfigModulewhere needed). - In
main.ts, set the application logger after app creation:
const app = await NestFactory.create(AppModule);
app.useLogger(app.get(LoggerService));
- If
moduleResolutionisnodenextornode16, use.jsextensions in relative runtime imports (for example./logger.service.js).
Step 5: Configure environment variables
Create or update .env:
LOGGER_LEVEL=info
LOGGER_SERVICE_NAME=my-service
LOGGER_PATH=logs
Rules:
NODE_ENV=productionmust be set in production to enable JSON console format.- Add
logs/to.gitignoreif log files should not be committed.
Step 6: Verify behavior
- Start the app with the repository's dev command (for example,
npm run start:dev). - In development (
NODE_ENVnot production), confirm readable colorized console output. - In production mode, confirm JSON console output.
- Confirm files are created under
LOGGER_PATH:combined.logerror.log
- Trigger one uncaught exception and one unhandled rejection in a safe local run, then confirm:
exceptions.logrejections.log
If verification fails, check import paths, missing env values, and whether LoggerModule is imported by AppModule.
Deterministic checklist
- Pass preflight checks (Nest files + package manager + target path)
- Install
winstonand@nestjs/configwhen missing - Add
LoggerModuleandLoggerServicefrom reference.md - Ensure
LoggerServiceimplementsOnModuleDestroycleanup for Winston handlers - Import
LoggerModuleand configureConfigModuleusage - Call
app.useLogger(app.get(LoggerService))inmain.ts - Set
LOGGER_LEVEL,LOGGER_SERVICE_NAME, andLOGGER_PATHin.env - Verify development, production, file, exception, and rejection logging outputs
Additional resources
Full implementation snippets: reference.md
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?