@loglayer/mixin-hot-shots
v3.3.1
Published
Adds statsd / hot-shots functionality to LogLayer.
Maintainers
Readme
hot-shots (StatsD) mixin for LogLayer
Adds StatsD metrics functionality to the LogLayer logging library using hot-shots.
The mixin provides a fluent builder API for sending metrics to StatsD, DogStatsD, and Telegraf through a stats property on LogLayer instances. See the hot-shots documentation for detailed usage information about available methods and options.
Installation
npm install loglayer @loglayer/mixin-hot-shots hot-shotsyarn add loglayer @loglayer/mixin-hot-shots hot-shotspnpm add loglayer @loglayer/mixin-hot-shots hot-shotsUsage
import { LogLayer, useLogLayerMixin, ConsoleTransport } from 'loglayer';
import { StatsD } from 'hot-shots';
import { hotshotsMixin } from '@loglayer/mixin-hot-shots';
// Create a StatsD client
const statsd = new StatsD({
host: 'localhost',
port: 8125
});
// Register the mixin (must be called before creating LogLayer instances)
useLogLayerMixin(hotshotsMixin(statsd));
// Create LogLayer instance
const log = new LogLayer({
transport: new ConsoleTransport({
logger: console
})
});
// Use StatsD methods through the stats property
log.stats.increment('request.count').send();
log.stats.decrement('request.count').send();
log.stats.timing('request.duration', 150).send();
log.stats.gauge('active.connections', 42).send();
// Use builder pattern for advanced configuration
log.stats.increment('request.count')
.withValue(5)
.withTags(['env:production', 'service:api'])
.withSampleRate(0.5)
.send();Documentation
For more details, visit https://loglayer.dev/mixins/hot-shots.
