返回顶部
c

cuihua-logger

|

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
89
下载量
0
收藏
概述
安装方式
版本历史

cuihua-logger

# cuihua-logger - Production-Ready Logging 📝 > **Debug faster with intelligent, structured logging.** An AI-powered logging assistant that automatically: - 📝 **Generates** structured logs with proper context - 🎯 **Selects** appropriate log levels (debug, info, warn, error) - 📊 **Adds** performance metrics and timing - 🔍 **Detects** missing logs in critical paths - ⚡ **Optimizes** log output for production ## 🎯 Why cuihua-logger? **The problem**: - ❌ Too many `console.log()` everywhere - ❌ No structure, hard to search - ❌ Wrong log levels (everything is "info") - ❌ Missing context (what user? what request?) - ❌ Performance overhead in production **cuihua-logger solves all of this.** --- ## 🚀 Quick Start ### Analyze logging coverage > "Check logging coverage in src/" ### Add structured logging > "Add logging to getUserById function" ### Generate performance logs > "Add performance logging to API endpoints" --- ## 🎨 Features ### 1. Structured Logging ✨ ```javascript // ❌ BEFORE - Unstructured async function getUserById(id) { console.log('Getting user:', id); const user = await db.query('SELECT * FROM users WHERE id = $1', [id]); console.log('User found:', user); return user; } // ✅ AFTER - Structured async function getUserById(id) { logger.info('Fetching user', { userId: id, operation: 'getUserById' }); const startTime = Date.now(); const user = await db.query('SELECT * FROM users WHERE id = $1', [id]); const duration = Date.now() - startTime; logger.info('User fetched successfully', { userId: id, operation: 'getUserById', duration, found: !!user }); return user; } ``` ### 2. Smart Log Levels 🎯 ```javascript // Automatic level selection based on context logger.debug('Cache hit', { key, ttl }); // Development only logger.info('User logged in', { userId, ip }); // Important events logger.warn('Rate limit approaching', { userId, current: 95, limit: 100 }); // Potential issues logger.error('Payment failed', { orderId, error: error.message, stack: error.stack }); // Critical errors ``` ### 3. Performance Logging ⚡ ```javascript async function fetchData() { const timer = logger.startTimer(); const data = await expensiveOperation(); timer.done({ level: 'info', message: 'Operation complete' }); return data; } // Output: "Operation complete" duration=1234ms ``` ### 4. Request Tracking 🔍 ```javascript app.use((req, res, next) => { req.requestId = generateId(); req.logger = logger.child({ requestId: req.requestId, method: req.method, path: req.path }); req.logger.info('Request started'); res.on('finish', () => { req.logger.info('Request completed', { statusCode: res.statusCode, duration: Date.now() - req.startTime }); }); next(); }); ``` --- ## 📋 Usage Examples ### Example 1: Add Logging to Function **User**: "Add logging to processOrder function" **Generated**: ```javascript async function processOrder(orderId, items) { logger.info('Processing order', { orderId, itemCount: items.length }); try { // Validate if (!orderId || !items.length) { logger.warn('Invalid order data', { orderId, items }); throw new ValidationError('Invalid order'); } // Create order const order = await createOrder(orderId, items); logger.info('Order created', { orderId, orderNumber: order.number }); // Process payment const payment = await processPayment(order); logger.info('Payment processed', { orderId, paymentId: payment.id, amount: payment.amount }); return order; } catch (error) { logger.error('Order processing failed', { orderId, error: error.message, stack: error.stack }); throw error; } } ``` ### Example 2: API Endpoint Logging ```javascript app.post('/api/users', async (req, res) => { const { logger } = req; logger.info('Creating user', { email: req.body.email }); try { const user = await userService.create(req.body); logger.info('User created successfully', { userId: user.id, email: user.email }); res.status(201).json(user); } catch (error) { logger.error('User creation failed', { email: req.body.email, error: error.message }); res.status(500).json({ error: 'Failed to create user' }); } }); ``` --- ## ⚙️ Logger Configuration ### Winston ```javascript import winston from 'winston'; const logger = winston.createLogger({ level: process.env.LOG_LEVEL || 'info', format: winston.format.combine( winston.format.timestamp(), winston.format.errors({ stack: true }), winston.format.json() ), transports: [ new winston.transports.File({ filename: 'error.log', level: 'error' }), new winston.transports.File({ filename: 'combined.log' }) ] }); ``` ### Pino (fastest) ```javascript import pino from 'pino'; const logger = pino({ level: process.env.LOG_LEVEL || 'info', timestamp: pino.stdTimeFunctions.isoTime, formatters: { level: (label) => ({ level: label }) } }); ``` --- ## 📊 Log Levels | Level | When to Use | Example | |-------|------------|---------| | **debug** | Development debugging | `logger.debug('Cache miss', { key })` | | **info** | Important events | `logger.info('User logged in', { userId })` | | **warn** | Potential issues | `logger.warn('Rate limit approaching', { userId })` | | **error** | Errors that need attention | `logger.error('Payment failed', { orderId })` | --- ## 💰 Pricing ### Free - ✅ Basic log generation - ✅ Up to 10 files ### Pro ($8/month) - ✅ Unlimited files - ✅ Performance logging - ✅ Request tracking - ✅ CI/CD integration ### Enterprise ($59/month) - ✅ Team policies - ✅ Log aggregation setup - ✅ Custom formatters --- ## 📚 Best Practices 1. **Always log errors with context** 2. **Use structured logging (objects, not strings)** 3. **Include request IDs for tracing** 4. **Don't log sensitive data (passwords, tokens)** 5. **Use appropriate log levels** --- ## 📜 License MIT --- ## 🙏 Acknowledgments Built with 🌸 by 翠花 (Cuihua) --- **Made with 🌸 | Cuihua Series | ClawHub Pioneer**

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 cuihua-logger-1776056529 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 cuihua-logger-1776056529 技能

通过命令行安装

skillhub install cuihua-logger-1776056529

下载 Zip 包

⬇ 下载 cuihua-logger v1.0.0

文件大小: 5.72 KB | 发布时间: 2026-4-14 14:22

v1.0.0 最新 2026-4-14 14:22
📝 First release! AI-powered structured logging for production systems.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部