コード例 #1
0
ファイル: logging.go プロジェクト: JasonGiedymin/test-flight
// Sets up Loggers
func Setup() {
	maxLevel := func(verbosity int) int {
		max := len(levels)
		if verbosity > max {
			return max
		}
		return verbosity
	}

	Log = factorlog.New(
		os.Stdout,
		factorlog.NewStdFormatter(stdLogFormat))

	LogDebug = factorlog.New(
		os.Stdout,
		factorlog.NewStdFormatter(debugLogFormat))

	LogConsole = factorlog.New(
		os.Stdout,
		factorlog.NewStdFormatter(consoleLogFormat))

	Log.SetMinMaxSeverity(levels[maxLevel(verbosity)], factorlog.ERROR)

	// Do not set logdebug and logconsole
	// LogDebug.SetMinMaxSeverity(levels[maxLevel(verbosity)], factorlog.ERROR)
	// LogConsole.SetMinMaxSeverity(levels[maxLevel(verbosity)], factorlog.ERROR)

	if verbosity >= maxVerbosity {
		File = factorlog.New(
			debugFile,
			factorlog.NewStdFormatter(fileLogFormat))
	}
}
コード例 #2
0
ファイル: interface.go プロジェクト: xiaoxiaoyijian/logger
func SetGlobalLogger(logPath string) *log.FactorLog {
	sfmt := `%{Color "red:white" "CRITICAL"}%{Color "red" "ERROR"}%{Color "yellow" "WARN"}%{Color "green" "INFO"}%{Color "cyan" "DEBUG"}%{Color "blue" "TRACE"}[%{Date} %{Time}] [%{SEVERITY}:%{ShortFile}:%{Line}] %{Message}%{Color "reset"}`
	logger := log.New(os.Stdout, log.NewStdFormatter(sfmt))
	if len(logPath) > 0 {
		logf, err := os.OpenFile(logPath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0640)
		if err != nil {
			return logger
		}
		logger = log.New(logf, log.NewStdFormatter(sfmt))
	}
	logger.SetSeverities(log.INFO | log.WARN | log.ERROR | log.FATAL | log.CRITICAL)
	return logger
}
コード例 #3
0
ファイル: Logger.go プロジェクト: Griesbacher/Yarbes
//InitLogger creates a factorlog with the given min loglevel
func InitLogger(minSeverity string) {
	mutex.Lock()
	logFormatter := factorlog.NewStdFormatter(logColors + logFormat)
	targetWriter := os.Stdout
	singleLogger = factorlog.New(targetWriter, logFormatter)
	singleLogger.SetMinMaxSeverity(factorlog.StringToSeverity(minSeverity), factorlog.StringToSeverity("PANIC"))
	mutex.Unlock()
}
コード例 #4
0
ファイル: main.go プロジェクト: zhaozhi406/factorlog
func main() {
	frmt := `%{Color "red" "ERROR"}%{Color "yellow" "WARN"}%{Color "green" "INFO"}%{Color "cyan" "DEBUG"}%{Color "blue" "TRACE"}[%{Date} %{Time}] [%{SEVERITY}:%{File}:%{Line}] %{Message}%{Color "reset"}`
	log := factorlog.New(os.Stdout, factorlog.NewStdFormatter(frmt))
	log.Error("Severity: Error occurred")
	log.Warn("Severity: Warning!!!")
	log.Info("Severity: I have some info for you")
	log.Debug("Severity: Debug what?")
	log.Trace("Severity: Tracing your IP... muauahaha")
}
コード例 #5
0
ファイル: main.go プロジェクト: zhaozhi406/factorlog
func main() {
	log := factorlog.New(os.Stdout, gelf.NewGELFFormatter())
	log.Print("GELF formatter")

	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		log.Print("GELF: client connected", gelf.Extra{"_hello": "there"}, r)
	}))

	http.Get(server.URL)
}
コード例 #6
0
ファイル: logging.go プロジェクト: Griesbacher/nagflux
//InitLogger Constructor.
func InitLogger(logFile, minSeverity string) {
	var logFormatter factorlog.Formatter
	var targetWriter io.Writer
	var err error
	if logFile == "" {
		logFormatter = factorlog.NewStdFormatter(logColors + logFormat)
		targetWriter = os.Stdout
	} else {
		logFormatter = factorlog.NewStdFormatter(logFormat)
		targetWriter, err = os.OpenFile(logFile, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644)
	}
	if err != nil {
		panic(err)
	}
	singleLogger = factorlog.New(targetWriter, logFormatter)
	singleLogger.SetMinMaxSeverity(factorlog.StringToSeverity(minSeverity), factorlog.StringToSeverity("PANIC"))
}
コード例 #7
0
ファイル: logging.go プロジェクト: samahee/nagflux
//Logger Constructor.
func InitLogger(logFile, minSeverity string) {
	var logFormatter factorlog.Formatter
	var targetWriter io.Writer
	var err error
	if logFile == "" {
		logFormatter = factorlog.NewStdFormatter(logColors + logFormat)
		targetWriter = os.Stdout
	} else {
		logFormatter = factorlog.NewStdFormatter(logFormat)
		if _, err := os.Stat(logFile); err == nil {
			targetWriter, err = os.Create(logFile)
		} else {
			targetWriter, err = os.Open(logFile)
		}
	}
	if err != nil {
		panic(err)
	}
	singleLogger = factorlog.New(targetWriter, logFormatter)
	singleLogger.SetMinMaxSeverity(factorlog.StringToSeverity(minSeverity), factorlog.StringToSeverity("PANIC"))
}
コード例 #8
0
// We need initialize logging before all other modules.
// It don't matter in regular program run but critical for unit tests.
func init() {
	var (
		debug  = flag.Bool("debug", false, "debug output")
		verb   = flag.Bool("verb", false, "verbose output")
		listen = flag.String("listen", "http://127.1:48084/ws", "listen HTTP requests at addr:port/path")
		logFmt string
		err    error
	)

	flag.Parse()
	listenURL, err = url.Parse(*listen)

	if *debug {
		// brief format for debug
		logFmt = `%{Color "red" "ERROR"}%{Color "red" "FATAL"}%{Color "yellow" "WARN"}%{Color "green" "INFO"}%{Color "cyan" "DEBUG"}%{Color "blue" "TRACE"}[%{Date} %{Time}] [%{SEVERITY}:%{File}:%{Line}] %{Message}%{Color "reset"}`
	} else {
		// short format for production
		logFmt = `%{Color "red" "ERROR"}%{Color "red" "FATAL"}%{Color "yellow" "WARN"}%{Color "green" "INFO"}%{Color "cyan" "DEBUG"}%{Color "blue" "TRACE"}[%{Date} %{Time}] [%{SEVERITY}] %{Message}%{Color "reset"}`
	}

	log = factorlog.New(os.Stderr, factorlog.NewStdFormatter(logFmt))

	switch {
	case *debug:
		log.SetMinMaxSeverity(factorlog.TRACE, factorlog.PANIC)
	case *verb:
		log.SetMinMaxSeverity(factorlog.INFO, factorlog.PANIC)
	default:
		log.SetMinMaxSeverity(factorlog.WARN, factorlog.PANIC)
	}

	if err != nil {
		log.Criticalf("bad url %s", *listen)
		os.Exit(1)
	}
	if listenURL.Path == "" {
		listenURL.Path = "/"
	}
}
コード例 #9
0
ファイル: main.go プロジェクト: zhaozhi406/factorlog
func main() {
	log := factorlog.New(os.Stdout, factorlog.NewStdFormatter(`%{Color "magenta"}[%{Date} %{Time}] %{Color "cyan"}[%{SEVERITY}:%{File}:%{Line}] %{Color "yellow"}%{Message}%{Color "reset"}`))
	log.Println("Color")
}
コード例 #10
0
ファイル: main.go プロジェクト: zhaozhi406/factorlog
func main() {
	log := factorlog.New(os.Stdout, factorlog.NewStdFormatter("%{Date} %{Time} %{File}:%{Line} %{Message}"))
	log.Println("Basic formatter")
}
コード例 #11
0
ファイル: nlp.go プロジェクト: payfriendz/go-freeling
func init() {
	frmt := `%{Color "red" "ERROR"}%{Color "yellow" "WARN"}%{Color "green" "INFO"}%{Color "cyan" "DEBUG"}%{Color "blue" "TRACE"}[%{Date} %{Time}] [%{SEVERITY}:%{File}:%{Line}] %{Message}%{Color "reset"}`
	LOG = factorlog.New(os.Stdout, factorlog.NewStdFormatter(frmt))
	LOG.SetMinMaxSeverity(factorlog.PANIC, factorlog.TRACE)
}
コード例 #12
0
ファイル: main.go プロジェクト: zhaozhi406/factorlog
func main() {
	log := log.New(os.Stdout, NewCustomFormatter())
	log.Println("Custom formatter")
}
コード例 #13
0
ファイル: phantom.go プロジェクト: Marmeladenbrot/Crawler
package main

