Logging framework for Golang
Find a file
Martin Riedl ba2ba315d0
All checks were successful
Build / Checks (push) Successful in 33s
Build / Code Coverage (push) Successful in 43s
Build / Build (push) Successful in 30s
Release / Semantic Release (push) Successful in 45s
docs: enhanced simple example
2025-03-04 20:56:50 +01:00
.forgejo/workflows ci: new build workflow 2025-02-28 16:13:23 +01:00
cmd/simple docs: enhanced simple example 2025-03-04 20:56:50 +01:00
.gitignore ignore jetbrains idea folder 2024-05-25 16:32:46 +02:00
.releaserc ci: new semantic release workflow 2025-02-28 16:07:04 +01:00
entry.go feat: new WithMap method for adding multiple values with one call 2025-03-04 20:56:00 +01:00
formatter.go refactor: renamed golog to log 2025-02-20 18:06:56 +01:00
formatter_json.go style: fix goland warnings for unused parameters 2025-03-04 20:56:30 +01:00
formatter_json_test.go refactor: renamed golog to log 2025-02-20 18:06:56 +01:00
formatter_keyvalue.go style: fix goland warnings for unused parameters 2025-03-04 20:56:30 +01:00
formatter_keyvalue_test.go refactor: renamed golog to log 2025-02-20 18:06:56 +01:00
go.mod refactor: renamed golog to log 2025-02-20 18:06:56 +01:00
level.go refactor: renamed golog to log 2025-02-20 18:06:56 +01:00
LICENSE.txt initial commit 2024-01-03 21:25:52 +01:00
logger.go feat: new WithMap method for adding multiple values with one call 2025-03-04 20:56:00 +01:00
output.go refactor: renamed golog to log 2025-02-20 18:06:56 +01:00
printer.go refactor: renamed golog to log 2025-02-20 18:06:56 +01:00
printer_stdout.go refactor: renamed golog to log 2025-02-20 18:06:56 +01:00
README.md docs: enhanced simple example 2025-03-04 20:56:50 +01:00
renovate.json ci: use new renovate config location 2025-02-28 16:02:39 +01:00

log

Log is a simple logging framework for golang.

Getting Started

import "git.martin-riedl.de/golang/log"

func main(){
	log.Default.Info("My First Info Message")
}

Check out this simple example file for the basic usage.

Multiple Log Instance

Create a new log instance (instead of using the Default).

import "git.martin-riedl.de/golang/log"

var myLog := log.NewLoggerDefault()
myLog.Info("My First Info Message")

Outputs / Formatter / Printer

  • Formatter defines the output format (e.g. Key/Value or JSON)
  • Printer defines the message output location (e.g. stdout or file)
  • Output is a combination of Formatter and Printer

The following sample creates 2 outputs. The first sends a key/value format to stdout. The second writes messages as JSON format to stdout.

import "git.martin-riedl.de/golang/log"

var output1 := NewOutput(log.LevelInfo, NewFormatterKeyValue(), NewPrinterStdout()
var output2 := NewOutput(log.LevelError, NewFormatterJSON(), NewPrinterStdout())

var myLog := log.NewLogger(
	[]*Output{output1, output2}
)
myLog.Info("My First Info Message")

Custom Formatter / Printer

If you need a special Formatter or Printer: simply implement the Interface (same name) and assign it to an Output.

License

Copyright 2023 Martin Riedl

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.