An open API service indexing awesome lists of open source software.

https://github.com/kaatinga/dummylogger

a summy logger to add to any package that must log something somewhere
https://github.com/kaatinga/dummylogger

Last synced: 5 months ago
JSON representation

a summy logger to add to any package that must log something somewhere

Awesome Lists containing this project

README

          

[![Tests](https://github.com/kaatinga/dummylogger/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/kaatinga/dummylogger/actions/workflows/test.yml)
# dummylogger

A dummy logger for a custom package.

## Usage

Use the custom logger in your package.

```go
import (
"github.com/kaatinga/dummylogger"
)

var log = dummylogger.Get()

func Init(logger dummylogger.I) {
dummylogger.Set(logger)
}
```

Use it where you need it in the package.

```go
func main() {
log().Errorf("This is an error message")
}
```

Create a custom logger in your project.

```go
type customLogger bool

var CustomLogger = customLogger(true)

func (customLogger) Errorf(format string, v ...interface{}) {
logger.Error().Msgf(format, v...)
}
```

Pass the custom logger to init the package.

```go
import (
"github.com/yourname/yourpackage"
)

func main() {
yourpackage.Init(CustomLogger)
}
```