| name | logg |
| description | Guide for using @guiiai/logg — a lightweight structured logger for Node.js and browser. Use this skill whenever the user imports from '@guiiai/logg', mentions logg, needs structured logging with JSON or pretty output, wants caller-aware logs with clickable hyperlinks, needs child loggers with persistent fields, or asks about lightweight alternatives to winston, pino, or bunyan. Also use when setting up application logging with log levels, custom formatters, or error extraction. |
| license | MIT |
| metadata | {"author":"guiiai","version":"1.2.0"} |
@guiiai/logg
Lightweight structured logger for Node.js and browser with stack parsing, caller records, and clickable hyperlinks.
Quick Start
import { initLogger, useGlobalLogger } from '@guiiai/logg'
initLogger()
const log = useGlobalLogger('MyApp')
log.log('Hello world!')
Core API
Creating Loggers
import { createLogg, createLogger, createGlobalLogger } from '@guiiai/logg'
const log = createLogg('http/request').useGlobalConfig()
const log = createLogger().useGlobalConfig()
const log = createGlobalLogger()
Aliases: useLogg = createLogg, useLogger = createLogger, useGlobalLogger = createGlobalLogger
Log Levels
import { LogLevel, setGlobalLogLevel, setGlobalLogLevelString } from '@guiiai/logg'
setGlobalLogLevel(LogLevel.Debug)
setGlobalLogLevelString('debug')
| Level | Value | Description |
|---|
Error | 0 | Only errors |
Warning | 1 | Errors + warnings |
Log | 2 | + general logs |
Verbose | 3 | + verbose info |
Debug | 4 | Everything |
Output Formats
import { Format, setGlobalFormat } from '@guiiai/logg'
setGlobalFormat(Format.Pretty)
setGlobalFormat(Format.JSON)
JSON output:
{"level":"log","context":"app","timestamp":"2024-01-01T00:00:00.000Z","message":"User logged in","fields":{"userId":"123"}}
Pretty output:
[2024-01-01 00:00:00] LOG app: User logged in { userId: '123' }
Structured Fields
log
.withField('requestId', req.id)
.withField('url', req.url)
.error('Resource not found (404)')
log
.withFields({ userId: '12345', ip: '192.168.1.1' })
.log('User logged in')
Child Loggers
Child loggers inherit parent config and carry persistent fields:
const parentLog = createLogg('app').useGlobalConfig()
const childLog = parentLog.child({
module: 'database',
version: '1.0.0',
})
childLog.log('Connected')
Error Handling
try {
} catch (err) {
log.withError(err).error('Operation failed')
log.errorWithError('Failed to process request', err)
}
Custom Processors
const log = createLogg('app')
.useGlobalConfig()
.withTimeFormatter(date => date.toLocaleString('en-US', { timeZone: 'America/New_York' }))
const log = createLogg('app')
.useGlobalConfig()
.withErrorProcessor(err => {
if (err instanceof CustomError) return { ...err, customField: 'value' }
return err
})
Configuration Methods (Fluent API)
All return a new logger instance (immutable):
| Method | Description |
|---|
.useGlobalConfig() | Apply global level/format settings |
.child(fields) | Create child with persistent fields |
.withContext(ctx) | Set context string |
.withLogLevel(level) | Set log level |
.withFormat(format) | Set output format |
.withField(key, value) | Add single field |
.withFields(obj) | Add multiple fields |
.withError(err) | Attach error object |
.withTimeFormatter(fn) | Custom timestamp format |
.withErrorProcessor(fn) | Custom error transform |
Typical Setup Pattern
import { Format, initLogger, LogLevel, useGlobalLogger } from '@guiiai/logg'
initLogger(
process.env.NODE_ENV === 'production' ? LogLevel.Log : LogLevel.Debug,
process.env.NODE_ENV === 'production' ? Format.JSON : Format.Pretty,
)
const log = useGlobalLogger('module-name')
log.log('ready')
Key Rules
- Call
initLogger() or setGlobalLogLevel() + setGlobalFormat() once at app startup
- Use
.useGlobalConfig() on logger instances to pick up global settings
withField / withFields / child return new instances — they don't mutate
- Use
Format.JSON in production, Format.Pretty in development
- Works in both Node.js and browser — format auto-adapts
Documentation
For the latest API reference, use context7 to query @guiiai/logg documentation.