logger

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: Apache-2.0 Imports: 11 Imported by: 3 modules, 26 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

logger for OpenPitrix

Build Status Go Report Card GoDoc License

Install

  1. Install Go1.11+
  2. set GO111MODULE=on
  3. go get github.com/codefuture-io/logger
  4. go run hello.go

Example

package main

import (
	"bytes"
	"context"
	"fmt"

	"github.com/codefuture-io/logger"
	"github.com/codefuture-io/logger/ctxutil"
)

func main() {
	logger.Infof(nil, "hello1 openpitrix")

	logger.HideCallstack()
	logger.Infof(nil, "hello2 openpitrix")

	logger.ShowCallstack()
	logger.Infof(nil, "hello3 openpitrix")

	{
		var buf bytes.Buffer
		logger := logger.New().SetOutput(&buf)

		logger.Infof(nil, "hello4 openpitrix")
		logger.Infof(nil, "hello5 openpitrix\nlogger")
		logger.Infof(nil, "")

		fmt.Print(buf.String())
	}

	ctx := context.Background()
	ctx = ctxutil.SetRequestId(ctx, "req-id-001")

	logger.Infof(ctx, "hello context1")

	ctx = ctxutil.SetMessageId(ctx, "msg-001", "msg-002")
	logger.Infof(ctx, "hello context2")

	ctx = ctxutil.ClearRequestId(ctx)
	logger.Infof(ctx, "hello context3")
}

output:

2018-10-20 07:43:31.70066 -INFO- hello1 openpitrix (hello.go:19)
2018-10-20 07:43:31.70085 -INFO- hello2 openpitrix
2018-10-20 07:43:31.70086 -INFO- hello3 openpitrix (hello.go:25)
2018-10-20 07:43:31.70089 -INFO- hello4 openpitrix (hello.go:31)
2018-10-20 07:43:31.70091 -INFO- hello5 openpitrix\nlogger (hello.go:32)
2018-10-20 07:43:31.70093 -INFO-  (hello.go:33)
2018-10-20 07:43:31.70096 -INFO- hello context1 (hello.go:41){@req-id-001}
2018-10-20 07:43:31.70099 -INFO- hello context2 (hello.go:44){msg-001|msg-002@req-id-001}
2018-10-20 07:43:31.70101 -INFO- hello context3 (hello.go:47){msg-001|msg-002@}

Documentation

Overview

Package logger provides standard logger for OpenPitrix.

Example
package main

import (
	"github.com/codefuture-io/logger"
)

func main() {
	logger.Infof(nil, "hello openpitrix")
}
Example (WithContext)
package main

import (
	"context"

	"github.com/codefuture-io/logger"
	"github.com/codefuture-io/logger/ctxutil"
)

func main() {
	ctx := context.Background()
	ctx = ctxutil.SetRequestId(ctx, "req-id-001")
	ctx = ctxutil.SetMessageId(ctx, "msg-001", "msg-002")

	logger.Infof(ctx, "hello openpitrix")
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Criticalf

func Criticalf(ctx context.Context, format string, a ...interface{})

func Debugf

func Debugf(ctx context.Context, format string, a ...interface{})

func Errorf

func Errorf(ctx context.Context, format string, a ...interface{})

func HideCallstack

func HideCallstack()

func Infof

func Infof(ctx context.Context, format string, a ...interface{})

func SetLevelByString

func SetLevelByString(level string)

func SetOutput

func SetOutput(output io.Writer)

func ShowCallstack

func ShowCallstack()

func Warnf

func Warnf(ctx context.Context, format string, a ...interface{})

Types

type Level

type Level uint32
const (
	CriticalLevel Level = iota
	ErrorLevel
	WarnLevel
	InfoLevel
	DebugLevel
)

func StringToLevel

func StringToLevel(level string) Level

func (Level) String

func (level Level) String() string

type Logger

type Logger struct {
	Level Level
	// contains filtered or unexported fields
}

func New

func New() *Logger

func (*Logger) Criticalf

func (p *Logger) Criticalf(ctx context.Context, format string, args ...interface{})

func (*Logger) Debugf

func (p *Logger) Debugf(ctx context.Context, format string, a ...interface{})

func (*Logger) Errorf

func (p *Logger) Errorf(ctx context.Context, format string, args ...interface{})

func (*Logger) HideCallstack

func (p *Logger) HideCallstack() *Logger

func (*Logger) Infof

func (p *Logger) Infof(ctx context.Context, format string, a ...interface{})

func (*Logger) SetLevel

func (p *Logger) SetLevel(level Level)

func (*Logger) SetLevelByString

func (p *Logger) SetLevelByString(level string)

func (*Logger) SetOutput

func (p *Logger) SetOutput(w io.Writer) *Logger

func (*Logger) ShowCallstack

func (p *Logger) ShowCallstack() *Logger

func (*Logger) Warnf

func (p *Logger) Warnf(ctx context.Context, format string, a ...interface{})

func (*Logger) WithDepth

func (p *Logger) WithDepth(depth int) *Logger

Directories

Path Synopsis
Package ctxutil provides utilities for grpc context in OpenPitrix.
Package ctxutil provides utilities for grpc context in OpenPitrix.

Jump to

Keyboard shortcuts

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