import (
	"fmt"
	"github.com/kdar/factorlog"
	"io/ioutil"
	"net/http"
	"os"
	"strings"
)

var ip = "http://127.0.0.1:8080"
var file, _ = os.OpenFile("logfile.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
var logg = factorlog.New(os.Stdout, factorlog.NewStdFormatter("%{Message}"))
var loggFile = factorlog.New(file, factorlog.NewStdFormatter("%{Message}"))

func Phantom(link string) {

	buf := strings.NewReader(link)
	resp, err := http.Post(ip, "text/plain", buf)
	if err != nil {
		fmt.Println(err)
		return
	}
	defer resp.Body.Close()
	bodyBytes, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		fmt.Println(err)
		return
	}
	bodyString := string(bodyBytes)
コード例 #14
0
ファイル: main.go プロジェクト: zhaozhi406/factorlog
func main() {
	log := factorlog.New(os.Stdout, glog.NewGlogFormatter())
	log.Print("Glog formatter")
}
コード例 #15
0
ファイル: factorlog.go プロジェクト: Marmeladenbrot/Crawler
func Logger() {
	file, _ := os.OpenFile("logfile.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
	log := factorlog.New(file, factorlog.NewStdFormatter("%{Date} %{Time}\tLOG\t%{Message}"))
	log.Println("Innerhalb Basic formatter")
}
コード例 #16
0
ファイル: logging.go プロジェクト: kiesel/xp-runners-go
func init() {
	Log = new(log.NullLogger)
	if dbg := os.Getenv("XP_DBG"); dbg != "" {
		Log = log.New(os.Stdout, log.NewStdFormatter("%{File}:%{Line} >> %{Message}"))
	}
}
コード例 #17
0
ファイル: logging.go プロジェクト: Griesbacher/nagflux
//InitTestLogger creates logger for testing
func InitTestLogger() {
	singleLogger = factorlog.New(os.Stderr, factorlog.NewStdFormatter(""))
}