@sylphx/cat-pretty
v0.1.0
Published
Pretty formatter for @sylphx/cat logger
Readme
@sylphx/cat-pretty
Pretty formatter for @sylphx/cat logger
0.81 KB • Beautiful colored output • Perfect for development
Installation
npm install @sylphx/cat @sylphx/cat-prettyDescription
A beautiful, human-readable formatter for @sylphx/cat logs. Adds colors, timestamps, and clean formatting to make logs easy to read during development. Optimized for terminal output with ANSI color support.
Usage Examples
Basic Pretty Logging
import { createLogger } from '@sylphx/cat'
import { prettyFormatter } from '@sylphx/cat-pretty'
const logger = createLogger({
formatter: prettyFormatter()
})
logger.info('Server started', { port: 3000 })
// [2024-11-14T20:30:15.123Z] INF Server started {"port":3000}
logger.error('Connection failed', { host: 'db.example.com' })
// [2024-11-14T20:30:16.456Z] ERR Connection failed {"host":"db.example.com"}Custom Timestamp Format
import { prettyFormatter } from '@sylphx/cat-pretty'
// ISO format (default)
const logger1 = createLogger({
formatter: prettyFormatter({ timestampFormat: 'iso' })
})
logger1.info('Hello')
// [2024-11-14T20:30:15.123Z] INF Hello
// Unix timestamp
const logger2 = createLogger({
formatter: prettyFormatter({ timestampFormat: 'unix' })
})
logger2.info('Hello')
// [1700000000000] INF Hello
// Relative time (ms since start)
const logger3 = createLogger({
formatter: prettyFormatter({ timestampFormat: 'relative' })
})
logger3.info('Hello')
// [+1234ms] INF HelloDisable Colors and Timestamps
import { prettyFormatter } from '@sylphx/cat-pretty'
const logger = createLogger({
formatter: prettyFormatter({
colors: false,
timestamp: false
})
})
logger.info('Hello world')
// INF Hello worldAPI Reference
prettyFormatter(options?: PrettyFormatterOptions): Formatter
Creates a pretty formatter instance.
Options:
colors?: boolean- Enable ANSI colors (default:true)timestamp?: boolean- Show timestamps (default:true)timestampFormat?: 'iso' | 'unix' | 'relative'- Timestamp format (default:'iso')
Color scheme:
trace- Graydebug- Cyaninfo- Greenwarn- Yellowerror- Redfatal- Magenta
Level labels:
trace→ TRCdebug→ DBGinfo→ INFwarn→ WRNerror→ ERRfatal→ FTL
Output Format
[timestamp] LEVEL message {data} [context]Example:
[2024-11-14T20:30:15.123Z] INF User logged in {"userId":123} [service=auth requestId=abc-123]Package Size
- Minified: ~2.5 KB
- Minified + Gzipped: 0.81 KB
- No additional dependencies
Links
Related Packages
- @sylphx/cat - Core logger
- @sylphx/cat-file - File and stream transports
- @sylphx/cat-http - HTTP request/response serializers
License
MIT © Kyle Zhu
