logger

package
v0.1.58 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

README

README

This package contains the logging client written in the Go programming language. The logging client is used by Go services or other Go code to communicate with the EdgeX support-logging microservice (regardless of underlying implemenation type) by sending REST requests to the service's API endpoints.

How To Use

To use the support-logging client package you first need to import the library into your project:

import "github.com/edgexfoundry/go-mod-core-contracts/clients/logging"

To send a log message to the centralized logging service, you first need to get a LoggingClient and then you can send logging messages into the service (indicating the level with the various log function call.

  logTarget := setLoggingTarget(*configuration)
	loggingClient = logger.NewClient(internal.CoreDataServiceKey, configuration.EnableRemoteLogging, logTarget)

  loggingClient.Info(consulMsg)
	loggingClient.Info(fmt.Sprintf("Starting %s %s ", internal.CoreDataServiceKey, edgex.Version))

Log messages can be logged as Info, Error, Debug, or Warn.

Documentation

Overview

Package logger provides a client for integration with the support-logging service. The client can also be configured to write logs to a local file rather than sending them to a service.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValidLogLevel

func IsValidLogLevel(l string) bool

IsValidLogLevel checks if `l` is a valid log level

Types

type LoggingClient

type LoggingClient interface {
	// SetLogLevel sets minimum severity log level. If a logging method is called with a lower level of severity than
	// what is set, it will result in no output.
	SetLogLevel(logLevel string) error
	// Debug logs a message at the DEBUG severity level
	Debug(msg string, args ...interface{})
	// Error logs a message at the ERROR severity level
	Error(msg string, args ...interface{})
	// Info logs a message at the INFO severity level
	Info(msg string, args ...interface{})
	// Trace logs a message at the TRACE severity level
	Trace(msg string, args ...interface{})
	// Warn logs a message at the WARN severity level
	Warn(msg string, args ...interface{})
}

LoggingClient defines the interface for logging operations.

func NewClient

func NewClient(owningServiceName string, isRemote bool, logTarget string, logLevel string) LoggingClient

NewClient creates an instance of LoggingClient

func NewClientStdOut

func NewClientStdOut(owningServiceName string, isRemote bool, logLevel string) LoggingClient

NewClientStdOut creates an instance of LoggingClient that expects to log to stdout and does not check logTarget

func NewMockClient

func NewMockClient() LoggingClient

NewMockClient creates a mock instance of LoggingClient

type MockLogger

type MockLogger struct {
}

MockLogger is a type that can be used for mocking the LoggingClient interface during unit tests

func (MockLogger) Debug

func (lc MockLogger) Debug(msg string, args ...interface{})

Debug simulates logging an entry at the DEBUG severity level

func (MockLogger) Error

func (lc MockLogger) Error(msg string, args ...interface{})

Error simulates logging an entry at the ERROR severity level

func (MockLogger) Info

func (lc MockLogger) Info(msg string, args ...interface{})

Info simulates logging an entry at the INFO severity level

func (MockLogger) SetLogLevel

func (lc MockLogger) SetLogLevel(loglevel string) error

SetLogLevel simulates setting a log severity level

func (MockLogger) Trace

func (lc MockLogger) Trace(msg string, args ...interface{})

Trace simulates logging an entry at the TRACE severity level

func (MockLogger) Warn

func (lc MockLogger) Warn(msg string, args ...interface{})

Warn simulates logging an entry at the WARN severity level

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL