Exemplo n.º 1
0
func init() {
	debugLogger = golog.GetLogger("debug")
	debugLogger.Enable(appenders.File(golog.Conf{
		"path": "./debug.log",
	}))
	debugLogger.Disable(golog.StdoutAppender())
	debugLogger.Level = golog.DEBUG

	infoLogger = golog.GetLogger("info")
	infoLogger.Enable(appenders.File(golog.Conf{
		"path": "./info.log",
	}))
	infoLogger.Disable(golog.StdoutAppender())
	infoLogger.Level = golog.INFO

	warnLogger = golog.GetLogger("warn")
	warnLogger.Enable(appenders.File(golog.Conf{
		"path": "./warn.log",
	}))
	warnLogger.Disable(golog.StdoutAppender())
	warnLogger.Level = golog.WARN

	errorLogger = golog.GetLogger("error")
	errorLogger.Enable(appenders.File(golog.Conf{
		"path": "./error.log",
	}))
	errorLogger.Disable(golog.StdoutAppender())
	errorLogger.Level = golog.ERROR
}
Exemplo n.º 2
0
func init() {
	logPath := os.Getenv("LOG_PATH")
	if logPath == "" {
		logPath = "/tmp"
	}
	debugLogger = golog.GetLogger("debug")
	debugLogger.Enable(appenders.File(golog.Conf{
		"path": logPath + "/debug.log",
	}))
	debugLogger.Disable(golog.StdoutAppender())
	debugLogger.Level = golog.DEBUG

	infoLogger = golog.GetLogger("info")
	infoLogger.Enable(appenders.File(golog.Conf{
		"path": logPath + "/info.log",
	}))
	infoLogger.Disable(golog.StdoutAppender())
	infoLogger.Level = golog.INFO

	warnLogger = golog.GetLogger("warn")
	warnLogger.Enable(appenders.File(golog.Conf{
		"path": logPath + "/warn.log",
	}))
	warnLogger.Disable(golog.StdoutAppender())
	warnLogger.Level = golog.WARN

	errorLogger = golog.GetLogger("error")
	errorLogger.Enable(appenders.File(golog.Conf{
		"path": logPath + "/error.log",
	}))
	errorLogger.Disable(golog.StdoutAppender())
	errorLogger.Level = golog.ERROR
}
Exemplo n.º 3
0
func Log(ctx *neo.Ctx, next neo.Next) {
	start := time.Now()
	logger := golog.GetLogger("github.com/ivpusic/neo")
	method := ctx.Req.Method
	path := ctx.Req.URL.Path

	logger.Info("--> [Req] " + method + " to " + path)

	next()

	status := strconv.Itoa(ctx.Res.Status)
	elapsed := int(time.Now().Sub(start) / time.Millisecond)

	logger.Info("<-- [Res] (" + status + ") " + method + " to " + path + " Took " + strconv.Itoa(elapsed) + "ms")
}
Exemplo n.º 4
0
// Application initialization.
func (a *Application) init(confFile string) {
	a.InitEBus()
	a.initRouter()
	a.initConf(confFile)

	// neo logger
	lvl, err := parseLogLevel(a.Conf.Neo.Logger.Level)
	if err != nil {
		log.Warn(err)
	} else {
		log.Level = lvl
	}

	// application logger
	lvl, err = parseLogLevel(a.Conf.App.Logger.Level)
	a.Logger = golog.GetLogger(a.Conf.App.Logger.Name)
	if err != nil {
		log.Warn(err)
	} else {
		a.Logger.Level = lvl
	}
}
Exemplo n.º 5
0
func advanced() {
	logger := golog.Default
	logger.Debug("some message")

	// you can provide additional data to log
	additionalData := &TestStruct{}
	logger.Debug("some message", additionalData)

	// you can require logger instance
	application := golog.GetLogger("application")

	// set log level
	application.Level = golog.WARN

	application.Info("log from application logger")

	appender := appenders.File(golog.Conf{
		"path": "/path/to/log.txt",
	})

	// you can enable appender
	application.Enable(appender)

	// you can disable appender by passing reference
	application.Disable(appender)

	// you can disable appender by passing appender id
	// id is returned with appender.Id() method
	application.Disable("github.com/ivpusic/golog/appender/file")

	// you can disable some logger completely
	// you have to provide logger name in order to disable it
	golog.Disable("github.com/someuser/somelib")

	// all loggers are enabled by default
	// if you have case that at some point you disable it,
	// and later you want to enable it again, you can use this method
	golog.Enable("github.com/someuser/somelib")
}
Exemplo n.º 6
0
		Deads []*User
	}

	StatData struct {
		Total int
		Stat  []Stat
	}

	Stat struct {
		User  string
		Count int64
		Perc  float64
	}
)

var neo_log = golog.GetLogger("application")

func (d *StatData) Len() int { return len(d.Stat) }

func (d *StatData) Less(i, j int) bool { return d.Stat[i].Count > d.Stat[j].Count }

func (d *StatData) Swap(i, j int) { d.Stat[i], d.Stat[j] = d.Stat[j], d.Stat[i] }

func loadTpl(name string) (ret *template.Template, err error) {
	tn := filepath.Join("tpl", name+".tpl")
	if _, err = os.Stat(tn); err == nil {
		ret, err = template.ParseFiles(tn)
	}
	return
}
Exemplo n.º 7
0
package ebus

import (
	"container/list"
	"github.com/ivpusic/golog"
)

var log = golog.GetLogger("github.com/ivpusic/neo")

// Handler for event
type EvHandler func(interface{})

// Map with name of event and list of listeners.
type events map[string]list.List

type EBus struct {
	eventList events
}

func (b *EBus) InitEBus() {
	b.eventList = events{}
}

// Registering listener for provided event.
func (e *EBus) On(event string, fn EvHandler) {
	log.Debugf("registering event `%s`", event)
	topic, ok := e.eventList[event]

	if !ok {
		topic = list.List{}
	}
Exemplo n.º 8
0
)

type (
	Checker struct {
		t        *testing.T
		handler  http.Handler
		request  *http.Request
		response *http.Response
		cookies  map[string]string
	}

	Callback func(*http.Response)
)

var (
	logger = golog.GetLogger("github.com/ivpusic/httpcheck")
)

func New(t *testing.T, handler http.Handler) *Checker {
	logger.Level = golog.INFO

	instance := &Checker{
		t:       t,
		handler: handler,
		cookies: map[string]string{},
	}

	return instance
}

// make request /////////////////////////////////////////////////
Exemplo n.º 9
0
package main

import (
	"os"
	"os/signal"
	"syscall"

	"github.com/ivpusic/golog"
)

var (
	logger    = golog.GetLogger("github.com/ivpusic/rerun")
	TEST_MODE = false
)

func main() {
	conf, err := loadConfiguration()
	if err != nil {
		logger.Panicf("Error while loading configuration! %s", err.Error())
	}

	// setup logger level
	if *verbose {
		logger.Level = golog.DEBUG
	} else {
		logger.Level = golog.INFO
	}

	pm := &processManager{
		conf: conf,
	}