log

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2021 License: MIT Imports: 6 Imported by: 41

README

log

A simple log primative Open Privacy uses

Examples:

log.AddEverythingFromPattern("connectivity")
log.SetLevel(log.LevelDebug)
log.ExcludeFromPattern("connection/connection")
log.ExcludeFromPattern("outbound/3dhauthchannel")
log.AddPrivacyFilter(func(s string) bool {
    return len(s) == 56
})
log.SetPrivacyFilterReplace(true)

log.Debugf("Creating the thing with param %v\n", param)
log.Infoln("Doing thing X")
log.Warnf("This might be bad: %v\n", err)
log.Errorf("Failed to do thing: %v\n", err)
Making log go to a file
if runtime.GOOS == "windows" {
	filelogger, err := log.NewFile(log.LevelInfo, "cwtch_log.txt")
	if err == nil {
		log.SetStd(filelogger)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Debug = Teal
	Info  = Green
	Warn  = Yellow
	Error = Red
)

*** Color code from https://gist.github.com/ik5/d8ecde700972d4378d87 ***

View Source
var (
	Black   = Color("\033[1;30m%s\033[0m")
	Red     = Color("\033[1;31m%s\033[0m")
	Green   = Color("\033[1;32m%s\033[0m")
	Yellow  = Color("\033[1;33m%s\033[0m")
	Purple  = Color("\033[1;34m%s\033[0m")
	Magenta = Color("\033[1;35m%s\033[0m")
	Teal    = Color("\033[1;36m%s\033[0m")
	White   = Color("\033[1;37m%s\033[0m")
)

Functions

func AddEverythingFromPattern

func AddEverythingFromPattern(pattern string)

AddEverythingFromPattern adds a pattern to skip log level filtering, guaranteeing all logs matching the pattern are seen

func AddNothingExceptFilter

func AddNothingExceptFilter(pattern string)

AddNothingExceptFilter enables strong filtering showing logs only for things on the approved list, adding this pattern to the list

func AddPrivacyFilter added in v1.0.2

func AddPrivacyFilter(fn func(string) bool)

AddPrivacyFilter adds a function applied to printf argument strings that can flag them as sensitive data

func Color added in v1.0.1

func Color(colorString string) func(...interface{}) string

func Debugf

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

Debugf outputs the format and variables at the Debug level

func Debugln

func Debugln(v ...interface{})

Debugln outputs the variables at the Debug level

func Errorf

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

Errorf outputs the format and variables at the Error level

func Errorln

func Errorln(v ...interface{})

Errorln outputs the variables at the Error level

func ExcludeFromPattern

func ExcludeFromPattern(pattern string)

ExcludeFromPattern adds a pattern to exclude logs from

func Infof

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

Infof outputs the format and variables at the Info level

func Infoln

func Infoln(v ...interface{})

Infoln outputs the variables at the Info level

func Printf

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

Printf outputs the format with variables assuming it passes the filter level

func Println

func Println(level Level, v ...interface{})

Println outputs the varibles assuming they pass the filter level

func SetLevel

func SetLevel(level Level)

SetLevel changes the filtering level of the system logger

func SetPrivacyFilterReplace added in v1.0.2

func SetPrivacyFilterReplace(b bool)

SetPrivacyFilterReplace replaces the string argument to printf that a Privacy Filter identified with ****s

func SetStd

func SetStd(logger *Logger)

SetStd sets the default logger all other functions use

func SetUseColor added in v1.0.1

func SetUseColor(useColor bool)

SetUseColor toggles weather color output is used

func Warnf

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

Warnf outputs the format and variables at the Warning level

func Warnln

func Warnln(v ...interface{})

Warnln outputs the variables at the Warn level

Types

type Level

type Level int

Level indicates the level a log should be classified at

const (
	LevelDebug Level = iota + 1
	LevelInfo
	LevelWarn
	LevelError
)

The possible levels a log can have

type Logger

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

Logger is a go Logger wrapper that adds log levels and pattern filtering It allows high level 'log level' filtering broadly It allows allows two addition levels of filtering:

everythingFrom which allows inclusion of packages/patterns along with general logging
nothingExcept which allows focusing on just listed areas
privacyFilters by default apply all functions to printf args and add warnings to them for matches
privacyFilterReplace obscures any matches from the privacy filter functions

func New

func New(level Level) *Logger

New returns a new Logger with a filter set to the supplied level

func NewFile

func NewFile(level Level, filename string) (*Logger, error)

NewFile returns a new Logger that logs to the supplied file with a filter set to the supplied level

func (*Logger) AddEverythingFromPattern

func (l *Logger) AddEverythingFromPattern(pattern string)

AddEverythingFromPattern adds a pattern to skip log level filtering, guaranteeing all logs matching the pattern are seen

func (*Logger) AddNothingExceptFilter

func (l *Logger) AddNothingExceptFilter(pattern string)

AddNothingExceptFilter enables strong filtering showing logs only for things on the approved list, adding this pattern to the list

func (*Logger) AddPrivacyFilter added in v1.0.2

func (l *Logger) AddPrivacyFilter(fn func(string) bool)

func (*Logger) ExcludeFromPattern

func (l *Logger) ExcludeFromPattern(pattern string)

ExcludeFromPattern adds a pattern to exclude logs from

func (*Logger) Printf

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

Printf outputs the format and variables, assuming it passes the filter levels

func (*Logger) Println

func (l *Logger) Println(level Level, v ...interface{})

Println outputs the variables assuming the filter levels are passed

func (*Logger) SetLevel

func (l *Logger) SetLevel(level Level)

SetLevel adjusts the output filter by logging level

func (*Logger) SetPrivacyFilterReplace added in v1.0.2

func (l *Logger) SetPrivacyFilterReplace(b bool)

func (*Logger) SetUseColor added in v1.0.1

func (l *Logger) SetUseColor(useColor bool)

SetUseColor toggles weather color output is used

Jump to

Keyboard shortcuts

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