Cuihua Logger
/install 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 โจ
// โ 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 ๐ฏ
// 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 โก
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 ๐
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:
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
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
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)
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
- Always log errors with context
- Use structured logging (objects, not strings)
- Include request IDs for tracing
- Don't log sensitive data (passwords, tokens)
- Use appropriate log levels
๐ License
MIT
๐ Acknowledgments
Built with ๐ธ by ็ฟ ่ฑ (Cuihua)
Made with ๐ธ | Cuihua Series | ClawHub Pioneer
- Make sure OpenClaw is installed (local or Docker)
- Run the install command in chat:
/install cuihua-logger - After installation, invoke the skill by name or use
/cuihua-logger - Provide required inputs per the skill's parameter spec and get structured output
What is Cuihua Logger?
๐ AI-powered logging assistant that generates production-ready structured logs. Automatically add intelligent logging to your code with proper levels, conte... It is an AI Agent Skill for Claude Code / OpenClaw, with 133 downloads so far.
How do I install Cuihua Logger?
Run "/install cuihua-logger" in the OpenClaw or Claude Code chat to install it in one step โ no extra setup required.
Is Cuihua Logger free?
Yes, Cuihua Logger is completely free, licensed under MIT-0. You can download, install and use it at no cost.
Which platforms does Cuihua Logger support?
Cuihua Logger is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).
Who created Cuihua Logger?
It is built and maintained by supermario11 (@supermario11); the current version is v1.0.0.