log

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2021 License: Apache-2.0 Imports: 5 Imported by: 1

README

Usage:

package main

import (
	"context"

	"github.com/codefresh-io/foo/cmd/root"
	"github.com/codefresh-io/pkg/log"
	"github.com/sirupsen/logrus"
)

func main() {
	ctx := context.Background()
    lgrCfg := &log.LogrusConfig{Level: "info"}
	lgr := log.FromLogrus(logrus.NewEntry(logrus.StandardLogger()), lgrCfg)
	
    ctx = log.WithLogger(ctx, lgr)

	log.SetDefault(lgr) // if no context is provided to log.G() or the context does 
                        // not have a logger attached, you will get this logger.

	cmd := root.New(ctx)
	lgr.AddPFlags(cmd) // adds the logger flags to the command

	if err := cmd.Execute(); err != nil {
		log.G(ctx).Fatal(err)
	}
}

Documentation

Overview

Copyright 2021 The Codefresh Authors.

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.

Copyright 2021 The Codefresh Authors.

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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLogrusEntry

func GetLogrusEntry(l Logger) (*logrus.Entry, error)

func SetDefault

func SetDefault(logger Logger)

func WithLogger

func WithLogger(ctx context.Context, logger Logger) context.Context

Types

type Fields

type Fields map[string]interface{}

type Logger

type Logger interface {
	Printf(string, ...interface{})
	Debug(...interface{})
	Info(...interface{})
	Warn(...interface{})
	Fatal(...interface{})
	Error(...interface{})
	Debugf(string, ...interface{})
	Infof(string, ...interface{})
	Warnf(string, ...interface{})
	Fatalf(string, ...interface{})
	Errorf(string, ...interface{})

	WithField(string, interface{}) Logger
	WithFields(Fields) Logger
	WithError(error) Logger

	// AddPFlags adds persistent logger flags to cmd
	AddPFlags(*cobra.Command)
}
var (
	G = GetLogger

	L Logger = NopLogger{}
)

func FromLogrus

func FromLogrus(l *logrus.Entry, c *LogrusConfig) Logger

func GetLogger

func GetLogger(ctx ...context.Context) Logger

type LogrusConfig

type LogrusConfig struct {
	Level  string
	Format LogrusFormatter
}

type LogrusFormatter

type LogrusFormatter string
const (
	FormatterText LogrusFormatter = defaultFormatter
	FormatterJSON LogrusFormatter = "json"
)

type NopLogger

type NopLogger struct{}

func (NopLogger) AddPFlags

func (NopLogger) AddPFlags(*cobra.Command)

func (NopLogger) Debug

func (NopLogger) Debug(...interface{})

func (NopLogger) Debugf

func (NopLogger) Debugf(string, ...interface{})

func (NopLogger) Error

func (NopLogger) Error(...interface{})

func (NopLogger) Errorf

func (NopLogger) Errorf(string, ...interface{})

func (NopLogger) Fatal

func (NopLogger) Fatal(...interface{})

func (NopLogger) Fatalf

func (NopLogger) Fatalf(string, ...interface{})

func (NopLogger) Info

func (NopLogger) Info(...interface{})

func (NopLogger) Infof

func (NopLogger) Infof(string, ...interface{})

func (NopLogger) Printf

func (NopLogger) Printf(string, ...interface{})

func (NopLogger) Warn

func (NopLogger) Warn(...interface{})

func (NopLogger) Warnf

func (NopLogger) Warnf(string, ...interface{})

func (NopLogger) WithError

func (l NopLogger) WithError(error) Logger

func (NopLogger) WithField

func (l NopLogger) WithField(string, interface{}) Logger

func (NopLogger) WithFields

func (l NopLogger) WithFields(Fields) Logger

Jump to

Keyboard shortcuts

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