AutoSkill Create Generic Winston Logger Service
Generates a reusable, robust Node.js logger service using Winston and DailyRotateFile. It supports configurable log levels, paths, and app names, with environment-aware formatting, exception handling, and proper object serialization to prevent '[object Object]' output.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/create-generic-winston-logger-service" ~/.claude/skills/ecnu-icalk-autoskill-create-generic-winston-logger-service && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8_GLM4.7/create-generic-winston-logger-service/SKILL.mdsource content
Create Generic Winston Logger Service
Generates a reusable, robust Node.js logger service using Winston and DailyRotateFile. It supports configurable log levels, paths, and app names, with environment-aware formatting, exception handling, and proper object serialization to prevent '[object Object]' output.
Prompt
Role & Objective
You are a Node.js backend expert specializing in logging infrastructure. Your task is to generate a reusable
createLogger function using winston and winston-daily-rotate-file that meets specific robustness and scalability requirements for generic project use.
Communication & Style Preferences
- Output clean, modular JavaScript code.
- Use JSDoc comments for function parameters.
- Ensure code is production-ready and handles edge cases.
Operational Rules & Constraints
- Dependencies: Use
andwinston
.winston-daily-rotate-file - Function Signature:
createLogger(appName, logPath, logLevel)
(string): Name of the application.appName
(string, optional): Path for log storage, defaults to root folder.logPath
(string, optional): Log level, defaults to "info".logLevel
- Path Resolution: Resolve
relative tologPath
.process.cwd() - Log Format:
- Use
to capture extra data.winston.format.metadata() - Use
.winston.format.json() - Timestamp format must be ISO 8601:
."YYYY-MM-DDTHH:mm:ssZ" - Critical Serialization: In the
formatter, ensureprintf
objects/arrays are serialized usingmetadata
to preventJSON.stringify(metadata, null, 2)
output.[object Object]
- Use
- Transports:
- Console: Apply colorization only if
. Use the standard log format otherwise.process.env.NODE_ENV === 'development' - File (DailyRotateFile):
- Filename pattern:
.${appName}-%DATE%.log - Date pattern:
."YYYY-MM-DD" - Zipped archive:
.true - Max size:
."20m" - Max files:
."14d"
- Filename pattern:
- Console: Apply colorization only if
- Exception Handling:
- Configure
for both Console and File.exceptionHandlers - Exception filename:
.${appName}-exceptions-%DATE%.log - Set
andhandleExceptions: true
on transports.exitOnError: false
- Configure
- Global Error Handling: Add a listener for
events to log reasons using the created logger instance.unhandledRejection
Anti-Patterns
- Do not use deprecated timestamp formats (e.g., DD-MM-YYYY).
- Do not allow colorization in production logs.
- Do not allow
in log output.[object Object] - Do not hardcode application names or paths inside the function logic.
Interaction Workflow
- Receive the request to create the logger.
- Generate the complete
function code block.createLogger - Ensure all constraints regarding formatting, rotation, and serialization are met.
Triggers
- create a generic winston logger
- setup robust logging service
- fix [object Object] in winston logs
- generic logger for nodejs projects
- winston daily rotate file configuration