Sumo Logic support in the Javascript / Node.js ecosystem is lacking. The sumo-logger
package has not been updated in years, most likely due to their adoption of Open Telemetry (otel), and wants you to integrate using an otel stack instead.
What if you don't care about otel, and just want to send logs?
LogLayer offers a Sumo Logic Transport that you can use to send log entries to Sumo Logic.
What is LogLayer
LogLayer is the modern Typescript logging library built for structured logging. It wraps around your favorite logging libraries like pino
and winston
.
The logging APIs were built for the best developer experience possible:
import { LogLayer, ConsoleTransport } from 'loglayer'
const log = new LogLayer({
// swap with pino, or multiple loggers
transport: [
new ConsoleTransport({
logger: console,
})
],
})
// Basic logging
log.info('Hello world!')
// Logging with metadata
log.withMetadata({ user: 'john' }).info('User logged in')
// Logging with context (persists across log calls)
log.withContext({ requestId: '123' })
log.info('Processing request') // Will include requestId
// Logging errors
log.withError(new Error('Something went wrong')).error('Failed to process request')
Integrating LogLayer with Sumo Logic
Once you create an HTTP source in Sumo Logic, you can integrate by doing the following:
npm install @loglayer/transport-sumo-logic serialize-error loglayer
import { LogLayer } from "loglayer";
import { SumoLogicTransport } from "@loglayer/transport-sumo-logic";
import { serializeError } from "serialize-error";
const transport = new SumoLogicTransport({
url: "YOUR_SUMO_LOGIC_HTTP_SOURCE_URL",
});
const logger = new LogLayer({
errorSerializer: serializeError, // Important for proper error serialization
transport
});
logger.info("Hello from LogLayer!");
You should now see logs sent to Sumo Logic!
Top comments (0)