/gop

Primary LanguageGoMIT LicenseMIT

Go Reference Go Report Card

Contributors Forks Stargazers Issues MIT License [![LinkedIn][linkedin-shield]][linkedin-url]


GOP

Golang Patterns is commom used interfaces to use in your projects
Explore the docs »

Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Installation
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgments

About The Project

Using this project you can just send log (for example) and don't think about how implementation you'll use. This can be done any time, and can be changed any time too.

(back to top)

Installation

go get -u github.com/axpira/gop/log

(back to top)

Usage

The implementation will format the output, but you can change anytime implementation.

Choose a implementation

For now:

  • goplogjson Fast and with zero allocation
  • adapter Creates a map[string]interface{} with all fields, and you can implements just one func to create a logger. Has Logrus adadapter and Json using Golang encoding

Simple Log

package main

import (
	"github.com/axpira/gop/log"
)

func main() {
	log.Info("Hello World")
}

Add fields to log

package main

import (
	"github.com/axpira/gop/log"
	"github.com/axpira/gop/log/field"
)

func main() {
	log.Inf(field.
		Str("str_field", "hello").
		Int("int_field", 42).
		Msg("Hello World"),
	)
}

Leveled logging

package main

import (
	"errors"

	"github.com/axpira/gop/log"
)

func main() {
	log.Error("Hello World", errors.New("unknown error"))
}

Other Leveled logging

package main

import (
	"errors"

	"github.com/axpira/gop/log"
	"github.com/axpira/gop/log/field"
)

func main() {
	log.Log(
		log.ErrorLevel,
		field.Msg("Hello World").Err(errors.New("unknown error")),
	)

Sub logger

package main

import (
	"errors"

	"github.com/axpira/gop/log"
	"github.com/axpira/gop/log/field"
)

func main() {
	l := log.With(field.Str("mykey", "value"))
	l.Trace("Hello World")

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Thiago Ferreira - thiagogbferreira@gmail.com

Project Link: https://github.com/axpira/gop

(back to top)