How to use winston-loki as a Winston transport
developmentTo use winston-loki, integrate it as a transport within a Winston logger instance. You must provide a host URL pointing to your Grafana Loki instance. For most simple setups, setting json: true and providing the correct host is sufficient.
To include custom labels for specific log entries, pass a labels object within the log metadata.
const { createLogger, transports } = require("winston");
const LokiTransport = require("winston-loki");
const logger = createLogger({
transports: [
new LokiTransport({
host: "http://127.0.0.1:3100"
})
]
});
// Using custom labels per log entry
logger.debug({ message: 'test', labels: { 'key': 'value' } });