Categorygithub.com/ejazmughal/senlog
modulepackage
0.0.0-20220922083529-815978e517b7
Repository: https://github.com/ejazmughal/senlog.git
Documentation: pkg.go.dev

# README

senlog

A convinient Golang logger for Sentry

senlog is a wrapper arround sentry-go, the official Sentry logging package for Go. It has an easy "inline" interface for structured logging with context. For example, consider the following log event with sentry-go:

sentry.WithScope(func(scope *sentry.Scope) {
	scope.SetLevel(sentry.LevelInfo)
		
    scope.SetContext("character", map[string]interface{}{
		"name":        "Mighty Fighter",
		"age":         19,
		"attack_type": "melee",
	})		
	
    sentry.CaptureMessage("Character Info")	
})

This could be written with senlog as the following single line of code:

senlog.Cxt("character").Set("name", "Mighty Fighter").Set("age", 19).Set("attack_type", "melee").INF("Character Info")

Got it? ;-)

Along with Sentry server, senlog output can be written to console and local file. Each output type is called destination. In the following section you can find the example code for each destination with usage.

Integration Example:

package main

import (
	"errors"

	"github.com/ejazmughal/senlog"
	"github.com/getsentry/sentry-go"
)

func main() {

	senlog.INF("'console' destination is added by default, that's why you see this message!")

	err := senlog.AddDestination("sentry", sentry.ClientOptions{
		Dsn:       <YOUR_SENTRY_DSN>,
		Transport: senlog.NewSentryTransport(senlog.DEBUG),
		//Environment: "senlog_test",
	})
	if err != nil {
		senlog.FTL(err, "Could not add 'sentry' destinantion")
	}

	senlog.INF("'sentry' destination is added by you, This message is logged on sentry.io")

	senlog.Set("FirstName", "Ejaz").Set("LastName", "Mughal").INF("This is a log event with 'Default Context' and string value")

	senlog.Cxt("User Defined Context").Set("someID", 107).Set("SomeKey", "some text value").INF("This is an example of a user defined context with integer and string value")

	err = errors.New("Some error")
	senlog.Set("someIntegerValue", 7).ERR(err, "Example error log")

	// You could even write log parallel to a local file
	logFile := "sen.log"
	err = senlog.AddDestination("file", sentry.ClientOptions{
		Transport: senlog.NewFileTransport(logFile, logFile, senlog.INFO),
	})

	if err != nil {
		senlog.FTL(err, "Could not add 'file' destinantion")
	}

	senlog.INF("This message will be written to all three destinations: console, sentry and file")

	// You can disbale output to stdout/stderr by removing 'console' destination
	// This could be usefull in production environment
	senlog.RemoveDestination("console")

	senlog.INF("This message will be written to two destinations: sentry and file")

	senlog.RemoveDestination("sentry")

	senlog.INF("This message will be written to local file only")
}

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Multiple parameter values will be concated without spaces!.
returns ioTransport with time and date.
returns ioTransport with time only line prefix.
No description provided by the author
No description provided by the author
No description provided by the author
set min log level for a destinition.
No description provided by the author

# Constants

log levels.
log levels.
log levels.
No description provided by the author
log levels.
log levels.

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author