logn

package module
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2021 License: MIT Imports: 13 Imported by: 0

README

logn

A wrap of zap, maybe a simplified log4j for golang.

Installation

go get -u github.com/shanexu/logn

Quick Start

Logn loads configuration file from system environment virable LOGN_CONFIG. If the variable is unset, then Logn will try to load the configuration file from current work directory, the file name is "logn.yaml" or "logn.yml".

appenders:
  console:
    - name: CONSOLE
      target: stdout
      encoder:
        console:
          time_encoder: ISO8601
  file:
    - name: FILE
      file_name: /tmp/app.log
      encoder:
        json:
  gelf_udp:
    - name: GRAYLOG
      host: 127.0.0.1
      port: 12201
      compression_type: none
      encoder:
        gelf:
          key_value_pairs:
            - key: env
              value: ${ENV:dev}
            - key: app
              value: ${APPNAME:demo}
            - key: file
              value: app.log
  rolling_file:
    - name: GELF_FILE
      file_name: /tmp/app_gelf.log
      max_size: 100
      encoder:
        gelf:
          key_value_pairs:
            - key: env
              value: ${ENV:dev}
            - key: app
              value: ${APPNAME:demo}
            - key: file
              value: app.log
loggers:
  root:
    level: info
    appender_refs:
      - CONSOLE
  logger:
    - name: helloworld
      appender_refs:
        - CONSOLE
        - FILE
        - GELF_FILE
        - GRAYLOG
      level: debug      

sample code:

package main

import "github.com/shanexu/logn"

func main() {
    defer logn.Sync()
	helloWorld := logn.GetLogger("helloworld")
	helloWorld.Info("hello, shane!")

	some := logn.GetLogger("some")
	some.Infof("hello, %s", "shane")
}

Documentation

Index

Constants

View Source
const DefaultConfig = `` /* 225-byte string literal not displayed */

Variables

This section is empty.

Functions

func ConfigWithRawConfig added in v0.2.3

func ConfigWithRawConfig(rawConfig *common.Config) (core.Core, error)

func DPanic added in v0.2.3

func DPanic(args ...interface{})

DPanic uses fmt.Sprint to construct and log a message. In development, the logger then panics.

func DPanicf added in v0.2.3

func DPanicf(format string, args ...interface{})

DPanicf uses fmt.Sprintf to log a templated message. In development, the logger then panics.

func DPanicw added in v0.2.3

func DPanicw(msg string, keysAndValues ...interface{})

DPanicw logs a message with some additional context. The logger panics only in Development mode. The additional context is added in the form of key-value pairs. The optimal way to write the value to the log message will be inferred by the value's type. To explicitly specify a type you can pass a Field such as logp.Stringer.

func Debug added in v0.2.3

func Debug(args ...interface{})

func Debugf added in v0.2.3

func Debugf(format string, args ...interface{})

Debugf uses fmt.Sprintf to construct and log a message.

func Debugw added in v0.2.3

func Debugw(msg string, keysAndValues ...interface{})

Debugw logs a message with some additional context. The additional context is added in the form of key-value pairs. The optimal way to write the value to the log message will be inferred by the value's type. To explicitly specify a type you can pass a Field such as logp.Stringer.

func Error added in v0.2.3

func Error(args ...interface{})

Error uses fmt.Sprint to construct and log a message.

func Errorf added in v0.2.3

func Errorf(format string, args ...interface{})

Errorf uses fmt.Sprintf to log a templated message.

func Errorw added in v0.2.3

func Errorw(msg string, keysAndValues ...interface{})

Errorw logs a message with some additional context. The additional context is added in the form of key-value pairs. The optimal way to write the value to the log message will be inferred by the value's type. To explicitly specify a type you can pass a Field such as logp.Stringer.

func Fatal added in v0.2.3

func Fatal(args ...interface{})

Fatal uses fmt.Sprint to construct and log a message, then calls os.Exit(1).

func Fatalf added in v0.2.3

func Fatalf(format string, args ...interface{})

Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit(1).

func Fatalw added in v0.2.3

func Fatalw(msg string, keysAndValues ...interface{})

Fatalw logs a message with some additional context, then calls os.Exit(1). The additional context is added in the form of key-value pairs. The optimal way to write the value to the log message will be inferred by the value's type. To explicitly specify a type you can pass a Field such as logp.Stringer.

func GetLogger

func GetLogger(name ...string) core.Logger

func Info added in v0.2.3

func Info(args ...interface{})

Info uses fmt.Sprint to construct and log a message.

func Infof added in v0.2.3

func Infof(format string, args ...interface{})

Infof uses fmt.Sprintf to log a templated message.

func Infow added in v0.2.3

func Infow(msg string, keysAndValues ...interface{})

Infow logs a message with some additional context. The additional context is added in the form of key-value pairs. The optimal way to write the value to the log message will be inferred by the value's type. To explicitly specify a type you can pass a Field such as logp.Stringer.

func InitWithConfigContent added in v0.2.3

func InitWithConfigContent(content string) error

func InitWithConfigFile added in v0.2.3

func InitWithConfigFile(path string) error

func Panic added in v0.2.3

func Panic(args ...interface{})

Panic uses fmt.Sprint to construct and log a message, then panics.

func Panicf added in v0.2.3

func Panicf(format string, args ...interface{})

Panicf uses fmt.Sprintf to log a templated message, then panics.

func Panicw added in v0.2.3

func Panicw(msg string, keysAndValues ...interface{})

Panicw logs a message with some additional context, then panics. The additional context is added in the form of key-value pairs. The optimal way to write the value to the log message will be inferred by the value's type. To explicitly specify a type you can pass a Field such as logp.Stringer.

func Sync

func Sync()

func Warn added in v0.2.3

func Warn(args ...interface{})

Warn uses fmt.Sprint to construct and log a message.

func Warnf added in v0.2.3

func Warnf(format string, args ...interface{})

Warnf uses fmt.Sprintf to log a templated message.

func Warnw added in v0.2.3

func Warnw(msg string, keysAndValues ...interface{})

Warnw logs a message with some additional context. The additional context is added in the form of key-value pairs. The optimal way to write the value to the log message will be inferred by the value's type. To explicitly specify a type you can pass a Field such as logp.Stringer.

func With added in v0.2.8

func With(keysAndValues ...interface{}) core.Logger

func WithLogger added in v0.2.8

func WithLogger(l core.Logger, args ...interface{}) core.Logger

Types

This section is empty.

Jump to

Keyboard shortcuts

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