Ejemplo n.º 1
0
func NewLog15() Log15 {
	log := Log15{
		log: log15.Root(),
	}

	return log
}
Ejemplo n.º 2
0
func NewLogged() *Logged {
	return &Logged{
		Loggers:       []log.Logger{log.Root()},
		DefaultFormat: "term",
		DefaultLevel:  "info",
		DefaultTarget: "stdout",
	}
}
Ejemplo n.º 3
0
func init() {
	var handler log.Handler
	if term.IsTty(os.Stdout.Fd()) {
		handler = log.StreamHandler(os.Stdout, log.TerminalFormat())
	} else {
		handler = log.StreamHandler(os.Stdout, log.JsonFormat())
	}
	log.Root().SetHandler(handler)
	ncr.Log.SetHandler(handler)
}
Ejemplo n.º 4
0
func buildCluster(numberOfMasters int) *cluster {

	startPort := 6061
	rafts := make([]*Raft, numberOfMasters)

	for i := 0; i < numberOfMasters; i++ {

		// dir name
		fsm := NewLogFSM()

		rc := DefaultConfig()
		rc.Bind = fmt.Sprintf("127.0.0.1:%d", startPort+i)
		rc.Advertise = fmt.Sprintf("localhost:%d", startPort+i)
		rc.StateMachine = fsm
		rc.BaseDir = fmt.Sprintf("/tmp/rafttest/raftdir%d", i)
		rc.SnapshotInterval = 10 * time.Second

		// create tls for server
		rc.TLSConfig = serverTLS()
		rc.ClientTLSConfig = clientTLS()

		rc.LeaderChange = &testLeaderChange{}

		rc.ForwardCmds = true

		// create a list of peers
		var peers []string
		for a := 0; a < numberOfMasters; a++ {
			if startPort+i != startPort+a {
				peers = append(peers, fmt.Sprintf("localhost:%d", startPort+a))
			}
		}

		rc.Peers = peers
		raft, err := NewRaft(rc, log15.Root())

		props := make(map[string]string, 1)
		props["number"] = strconv.Itoa(i + 10)
		raft.PropertiesSet(props)

		if err != nil {
			log.Fatalf("Can not create raft: %s", err.Error())
		}

		// set logger of raft
		fsm.ParentLogger(raft.logger)

		rafts[i] = raft

	}

	return &cluster{
		rafts: rafts}

}
Ejemplo n.º 5
0
func init() {
	// Set global logging levels by the flag, default to WARN if not defined
	var level string
	flag.StringVar(&level, "level", "WARN", "a string")
	flag.StringVar(&confPath, "conf", "config/gologgen.conf", "a string")

	flag.Parse()

	switch level {
	case "DEBUG":
		log15.Root().SetHandler(log15.LvlFilterHandler(log15.LvlDebug, log15.StdoutHandler))
	case "INFO":
		log15.Root().SetHandler(log15.LvlFilterHandler(log15.LvlInfo, log15.StdoutHandler))
	case "WARN":
		log15.Root().SetHandler(log15.LvlFilterHandler(log15.LvlWarn, log15.StdoutHandler))
	case "ERROR":
		log15.Root().SetHandler(log15.LvlFilterHandler(log15.LvlError, log15.StdoutHandler))
	default:
		log15.Root().SetHandler(log15.LvlFilterHandler(log15.LvlWarn, log15.StdoutHandler))
	}

	log = log15.New("function", log15.Lazy{Fn: loghelper.Log15LazyFunctionName})
}
Ejemplo n.º 6
0
func ConfigureRootLogger() {
	sh := log.StreamHandler(colorable.NewColorableStdout(), log.TerminalFormat())

	logLevel := log.LvlInfo

	if showDebug == true {
		logLevel = log.LvlDebug
	} else {
		_, found := os.LookupEnv("DEBUG")
		if found == true {
			logLevel = log.LvlDebug
		}
	}

	fh := log.LvlFilterHandler(logLevel, sh)
	cfh := log.CallerFileHandler(fh)
	log.Root().SetHandler(cfh)
}
Ejemplo n.º 7
0
func setSettings(level int, filename string) {
	logFilename = filename
	debug = level

	filehandler := log.Must.FileHandler(filename, log.LogfmtFormat())
	handler := log.MultiHandler(
		filehandler,
		log.StreamHandler(os.Stderr, log.TerminalFormat()))
	if debug > 1 {
		handler = log.CallerStackHandler("%+v", handler)
	} else {
		handler = log.CallerFileHandler(handler)
	}
	if debug < 1 {
		handler = log.LvlFilterHandler(log.LvlInfo, handler)
	}
	log.Root().SetHandler(handler)
	log.Info("Logging started", "level", debug, "log_file", logFilename)
}
Ejemplo n.º 8
0
func TestFetchFeed(t *testing.T) {
	pool := newConnPool(t)

	rssBody := []byte(`<?xml version='1.0' encoding='UTF-8'?>
<rss>
  <channel>
    <title>News</title>
    <item>
      <title>Snow Storm</title>
      <link>http://example.org/snow-storm</link>
      <pubDate>Fri, 03 Jan 2014 22:45:00 GMT</pubDate>
    </item>
    <item>
      <title>Blizzard</title>
      <link>http://example.org/blizzard</link>
      <pubDate>Sat, 04 Jan 2014 08:15:00 GMT</pubDate>
    </item>
  </channel>
</rss>
</xml>`)

	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Write(rssBody)
	}))
	defer ts.Close()

	u := NewFeedUpdater(pool, log.Root())
	rawFeed, err := u.fetchFeed(ts.URL, data.String{})
	if err != nil {
		t.Fatalf("Unexpected error: %v", err)
	}
	if rawFeed.url != ts.URL {
		t.Errorf("rawFeed.url should match requested url but instead it was: %v", rawFeed.url)
	}
	if bytes.Compare(rssBody, rawFeed.body) != 0 {
		t.Errorf("rawFeed body should match returned body but instead it was: %v", rawFeed.body)
	}
	if rawFeed.etag.Status != data.Null {
		t.Errorf("Expected no ETag to be null but instead it was: %v", rawFeed.etag)
	}
}
Ejemplo n.º 9
0
import (
	"fmt"
	"os"
	"os/exec"
	"path/filepath"
	"runtime"
	"strings"
	"sync"
	"time"

	"github.com/codegangsta/cli"
	"github.com/inconshreveable/axiom"
	log "gopkg.in/inconshreveable/log15.v2"
)

var Log = log.Root()

const usage = `build Go installations with native stdlib packages

DESCRIPTION:
   Cross compiled Go binaries are not suitable for production applications
   because code in the standard library relies on Cgo for DNS resolution
   with the native resolver, access to system certificate roots, and parts of os/user.

   gonative is a simple tool which creates a build of Go that can cross compile
   to all platforms while still using the Cgo-enabled versions of the stdlib
   packages. It does this by downloading the binary distributions for each
   platform and copying their libraries into the proper places. It sets
   the correct access time so they don't get rebuilt. It also copies
   some auto-generated runtime files into the build as well. gonative does
   not modify any Go that you have installed and builds Go again in a separate
Ejemplo n.º 10
0
// I'm not really sure why this bit is required (and doesn't overwrite what's in main)... I may need to build my own logging library so I can grasp all the particulars
func init() {
	log15.Root().SetHandler(log15.LvlFilterHandler(log15.LvlError, log15.StdoutHandler))
	log = log15.New("function", log15.Lazy{Fn: loghelper.Log15LazyFunctionName})
}