clog

package module
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2019 License: MIT Imports: 8 Imported by: 3

README

colored-log

Pretty colored logger for Golang

Preview

example

Install

go get github.com/ShoshinNikita/log/v2

Example

Example program

package main

import (
    clog "github.com/ShoshinNikita/log/v2"
)

func main() {
    // For prod use log.NewProdConfig() or log.NewProdLogger()
    // For dev use log.NewDevConfig() or log.NewDevLogger()

    c := &clog.Config{}
    l := c.PrintColor(true).PrintErrorLine(true).PrintTime(true).Debug(true).Build()
    l.Debugln("some debug message")
    l.Infoln("some info message")
    l.Warnln("some warn message")
    l.Errorln("some error message")

    l.WriteString("\n")

    c = &clog.Config{}
    l = c.PrintColor(true).PrintErrorLine(false).PrintTime(false).Debug(true).Build()
    l.Debugln("some debug message")
    l.Infoln("some info message")
    l.Warnln("some warn message")
    l.Errorln("some error message")

    l.WriteString("\n")

    c = &clog.Config{}
    l = c.PrintColor(false).PrintErrorLine(false).PrintTime(false).Debug(true).Build()
    l.Debugln("some debug message")
    l.Infoln("some info message")
    l.Warnln("some warn message")
    l.Errorln("some error message")

    l.WriteString("\n")

    c = &clog.Config{}
    l = c.PrintColor(false).PrintErrorLine(false).PrintTime(false).Debug(false).Build()
    l.Debugln("some debug message")
    l.Infoln("some info message")
    l.Warnln("some warn message")
    l.Errorln("some error message")
}

Documentation

Overview

Package log provides functions for pretty print

Patterns of functions print:

* (?time) msg - Print(), Printf(), Println():

* (?time) [DBG] msg - Debug(), Debugf(), Debugln():

* (?time) [INF] msg - Info(), Infof(), Infoln():

* (?time) [WRN] warning - Warn(), Warnf(), Warnln():

* (?time) [ERR] (?file:line) error - Error(), Errorf(), Errorln():

* (?time) [FAT] (?file:line) error - Fatal(), Fatalf(), Fatalln():

Time pattern: MM.dd.yyyy hh:mm:ss (01.30.2018 05:5:59)

Index

Constants

View Source
const (
	DefaultTimeLayout = "01.02.2006 15:04:05"
)

Variables

This section is empty.

Functions

func Error

func Error(v ...interface{})

Error prints error Output pattern: (?time) [ERR] (?file:line) error

func Errorf

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

Errorf prints error Output pattern: (?time) [ERR] (?file:line) error

func Errorln

func Errorln(v ...interface{})

Errorln prints error Output pattern: (?time) [ERR] (?file:line) error

func Fatal

func Fatal(v ...interface{})

Fatal prints error and call os.Exit(1) Output pattern: (?time) [FAT] (?file:line) error

func Fatalf

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

Fatalf prints error and call os.Exit(1) Output pattern: (?time) [FAT] (?file:line) error

func Fatalln

func Fatalln(v ...interface{})

Fatalln prints error and call os.Exit(1) Output pattern: (?time) [FAT] (?file:line) error

func Info

func Info(v ...interface{})

Info prints info message Output pattern: (?time) [INF] msg

func Infof

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

Infof prints info message Output pattern: (?time) [INF] msg

func Infoln

func Infoln(v ...interface{})

Infoln prints info message Output pattern: (?time) [INF] msg

func Print

func Print(v ...interface{})

Print prints msg Output pattern: (?time) msg

func Printf

func Printf(format string, v ...interface{})

Printf prints msg Output pattern: (?time) msg

func Println

func Println(v ...interface{})

Println prints msg Output pattern: (?time) msg

func Warn

func Warn(v ...interface{})

Warn prints warning Output pattern: (?time) [WRN] warning

func Warnf

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

Warnf prints warning Output pattern: (?time) [WRN] warning

func Warnln

func Warnln(v ...interface{})

Warnln prints warning Output pattern: (?time) [WRN] warning

Types

type Config

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

func NewDevConfig

