Logging Guide
Learn how to use nstypocolors effectively for real-world logging scenarios.
This guide explains how to use nstypocolors in real-world scenarios to produce clean, readable, and expressive terminal logs.
The goal is not to color everything — but to make important information stand out intentionally.
Color is a signal, not decoration. Use it to guide attention, not to overwhelm.
Core Principle
Use color to:
- Highlight success or failure
- Separate informational output
- Improve scan-ability
- Reduce cognitive load
Avoid:
- Coloring every log line
- Overusing gradients
- Mixing too many styles together
Basic Logging
For small scripts or simple utilities, plain color functions work best.
import { logGreen, logRed } from 'nstypocolors'
logGreen('Server started successfully')
logRed('Failed to connect to database')const { logGreen, logRed } = require('nstypocolors')
logGreen('Server started successfully')
logRed('Failed to connect to database')This approach is ideal when:
- Logs are short
- Meaning is obvious
- Consistency matters
Status-Based Logging (Recommended)
For applications, CLIs, or bots, prefer semantic gradient presets.
import { logSuccess, logError, logInfo, logWarn } from 'nstypocolors'
logSuccess('Build completed')
logInfo('Listening on port 3000')
logWarn('High memory usage detected')
logError('Unhandled exception occurred')const { logSuccess, logError, logInfo, logWarn } = require('nstypocolors')
logSuccess('Build completed')
logInfo('Listening on port 3000')
logWarn('High memory usage detected')
logError('Unhandled exception occurred')Why This Works
- Each state has a visual identity
- Messages remain readable
- No need to remember color codes
- Easy to maintain over time
Short vs Long Messages
Gradients in nstypocolors adapt automatically to message length.
logSuccess('OK')
logSuccess('Deployment completed successfully')logSuccess('OK')
logSuccess('Deployment completed successfully')Both short confirmations and longer messages remain visually balanced.
CLI Logging
nstypocolors also provides a CLI for quick terminal output.
nstc "Deployment successful" --success
nstc "Fetching data from server..." --info
nstc "Unauthorized access detected" --warn
nstc "Process crashed" --errorUse the CLI when:
- Writing shell scripts
- Automating workflows
- Testing output quickly */}
Combining with Plain Logs
A recommended pattern is mixing colored and plain logs.
console.log('Starting process...')
logInfo('Loading configuration')
logSuccess('Ready')console.log('Starting process...')
logInfo('Loading configuration')
logSuccess('Ready')This keeps neutral information neutral while highlighting key states.
What to Avoid
- Coloring every line
- Mixing multiple styles in one message
- Using gradients for stack traces or debug dumps
Example of what not to do:
logRainbow('Every')
logRainbow('Single')
logRainbow('Line')Recommended Patterns
| Scenario | Recommended |
|---|---|
| Startup complete | logSuccess |
| User action | logInfo |
| Potential issue | logWarn |
| Failure | logError |
| Highlight / phase | logBuild |
Final Thought
Good logs should:
- Be readable at a glance
- Communicate state clearly
- Remain consistent over time
nstypocolors helps you achieve this with zero configuration, minimal API surface, and intentional design.
Last updated on