Giter VIP home page Giter VIP logo

dreamit-de-otel-json-logger's Introduction

otel-json-logger

JSON diagnose logger for OpenTelemetry

Installation

npm install --save @dreamit/otel-json-logger

TypeScript declarations are provided within the project.

Compatibility

otel-json-logger is compatible with @opentelemetry/api version ^1.6.0.

Features

  • Provides JSON Logger for OpenTelemetry DiagLogger interface
  • Stringifies/inspects messages with objects and arrays as well as log arguments to avoid breaking logging tools
  • Creates ISODate timestamp for log entry

Usage

Create a JsonDiagLogger object by providing a fitting loggerName and serviceName. The logger can be used standalone to log JSON to console as well as a global DiagLogger.

import { JsonDiagLogger } from '@dreamit/otel-json-logger'
import { diag, DiagLogLevel } from "@opentelemetry/api";

// Standalone
const logger = new JsonDiagLogger({
    loggerName: 'test-logger', // The loggerName printed in field "logger"
    serviceName: 'test-service', // The serviceName printed in field "serviceName"
    minLogLevel: LogLevel.info, // Optional: The minimum log level to use. Default: Does not check for min LogLevel.
    logFirstIncomingRequest: true, // Optional: The first incoming request will be logged. Other messages on debug level will be ignored. Default: false. Note: If you use diag.setLogger ensure that at least "LogLevel.debug" is set, otherwise the message will be ignored.
    logLevelForServiceRequestErrorMessages: LogLevel.info, // Optional: The log level to use for error message "Service request". These contain request information that might not be logged on error level.
    logLevelForTimeoutErrorMessages: LogLevel.info, // Optional: The log level to use for Timeout related messages. These might be of short nature and be downgraded or ignored.
    logLevelForVerbose: LogLevel.off // Optional: Set LogLevel for verbose entries or ignore them
    truncateLimit: 200 // Optional:  The length of the message before the message gets truncated. Default: undefined/0 (off).
    truncatedText: '_TRC_' // Optional: The text to display if a message is truncated.
})
logger.debug('test', 1, {name: 'myname'})

// Add as global DiagLogger
diag.setLogger(logger, DiagLogLevel.ERROR)

JsonDiagLogger functions

General functions

  • createLogEntry: Creates and returns a log entry of type LogEntry with the provided information.
  • logMessage: Central function being called by all DiagLogger interface functions. Calls createLogEntry, stringifies the result and calls console.log().
  • formatMessage: Formats the message. If the message contains an object or array wrap it in JSON.stringify to avoid these being interpreted as JSON objects.
  • setOptions: Sets the LoggerOptions to be used for logging. Can be called after constructor call to set new/other options.
  • containsTimeout: Check if the message contains a Timeout information like "4 DEADLINE_EXCEEDED" or "14 UNAVAILABLE"
  • isIncomingRequestLogMessage: Checks if the arguments are part of an incomingRequest message, i.e. the first argument contains the text 'incomingRequest'
  • isEqualOrHigherMinLogLevel: Checks if the log level is equal or higher than the minimum log level

DiagLogger interface functions

  • debug: Logs a debug message
  • error: Logs an error message
  • info: Logs an info message
  • verbose: Logs a warn message
  • warn: Logs a verbose message

LogLevel enum values

  • DEBUG
  • ERROR
  • INFO
  • OFF : Do not log these entries!
  • VERBOSE
  • WARN

Contact

If you have questions or issues please visit our Issue page and open a new issue if there are no fitting issues for your topic yet.

License

otel-json-logger is under MIT-License.

dreamit-de-otel-json-logger's People

Contributors

dependabot[bot] avatar github-actions[bot] avatar sgohlke avatar shinigami92 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.