• Stars
    star
    3
  • Rank 3,963,521 (Top 79 %)
  • Language
    Go
  • License
    MIT License
  • Created about 4 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple Logging Facade for Golang

PkgGoDev Continuous Integration Coverage Status Go Report Card

Simple Log Framework for Golang (slf4g)

TOC

Principles

KISS for users

If you want to log something it should be easy, intuitive and straight forward. This should work either for very small applications (just one file) or big applications, too.

You should not care about the implementation, you want just to use it.

KISS for implementators

If you want to implement a new logger you should not be required to educate your users how to use it.

You just want to write a logger for a user-case. Someone else should take care of the public API.

Separation

A logging framework should not be both, by design: API and implementation.

You want to have one API and the possibility to use whatever implementation you want.

Interoperable

Regardless how used or implemented you want that just everything sticks together, and you're not ending up over and over again in writing new wrappers or in worst-case see different styled log messages in the console.

Every library should just work transparently with one logger.

Motivation

I've tried out many logging frameworks for Golang. They're coming with different promises, like:

  1. There are ones which tries to be "blazing fast"; focussing on be fast and non-blocking to be able to log as much log events as possible.

  2. Other ones are trying to be as minimalistic as possible. Just using a very few amount of code to work.

  3. ...

...but overall they're just violating the Principles listed above and we're ending up in just mess.

Slf4g is born out of feeling this pain every day again and be simply annoyed. It is inspired by Simple Logging Facade for Java (SLF4J), which was born out of the same pains; but obviously in Java before. Since SLF4J exists, and it is now broadly used in Java, nobody does experience this issues any longer.

Getting started

It is very easy to use slf4g (as the naming is promising â˜ēī¸):

  1. Import the API to your current project (in best with a Go Modules project)

    $ go get -u github.com/echocat/slf4g
  2. Select one of the implementation of slf4g and import it too (see Implementations). Example:

    $ go get -u github.com/echocat/slf4g/native

    ℹī¸ If you do not pick one implementation the fallback logger is used. It works, too, but is obviously less powerful and is not customizable. It is comparable with the SDK based logger.

  3. Configure your application to use the selected logger implementation:

    This should be only done in main/main.go:

    package main
    
    import (
    	_ "github.com/echocat/slf4g/native"
    )
    
    func main() {
    	// do your stuff...
    }
  4. In each package create a logger variable, in best case you create a file named common.go or package.go which will contain it:

    package foo
    
    import (
    	"github.com/echocat/slf4g"
    )
    
    var logger = log.GetLoggerForCurrentPackage()
  5. Now you're ready to go. In every file of this package you can do stuff, like:

    package foo
    
    func MyFunction() {
    	logger.Info("Hello, world!")
    
    	if !loaded {
    		logger.With("field", 123).
    		       Warn("That's not great.")
    	}
    
    	if err := doSomething(); err != nil {
    		logger.WithError(err).
    		       Error("Doh!")
    	}
    }

    For sure, you're able to simply do stuff like that (although to ensure interoperability this is not recommended):

    package foo
    
    import (
    	"github.com/echocat/slf4g"
    )
    
    func MyFunction() {
    	log.Info("Hello, world!")
    
    	if !loaded {
    		log.With("field", 123).
    		    Warn("That's not great.")
    	}
    
    	if err := doSomething(); err != nil {
    		log.WithError(err).
    		    Error("Doh!")
    	}
    }

Done. Enjoy!

Implementations

This is the reference implementation of slf4g.

Contributing

slf4g is an open source project by echocat. So if you want to make this project even better, you can contribute to this project on Github by fork us.

If you commit code to this project, you have to accept that this code will be released under the license of this project.

License

See the LICENSE file.

More Repositories

1

puppet-graphite

Puppet module for graphite monitoring tools
Puppet
67
star
2

gradle-golang-plugin

Gradle plugin to build, test and do other stuff of Golang projects.
Java
44
star
3

caddy-filter

Provides a directive to filter response bodies in caddy.
Go
38
star
4

nagios-plugin-check_mountpoints

Nagios check if all specified nfs/cifs/davfs mounts exist and if they are correct implemented.
Shell
38
star
5

puppet-mongodb

This module manages mongodb services. It provides the functions for sharding, mongod and mongos instances.
Shell
33
star
6

puppet-redis

Puppet module to install and configure redis service from internet sources
HTML
24
star
7

caretakerd

caretakerd is a minimal process supervisor. There are no external dependencies and is optimized for containerization (such as Docker) and simple configuration.
Go
22
star
8

golang-kata-1

Coding kata for Golang aimed to improve your development skills in continues sessions.
Go
19
star
9

teamcity-buildTagsViaBuildLog-plugin

Teamcity plugin to programatically add build tags via the build log.
Java
18
star
10

adam

Addon which enhances all user profiles of confluence. It also adds an advanced people directory. The whole addon is configurable by means of an XML, can be localized, supports Velocity templates and supports view and edit restrictions.
Java
11
star
11

jopus

Java binding to native opus encoder/decoder.
C
10
star
12

puppet-kibana4

Puppet module to install and configure kibana 4
Ruby
7
star
13

site24x7_exporter

site24x7 exporter for prometheus.io, written in go.
Go
7
star
14

tomcat-json-logging

Extension to Tomcat logging that will format the contents as JSON to be better compatible with logging environments for microservices
Java
7
star
15

java-kata-1

Coding kata for Java aimed to improve your development skills in continues sessions.
Java
6
star
16

kubor

Safely bringing repositories using templating and charting inside CI/CD pipelines to Kubernetes.
Go
4
star
17

watch

Like the unix one but works cross-platform without magic. 😄
Go
4
star
18

java-stream-utils

Utilities for handling Java Streams.
Java
3
star
19

ruby-kata-1

Coding kata for Ruby aimed to improve your development skills in continues sessions.
Ruby
3
star
20

oracle-java-launcher

Provides safe way to bundle Oracles JavaSE in other packages.
Go
3
star
21

https-enabler

Simple proxy to add HTTPS to endpoints that only support HTTP.
Go
3
star
22

velma

Master-Password protected password safe for Maven.
Java
2
star
23

terraform-provider-bitwarden

Go
2
star
24

nodejs-kata-1

Coding kata for Node.js aimed to improve your development skills in continues sessions.
JavaScript
2
star
25

hugo-maven-plugin

Plugin that wraps hugo build processes into Maven executions.
Java
2
star
26

lingress

Lean ingress controller.
Go
2
star
27

slf4g-logrus

Bridges events from logrus to slf4g and/or the other way around.
Go
1
star
28

gocheck-addons

Provides some addons functions for usage together with gocheck.
Go
1
star
29

jemoni

Tools to monitor the JVM including some convenience JMX beans and an JMX to Carbon bridge.
Java
1
star
30

jomon

Collection of many useful tools for Java. Could be compared with apache-commons.
Java
1
star
31

nagios-plugin-check_userimplementation

Check if a specified user exists and that he has the correct userId, groupId and supplementary groups.
Shell
1
star
32

redprecursor

Access and modify your code before it will be transformed to bytecode by the compiler without AspectJ.
Java
1
star
33

caretakerd-docker-demos

List of demos how to use caretakerd together with docker images.
Dockerfile
1
star
34

echocat.org

Source files for the frontend of https://echocat.org website.
Go
1
star