zapconfig

package module
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2021 License: Apache-2.0, MIT Imports: 6 Imported by: 18

README

zapconfig

😄 zap logger configurations

go.dev reference License GitHub release Docker Metrics Made by Manfred Touron

Go Release PR GolangCI codecov Go Report Card CodeFactor

Usage

import (
	"go.uber.org/zap/zapcore"

	"moul.io/zapconfig"
)

func Example() {
	logger := zapconfig.Configurator{}.MustBuild()
	logger.Info("hello!")
}

func Example_configuration() {
	logger := zapconfig.New().
		EnableStacktrace().
		SetLevel(zapcore.DebugLevel).
		SetOutputPath("stderr").
		SetOutputPaths([]string{"stderr", "stdout", "./path/to/log.txt"}).
		SetPreset("light-console").
		MustBuild()
	logger.Info("hello!")
}

Install

Using go
$ go get moul.io/zapconfig
Releases

See https://github.com/moul/zapconfig/releases

Contribute

I really welcome contributions. Your input is the most precious material. I'm well aware of that and I thank you in advance. Everyone is encouraged to look at what they can do on their own scale; no effort is too small.

Everything on contribution is sum up here: CONTRIBUTING.md

Contributors ✨

All Contributors

Thanks goes to these wonderful people (emoji key):


Manfred Touron

🚧 📖 ⚠️ 💻

moul-bot

🚧

This project follows the all-contributors specification. Contributions of any kind welcome!

Stargazers over time

Stargazers over time

License

© 2020 Manfred Touron

Licensed under the Apache License, Version 2.0 (LICENSE-APACHE) or the MIT license (LICENSE-MIT), at your option. See the COPYRIGHT file for more details.

SPDX-License-Identifier: (Apache-2.0 OR MIT)

Documentation

Overview

message from the author:

+--------------------------------------------------------------+
| * * * ░░░░░░░░░░░░░░░░░░░░  Hello  ░░░░░░░░░░░░░░░░░░░░░░░░░░|
+--------------------------------------------------------------+
|                                                              |
|     ++              ______________________________________   |
|     ++++           /                                      \  |
|      ++++          |                                      |  |
|    ++++++++++      |   Feel free to contribute to this    |  |
|   +++       |      |       project or contact me on       |  |
|   ++         |     |    manfred.life if you like this     |  |
|   +  -==   ==|     |               project!               |  |
|  (   <*>   <*>     |                                      |  |
|   |          |    /|                  :)                  |  |
|   |         _)   / |                                      |  |
|   |      +++    /  \______________________________________/  |
|    \      =+   /                                             |
|     \      +                                                 |
|     |\++++++                                                 |
|     |  ++++      ||//                                        |
|  ___|   |___    _||/__                                     __|
| /    ---    \   \|  |||                   __ _  ___  __ __/ /|
|/  |       |  \    \ /                    /  ' \/ _ \/ // / / |
||  |       |  |    | |                   /_/_/_/\___/\_,_/_/  |
+--------------------------------------------------------------+
Example
package main

import (
	"moul.io/zapconfig"
)

func main() {
	logger := zapconfig.Configurator{}.MustBuild()
	logger.Info("hello!")
}
Output:

Example (Configuration)
package main

import (
	"go.uber.org/zap/zapcore"

	"moul.io/zapconfig"
)

func main() {
	logger := zapconfig.New().
		EnableStacktrace().
		SetLevel(zapcore.DebugLevel).
		SetOutputPath("stderr").
		SetOutputPaths([]string{"stderr", "stdout", "./path/to/log.txt"}).
		SetPreset("light-console").
		MustBuild()
	logger.Info("hello!")
}
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var AvailablePresets = []string{"console", "json", "light-console", "light-json", "testing"}

AvailablePresets is the list of preset supported by `SetPreset`.

Functions

This section is empty.

Types

type Configurator

type Configurator struct {
	// contains filtered or unexported fields
}

Configurator is the main object of this package. Leaving it empty will generate an opinionated sane default zap.Config.

func New added in v1.4.0

func New() *Configurator

New instanciates a Configurator.

func (Configurator) Build

func (c Configurator) Build() (*zap.Logger, error)

BuildLogger returns a configured *zap.Logger.

func (Configurator) Config

func (c Configurator) Config() (zap.Config, error)

Config builds a zap.Config.

func (*Configurator) EnableStacktrace added in v1.2.0

func (c *Configurator) EnableStacktrace() *Configurator

EnableStacktrace forces stacktraces to be enabled.

func (Configurator) IsEmpty

func (c Configurator) IsEmpty() bool

IsEmpty checks whether the Configurator isn't touched (default value) or if it was modified.

func (Configurator) MustBuild

func (c Configurator) MustBuild() *zap.Logger

func (*Configurator) SetLevel

func (c *Configurator) SetLevel(level zapcore.Level) *Configurator

SetLevel sets the minimal logging level.

func (*Configurator) SetOutputPath

func (c *Configurator) SetOutputPath(dest string) *Configurator

SetOutputPath sets zap.Config.OutputPaths and c.Config.ErrorOutputPaths with the given path.

func (*Configurator) SetOutputPaths

func (c *Configurator) SetOutputPaths(dests []string) *Configurator

SetOutputPaths sets zap.Config.OutputPaths and c.Config.ErrorOutputPaths with the given paths.

func (*Configurator) SetPreset added in v1.3.0

func (c *Configurator) SetPreset(name string) *Configurator

SetPreset configures various things based on just a keyword.

func (Configurator) String

func (c Configurator) String() string

String implements Stringer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL