本文整理匯總了Golang中github.com/inconshreveable/log15.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
log = log15.New()
log.Info("starting server...")
envconfig.Process("", &settings)
schema, err := graphql.NewSchema(makeSchema())
if err != nil {
log.Info("error creating schema", "err", err)
return
}
h := handler.New(&handler.Config{
Schema: &schema,
Pretty: false,
})
mux := http.NewServeMux()
mux.Handle("/graphql", h)
mux.Handle("/", http.FileServer(http.Dir("dist")))
log.Info("Listening at " + settings.Port + "...")
graceful.Run(":"+settings.Port, 1*time.Second, mux)
log.Info("Exiting...")
}
示例2: StartWebServer
func StartWebServer() error {
conf, err := config.GetConfig()
if err != nil {
return err
}
var hystrixTimeout time.Duration
conf.Hystrix.Timeout = strings.TrimSpace(conf.Hystrix.Timeout)
if conf.Hystrix.Timeout != "" {
hystrixTimeout, err = time.ParseDuration(conf.Hystrix.Timeout)
if err != nil || hystrixTimeout < time.Millisecond {
hystrixTimeout = time.Second
log15.Error("Use default time", "module", "hystrix", "timeout", hystrixTimeout)
}
}
hystrix.ConfigureCommand("waitFor", hystrix.CommandConfig{
Timeout: int(int64(hystrixTimeout) / int64(time.Millisecond)), // converted into Millisecond.
MaxConcurrentRequests: conf.Hystrix.MaxConcurrentRequests,
ErrorPercentThreshold: conf.Hystrix.ErrorPercentThreshold,
RequestVolumeThreshold: conf.Hystrix.RequestVolumeThreshold,
SleepWindow: conf.Hystrix.SleepWindow,
})
e := echo.New()
e.Post("/api/v1/tweet", createTweetV1)
e.Get("/api/v1/tweets/:id", getAllTweetForV1)
e.Get("/api/v1/wait/:timeout", waitFor)
e.Get("/api/v1/wait_protected/:timeout", waitForProtected)
e.Static("/", "www/static/")
logsrv := log15.New("pid", os.Getpid(), "addr", conf.Web.Address)
return listenAndServer(logsrv, conf.Web.Address, handlers.LoggingHandler(os.Stdout, handlers.CompressHandler(e.Router())))
}
示例3: newLogger
func newLogger() log15.Logger {
l := log15.New()
h := log15.StreamHandler(os.Stdout, log15.LogfmtFormat())
//h = log15.CallerStackHandler("%+n", h)
l.SetHandler(log15.LazyHandler(h))
return l
}
示例4: Init
func (srv *T) Init() error {
err := os.MkdirAll(srv.Config.General.DataPath, os.ModeDir|0700)
if err != nil {
return err
}
database, err := db.NewDB(filepath.Join(srv.Config.General.DataPath, "db"))
if err != nil {
return err
}
srv.DB = database
srv.Log = log15.New()
srv.Router = pubsub.New(100)
return nil
}
示例5: ExampleHandler
func ExampleHandler() {
log := log15.New()
log.SetHandler(&slack15.Handler{
URL: "", // pass url here, or through $SLACK_WEBHOOK_URL
// You can skip this and stick with webhook defaults
Envelope: slack15.Envelope{
Username: "Mr. Bellamy",
IconEmoji: ":showman:",
},
})
log.Info("Whaam!", "who", "Roy Lichtenstein", "when", 1963)
// Output:
}
示例6: newLogger
func newLogger(c *Context) (log15.Logger, error) {
lvl := c.String(FlagLogLevel)
l := log15.New()
log.Println(fmt.Sprintf("Using log level %s", lvl))
v, err := log15.LvlFromString(lvl)
if err != nil {
return l, err
}
h := log15.LvlFilterHandler(v, log15.StreamHandler(os.Stdout, log15.LogfmtFormat()))
if lvl == "debug" {
h = log15.CallerFileHandler(h)
}
l.SetHandler(log15.LazyHandler(h))
return l, err
}
示例7: Init
func (i *Irrational) Init(license xchg.LicenseID) {
i.log.Info("Licensed", "license", license)
i.log = log15.New("license", license)
i.id = license
//i.tc = make(chan Tick)
i.cl = make(chan bool)
i.tq = lane.NewQueue()
i.lp = make(map[xchg.Symbol]float32)
i.ls = make(map[xchg.Symbol]uint64)
i.tra = make(map[xchg.AuctionID]xchg.TradeStatus)
i.trb = make(map[xchg.BidID]xchg.TradeStatus)
i.act = i.mkt.Bank().Open()
i.log.Info("Bank account opened", "token", i.act)
go i.Loop()
}
示例8: main
func main() {
flag.Parse()
args := flag.Args()
if len(args) != 2 || *validatorName == "" {
flag.Usage()
os.Exit(2)
}
log := log15.New()
expected, err := os.Open(args[0])
if err != nil {
log.Error("Unable to open expected file", "err", err)
os.Exit(1)
}
defer expected.Close()
contestant, err := os.Open(args[1])
if err != nil {
log.Error("Unable to open contestant file", "err", err)
os.Exit(1)
}
defer contestant.Close()
validator := &common.ValidatorSettings{
Name: *validatorName,
Tolerance: tolerance,
}
score, mismatch, err := runner.CalculateScore(
validator,
expected,
contestant,
)
if err != nil {
log.Error("Error validating", "err", err)
os.Exit(1)
}
if mismatch != nil {
log.Info(
"Token mismatch",
"expected", mismatch.Expected,
"got", mismatch.Contestant,
)
}
fmt.Printf("%.2f\n", score)
}
示例9: init
func init() {
Log = log.New()
var handler log.Handler
env := config.Viper.GetString("env")
lvl, err := log.LvlFromString(config.Viper.GetString("LogLevel"))
if err != nil {
panic("Could not read configuration for LogLevel, check the 'config-" + env +
".json' file: " + err.Error())
}
if env == "dev" || env == "qa" {
handler = logext.FatalHandler(log.LvlFilterHandler(lvl, log.CallerFileHandler(log.StdoutHandler)))
} else {
handler = logext.FatalHandler(log.LvlFilterHandler(lvl, log.CallerFileHandler(log.StreamHandler(os.Stdout, log.JsonFormat()))))
}
Log.SetHandler(handler)
}
示例10: TestSpeculativeHandler
func TestSpeculativeHandler(t *testing.T) {
t.Parallel()
// test with an even multiple of the buffer size, less than full buffer size
// and not a multiple of the buffer size
for _, count := range []int{10000, 50, 432} {
recs := make(chan *log.Record)
done := make(chan int)
spec := SpeculativeHandler(100, log.ChannelHandler(recs))
go func() {
defer close(done)
expectedCount := int(math.Min(float64(count), float64(100)))
expectedIdx := count - expectedCount
for r := range recs {
if r.Ctx[1] != expectedIdx {
t.Errorf("Bad ctx 'i', got %d expected %d", r.Ctx[1], expectedIdx)
return
}
expectedIdx++
expectedCount--
if expectedCount == 0 {
// got everything we expected
break
}
}
select {
case <-recs:
t.Errorf("got an extra record we shouldn't have!")
default:
}
}()
lg := log.New()
lg.SetHandler(spec)
for i := 0; i < count; i++ {
lg.Debug("test speculative", "i", i)
}
go spec.Flush()
// wait for the go routine to finish
<-done
}
}
示例11: InitConfig
// inital PoolConfig of pgx
func (pgdb *PostgresDB) InitConfig(dbhost, dbuser, dbpassword, dbname string) error {
pgdb.poolConfig = pgx.ConnPoolConfig{
ConnConfig: pgx.ConnConfig{
Host: dbhost,
User: dbuser,
Password: dbpassword,
Database: dbname,
Logger: log.New("module", "pgx"),
},
MaxConnections: 5,
AfterConnect: pgdb.afterConnect,
}
// = connPoolConfig
return nil
}
示例12: RunFormula
func RunFormula(s scheduler.Scheduler, e executor.Executor, formula def.Formula, journal io.Writer) def.JobResult {
jobLoggerFactory := func(_ def.JobID) io.Writer {
// All job progress reporting, still copy to our shared journal stream.
// This func might now be outdated; but we haven't decided what any of this
// should look like if take a lurch toward supporting cluster farming.
// (It might make sense to have a structural comms layer? Or, maybe plain
// byte streams are best for sanity conservation. Either way: not today.)
return journal
}
s.Configure(e, 1, jobLoggerFactory) // queue concept a bit misplaced here
s.Start()
// Set up a logger.
log := log15.New()
log.SetHandler(log15.StreamHandler(journal, log15.TerminalFormat()))
id, jobChan := s.Schedule(formula)
log = log.New(log15.Ctx{"JobID": id})
log.Info("Job queued")
job := <-jobChan
// TODO need better lifecycle events here. "starting" here means we might still be in provisioning stage.
log.Info("Job starting")
// Stream job output to terminal in real time
_, err := io.Copy(journal, job.OutputReader())
if err != nil {
log.Error("Error reading job stream", "error", err)
panic(err)
}
result := job.Wait()
if result.Error != nil {
log.Error("Job execution errored", "error", result.Error.Message())
} else {
log.Info("Job finished", log15.Ctx{
"exit": result.ExitCode,
"outputs": result.Outputs,
})
}
return result
}
示例13: Start
func (e *Executor) Start(f def.Formula, id def.JobID, stdin io.Reader, journal io.Writer) def.Job {
// Prepare the forumla for execution on this host
def.ValidateAll(&f)
job := basicjob.New(id)
jobReady := make(chan struct{})
go func() {
// Run the formula in a temporary directory
flak.WithDir(func(dir string) {
// spool our output to a muxed stream
var strm streamer.Mux
strm = streamer.CborFileMux(filepath.Join(dir, "log"))
outS := strm.Appender(1)
errS := strm.Appender(2)
job.Streams = strm
defer func() {
// Regardless of how the job ends (or even if it fails the remaining setup), output streams must be terminated.
outS.Close()
errS.Close()
}()
// Job is ready to stream process output
close(jobReady)
// Set up a logger. Tag all messages with this jobid.
logger := log15.New(log15.Ctx{"JobID": id})
logger.SetHandler(log15.StreamHandler(journal, log15.TerminalFormat()))
job.Result = e.Run(f, job, dir, stdin, outS, errS, logger)
}, e.workspacePath, "job", string(job.Id()))
// Directory is clean; job complete
close(job.WaitChan)
}()
<-jobReady
return job
}
示例14: TestHotSwapHandler
func TestHotSwapHandler(t *testing.T) {
t.Parallel()
h1, r1 := testHandler()
l := log.New()
h := HotSwapHandler(h1)
l.SetHandler(h)
l.Info("to h1")
if r1.Msg != "to h1" {
t.Fatalf("didn't get expected message to h1")
}
h2, r2 := testHandler()
h.Swap(h2)
l.Info("to h2")
if r2.Msg != "to h2" {
t.Fatalf("didn't get expected message to h2")
}
}
示例15: TestErrorHandler
func TestErrorHandler(t *testing.T) {
t.Parallel()
h, r := testHandler()
lg := log.New()
lg.SetHandler(EscalateErrHandler(
log.LvlFilterHandler(log.LvlError, h)))
lg.Debug("some function result", "err", nil)
if r.Msg != "" {
t.Fatalf("Expected debug level message to be filtered")
}
lg.Debug("some function result", "err", errors.New("failed operation"))
if r.Msg != "some function result" {
t.Fatalf("Expected debug level message to be escalated and pass lvlfilter")
}
if r.Lvl != log.LvlError {
t.Fatalf("Expected debug level message to be escalated to LvlError")
}
}