telemetry-log

module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2024 License: MIT

README

Log Telemetry

Build Status codecov

A simple dependency for trace log and store trace to mongo db

Installation

encore icon


Get the module with:

go get github.com/dyaksa/telemetry-log/telemetry@latest

The usage looks like this:

package main

import (
	"errors"

	"github.com/dyaksa/telemetry-log/telemetry"
)

func main() {
	l, err := telemetry.New(telemetry.WithJSONFormatter())
	if err != nil {
		panic(err)
	}

	l.Log.WithTrace(errors.New("error etc...")).Info("info message")
}

You can run it like this:

With telemetry.New(telemetry.WithJSONFormatter())

{"file":"main.go","func":"main.main","level":"info","line":15,"msg":"info message","time":"2024-06-14T22:36:10+07:00","trace":[{"name":"runtime.main","file":"proc.go","line":"271"},{"name":"runtime.goexit","file":"asm_arm64.s","line":"1222"}]}

With the default telemetry.New().

INFO[0000] info message file=main.go func=main.main line=15 trace="[{runtime.main proc.go 271} {runtime.goexit asm_arm64.s 1222}]"
Logging Method Name

If you wish to add the calling method WithTracer(errors.New("error etc...")) you can use the WithTracer(errors.New("error etc...")) method.

l, err := telemetry.New(telemetry.WithJSONFormatter())

if err != nil {
    panic(err)
}

l.Log.WithTrace(errors.New("error etc")).Info("info message")

This adds the caller as 'method' like so:

{"file":"main.go","func":"main.main","level":"info","line":15,"msg":"info message","time":"2024-06-14T22:51:12+07:00","trace":[{"name":"runtime.main","file":"proc.go","line":"271"},{"name":"runtime.goexit","file":"asm_arm64.s","line":"1222"}]}

With the default without WithTracer(error).

l.Log.Info("info message")

This adds the caller as 'method' like so

{"file":"main.go","func":"main.main","level":"info","line":13,"msg":"info message","time":"2024-06-14T22:54:41+07:00"}
Level logging

Logrus has seven logging levels: Trace, Debug, Info, Warning, Error, Fatal and Panic.

log.Trace("Something very low level.")
log.Debug("Useful debugging information.")
log.Info("Something noteworthy happened!")
log.Warn("You should probably take a look at this.")
log.Error("Something failed but I'm not quitting.")
// Calls os.Exit(1) after logging
log.Fatal("Bye.")
// Calls panic() after logging
log.Panic("I'm bailing.")
Environments

Directories

Path Synopsis
Package cmd provides functionality for command line operations.
Package cmd provides functionality for command line operations.
Package err provides functionality for error tracing.
Package err provides functionality for error tracing.
Package telemetry provides functionality for telemetry logging.
Package telemetry provides functionality for telemetry logging.
log
Package log provides an interface and functions for logging.
Package log provides an interface and functions for logging.
mongo
Package mongo provides a wrapper around the mongo-driver package, simplifying the process of connecting to a MongoDB instance and performing operations on it.
Package mongo provides a wrapper around the mongo-driver package, simplifying the process of connecting to a MongoDB instance and performing operations on it.

Jump to

Keyboard shortcuts

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