func NewDevConfig() *Config

func NewProdConfig

func NewProdConfig() *Config

func (*Config) Build

func (c *Config) Build() *Logger

Build create a new Logger according to Config

func (*Config) Debug added in v2.1.0

func (c *Config) Debug(b bool) *Config

Debug sets Config.debug to b

func (*Config) PrintColor

func (c *Config) PrintColor(b bool) *Config

PrintColor sets Config.printColor to b

func (*Config) PrintErrorLine

func (c *Config) PrintErrorLine(b bool) *Config

PrintErrorLine sets Config.printErrorLine to b

func (*Config) PrintTime

func (c *Config) PrintTime(b bool) *Config

PrintTime sets Config.printTime to b

func (*Config) SetOutput

func (c *Config) SetOutput(w io.Writer) *Config

SetOutput changes Config.output writer.

func (*Config) SetTimeLayout

func (c *Config) SetTimeLayout(layout string) *Config

SetTimeLayout changes Config.timeLayout Default Config.timeLayout is DefaultTimeLayout

type Logger

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

func NewDevLogger

func NewDevLogger() *Logger

func NewProdLogger

func NewProdLogger() *Logger

func (Logger) Debug added in v2.1.0

func (l Logger) Debug(v ...interface{})

Debug prints debug message if Debug mode is on Output pattern: (?time) [DBG] msg

func (Logger) Debugf added in v2.1.0

func (l Logger) Debugf(format string, v ...interface{})

Debugf prints debug message if Debug mode is on Output pattern: (?time) [DBG] msg

func (Logger) Debugln added in v2.1.0

func (l Logger) Debugln(v ...interface{})

Debugln prints debug message if Debug mode is on Output pattern: (?time) [DBG] msg

func (Logger) Error

func (l Logger) Error(v ...interface{})

Error prints error Output pattern: (?time) [ERR] (?file:line) error

func (Logger) Errorf

func (l Logger) Errorf(format string, v ...interface{})

Errorf prints error Output pattern: (?time) [ERR] (?file:line) error

func (Logger) Errorln

func (l Logger) Errorln(v ...interface{})

Errorln prints error Output pattern: (?time) [ERR] (?file:line) error

func (Logger) Fatal

func (l Logger) Fatal(v ...interface{})

Fatal prints error and call os.Exit(1) Output pattern: (?time) [FAT] (?file:line) error

func (Logger) Fatalf

func (l Logger) Fatalf(format string, v ...interface{})

Fatalf prints error and call os.Exit(1) Output pattern: (?time) [FAT] (?file:line) error

func (Logger) Fatalln

func (l Logger) Fatalln(v ...interface{})

Fatalln prints error and call os.Exit(1) Output pattern: (?time) [FAT] (?file:line) error

func (Logger) Info

func (l Logger) Info(v ...interface{})

Info prints info message Output pattern: (?time) [INF] msg

func (Logger) Infof

func (l Logger) Infof(format string, v ...interface{})

Infof prints info message Output pattern: (?time) [INF] msg

func (Logger) Infoln

func (l Logger) Infoln(v ...interface{})

Infoln prints info message Output pattern: (?time) [INF] msg

func (Logger) Print

func (l Logger) Print(v ...interface{})

Print prints msg Output pattern: (?time) msg

func (Logger) Printf

func (l Logger) Printf(format string, v ...interface{})

Printf prints msg Output pattern: (?time) msg

func (Logger) Println

func (l Logger) Println(v ...interface{})

Println prints msg Output pattern: (?time) msg

func (Logger) Warn

func (l Logger) Warn(v ...interface{})

Warn prints warning Output pattern: (?time) [WRN] warning

func (Logger) Warnf

func (l Logger) Warnf(format string, v ...interface{})

Warnf prints warning Output pattern: (?time) [WRN] warning

func (Logger) Warnln

func (l Logger) Warnln(v ...interface{})

Warnln prints warning Output pattern: (?time) [WRN] warning

func (*Logger) Write

func (l *Logger) Write(b []byte)

func (*Logger) WriteString

func (l *Logger) WriteString(s string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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