j

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2019 License: MIT Imports: 7 Imported by: 0

README

j

golang logger

Documentation

Index

Examples

Constants

View Source
const (
	CallerNone = callerType(iota + 1)
	CallerShort
	CallerLong
)

just like Lshortfile/Llongfile in pkg/log

View Source
const (
	TimeMS      = `15:04:05.000 `
	TimeDayMS   = `02 15:04:05.000 `
	TimeMonthMS = `01-02 15:04:05.000 `
	TimeYearMS  = `2006-01-02 15:04:05.000 `
	Time        = `15:04:05 `
	TimeDay     = `02 15:04:05 `
	TimeMonth   = `01-02 15:04:05 `
	TimeYear    = `2006-01-02 15:04:05 `
	TimeNS      = `15:04:05.000000000 `
)

time format in config

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Filename   string
	Echo       bool // stdout
	Append     bool
	Prefix     string
	TimeFormat string
	Tunnel     int // channel buffer size
	FileFunc   func(t *time.Time) (filename string)
	LineFunc   func(line *string)
	Caller     callerType
}

Config ...

type Logger

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

Logger ...

func New

func New(c *Config) (o *Logger, err error)

New create a new logger with config

func NewEcho

func NewEcho() (o *Logger)

NewEcho create a new logger without file, only stdout

func NewFile

func NewFile(filename string) (o *Logger, err error)

NewFile create a new logger with filename

func NewFunc

func NewFunc(fn func(t *time.Time) (filename string)) (o *Logger, err error)

NewFunc create a new logger with FileFunc

Example
package main

import (
	"time"

	"github.com/zhengkai/j"
)

func main() {

	jx, _ := j.NewFunc(func(t *time.Time) string {
		return t.Format(`log/01-02/15.log`)
	})
	jx.Log(`file func`)
}

func (*Logger) BR

func (o *Logger) BR() (err error)

BR add an empty line

func (*Logger) Close

func (o *Logger) Close()

Close ...

func (*Logger) Color

func (o *Logger) Color(s string) (err error)

Color Set ANSI color

func (*Logger) ColorOnce

func (o *Logger) ColorOnce(s string) (err error)

ColorOnce Set ANSI color, only next one log

func (*Logger) ColorReset

func (o *Logger) ColorReset() (err error)

ColorReset clean ANSI color

func (*Logger) Compact

func (o *Logger) Compact(format string, a ...interface{}) (err error)

Compact just like fmt.Print, but no spaces

func (*Logger) Enable

func (o *Logger) Enable(is bool)

Enable ...

func (*Logger) Log

func (o *Logger) Log(a ...interface{}) (err error)

Log just like log.Println

func (*Logger) Logf

func (o *Logger) Logf(format string, a ...interface{}) (err error)

Logf just like log.Printf

func (*Logger) Print

func (o *Logger) Print(format string, a ...interface{}) (err error)

Print just like log.Print, added linebreak

func (*Logger) Raw

func (o *Logger) Raw(a ...interface{}) (err error)

Raw log raw (no time, no linebreak, no spaces)

Jump to

Keyboard shortcuts

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