當前位置: 首頁>>代碼示例>>Golang>>正文


Golang logrus.New函數代碼示例

本文整理匯總了Golang中github.com/Sirupsen/logrus.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Test_changefeed

func Test_changefeed(t *testing.T) {
	s := storage.NewMemStorage()

	tests := []changefeedTest{
		{
			name: "Empty Store",
			args: changefeedArgs{
				logger:    logrus.New(),
				store:     s,
				imageName: "",
				changeID:  "0",
				pageSize:  notary.DefaultPageSize,
			},
			want:    []byte("{\"count\":0,\"records\":null}"),
			wantErr: false,
		},
		{
			name: "Bad ChangeID",
			args: changefeedArgs{
				logger:    logrus.New(),
				store:     s,
				imageName: "",
				changeID:  "not_a_number",
				pageSize:  notary.DefaultPageSize,
			},
			want:    nil,
			wantErr: true,
		},
	}
	runChangefeedTests(t, tests)

}
開發者ID:jfrazelle,項目名稱:notary,代碼行數:32,代碼來源:changefeed_test.go

示例2: TestClient

func TestClient(t *testing.T) {
	assert.Panics(t, func() {
		NewAPIMock(true, logrus.New(), "panic!")
	}, "It must panic if wrong type")

	api := NewAPIMock(true, logrus.New(), "json")
	assert.IsType(t, api, new(APIMock), "It must instance an APIMock struct")
	assert.Equal(t, api.CORSEnabled, true, "Cors must be TRUE")
	assert.Equal(t, api.Log, logrus.New(), "Logger must be set correctly")
	assert.Equal(t, api.Type, "json", "Type must be 'json'")
}
開發者ID:fernandezvara,項目名稱:apimock,代碼行數:11,代碼來源:apimock_test.go

示例3: NewOptionsFromConfig

// NewOptionsFromConfig extracts bits from a config to make an agent options object
func NewOptionsFromConfig(cfg *config.Config) *Options {
	log := logrus.New()
	opts := &Options{
		Env: cfg.Env,
		Log: logrus.New(),
	}

	if cfg.LogFormat == "json" {
		log.Formatter = &logrus.JSONFormatter{}
	}

	opts.Log = Logger(log)
	return opts
}
開發者ID:hamfist,項目名稱:go-newrelic,代碼行數:15,代碼來源:options.go

示例4: TestRecoverMiddleware

func TestRecoverMiddleware(t *testing.T) {
	req := &protocol.Request{
		Method: "foobar",
		Params: protocol.Params{},
		Header: header.Header{},
	}
	rw := &dummy.ResponseWriter{
		HeaderValues: header.Header{},
	}

	buff := bytes.NewBufferString("")
	logger := log.New()
	logger.Out = buff

	handler := Chain(panicHandler, NewRecover(logger, true, 8*1024))

	handler.Handle(rw, req)

	loglines := buff.String()

	expectedLog := regexp.MustCompile(`error="Booom"`)
	if expectedLog.FindString(loglines) != "" {
		t.Errorf("didn't find expected log line in %s", loglines)
	}
}
開發者ID:mamachanko,項目名稱:go-nano,代碼行數:25,代碼來源:recover_test.go

示例5: main

func main() {
	log := logrus.New()
	cli.VersionPrinter = func(c *cli.Context) {
		fmt.Printf("%s v=%s d=%s\n", c.App.Name, c.App.Version, GeneratedString)
	}

	app := cli.NewApp()
	app.Name = "artifacts-service"
	app.Version = VersionString
	app.Commands = []cli.Command{
		{
			Name:      "serve",
			ShortName: "s",
			Usage:     "run the HTTP thing",
			Action: func(_ *cli.Context) {
				server.Main(log)
			},
		},
		{
			Name:      "migrate",
			ShortName: "m",
			Usage:     "run database migrations",
			Action: func(_ *cli.Context) {
				server.MigratorMain(log)
			},
		},
	}

	app.Run(os.Args)
}
開發者ID:hamfist,項目名稱:artifacts-service,代碼行數:30,代碼來源:artifacts_service.go

示例6: main

func main() {
	r := gin.New()

	// Add a ginrus middleware, which:
	//   - Logs all requests, like a combined access and error log.
	//   - Logs to stdout.
	//   - RFC3339 with UTC time format.
	r.Use(ginrus.Ginrus(logrus.StandardLogger(), time.RFC3339, true))

	// Add similar middleware, but:
	//   - Only logs requests with errors, like an error log.
	//   - Logs to stderr instead of stdout.
	//   - Local time zone instead of UTC.
	logger := logrus.New()
	logger.Level = logrus.ErrorLevel
	logger.Out = os.Stderr
	r.Use(ginrus.Ginrus(logger, time.RFC3339, false))

	// Example ping request.
	r.GET("/ping", func(c *gin.Context) {
		c.String(200, "pong "+fmt.Sprint(time.Now().Unix()))
	})

	// Listen and Server in 0.0.0.0:8080
	r.Run(":8080")
}
開發者ID:doubledutch,項目名稱:dd-vote,代碼行數:26,代碼來源:example.go

示例7: main

func main() {
	log := logrus.New()
	hook, err := logrus_influxdb.NewInfluxDB(nil)
	if err == nil {
		log.Hooks.Add(hook)
	}
}
開發者ID:Abramovic,項目名稱:logrus_influxdb,代碼行數:7,代碼來源:main.go

示例8: Instance

func Instance() *log.Logger {
	if logger == nil {
		logger = log.New()
	}

	return logger
}
開發者ID:ch3lo,項目名稱:crane,代碼行數:7,代碼來源:logger.go

示例9: Fire

func (h *TeeHook) Fire(entry *logrus.Entry) error {
	logger := logrus.New()
	logger.Out = h.W
	switch entry.Level {
	case logrus.PanicLevel:
		logger.WithFields(entry.Data).Panic(entry.Message)
		break
	case logrus.FatalLevel:
		logger.WithFields(entry.Data).Fatal(entry.Message)
		break
	case logrus.ErrorLevel:
		logger.WithFields(entry.Data).Error(entry.Message)
		break
	case logrus.WarnLevel:
		logger.WithFields(entry.Data).Warnf(entry.Message)
		break
	case logrus.InfoLevel:
		logger.WithFields(entry.Data).Info(entry.Message)
		break
	case logrus.DebugLevel:
		logger.WithFields(entry.Data).Info(entry.Message)
		break
	}
	return nil
}
開發者ID:layer-x,項目名稱:layerx-commons,代碼行數:25,代碼來源:hooks.go

示例10: Run

func (svc *service) Run() (string, error) {
	logger := logrus.New()
	err := setupSyslog(logger)
	if err != nil {
		return "Could not create syslog", err
	}

	// load configuration file
	config, err := config.LoadFromFile(svc.args["<config-file>"].(string))
	if err != nil {
		logger.WithError(err).Error("Failed to open configuration file")
		return "Failed to open configuration file", err
	}

	w, err := worker.New(config, logger)
	if err != nil {
		logger.WithError(err).Error("Could not create worker")
		return "Could not create worker", err
	}

	sigTerm := make(chan os.Signal, 1)
	signal.Notify(sigTerm, os.Interrupt, os.Kill, syscall.SIGTERM)
	go func() {
		<-sigTerm
		w.Stop()
	}()
	w.Start()
	return "Worker successfully started", nil
}
開發者ID:taskcluster,項目名稱:taskcluster-worker,代碼行數:29,代碼來源:service.go

示例11: main

func main() {
	log := logrus.New()
	log.Formatter = new(logrus.JSONFormatter)

	for {
		log.WithFields(logrus.Fields{
			"animal": "walrus",
			"size":   "10",
		}).Print("A group of walrus emerges from the ocean")

		log.WithFields(logrus.Fields{
			"omg":    true,
			"number": 122,
		}).Warn("The group's number increased tremendously!")

		log.WithFields(logrus.Fields{
			"animal": "walrus",
			"size":   "10",
		}).Print("A giant walrus appears!")

		log.WithFields(logrus.Fields{
			"animal": "walrus",
			"size":   "9",
		}).Print("Tremendously sized cow enters the ocean.")

		log.WithFields(logrus.Fields{
			"omg":    true,
			"number": 100,
		}).Fatal("The ice breaks!")
	}
}
開發者ID:shaunstanislaus,項目名稱:logrus,代碼行數:31,代碼來源:text.go

示例12: New

func New(concurrentRequests int, hosts []string, startUrls []string) *Crawler {
	c := &Crawler{
		ConcurrentRequests: concurrentRequests,
		AllowCrawlPatterns: make([]*regexp.Regexp, 0),

		Logger: logrus.New(),

		Client: &http.Client{},

		itemQueue:   make([]*CrawlItem, 0),
		crawledUrls: make(map[string]bool),
		pendingUrls: make(map[string]bool),

		resultChannel: make(chan *CrawlItem),
	}

	for _, host := range hosts {
		re := regexp.MustCompile("https?\\://" + host + "*")
		c.AllowCrawlPatterns = append(c.AllowCrawlPatterns, re)
	}

	for _, url := range startUrls {
		c.itemQueue = append(c.itemQueue, &CrawlItem{
			Url: url,
		})
	}

	return c
}
開發者ID:app-kit,項目名稱:go-appkit,代碼行數:29,代碼來源:crawler.go

示例13: main

func main() {
	var log = logrus.New()
	app := cli.NewApp()
	app.Name = "Geopardy"
	app.Usage = "Import and query Jeopardy questions"
	app.Action = func(c *cli.Context) {
		log.Out = os.Stderr
		log.WithFields(logrus.Fields{
			"args": c.Args(),
		}).Info("Called with args")
	}

	app.Commands = []cli.Command{
		{
			Name:  "import",
			Usage: "Import Jeopardy questions from the web to the database",
			Action: func(c *cli.Context) {
				err := imp.RunImport(c.Args())
				if err != nil {
					log.Error(err)
				}
			},
		},
	}

	app.Run(os.Args)
}
開發者ID:russmatney,項目名稱:go-jeopardy,代碼行數:27,代碼來源:main.go

示例14: newRedisNotify

func newRedisNotify(accountID string) (*logrus.Logger, error) {
	rNotify := serverConfig.GetRedisNotifyByID(accountID)

	// Dial redis.
	rPool, err := dialRedis(rNotify)
	if err != nil {
		return nil, err
	}

	rrConn := redisConn{
		Pool:   rPool,
		params: rNotify,
	}

	redisLog := logrus.New()

	redisLog.Out = ioutil.Discard

	// Set default JSON formatter.
	redisLog.Formatter = new(logrus.JSONFormatter)

	redisLog.Hooks.Add(rrConn)

	// Success, redis enabled.
	return redisLog, nil
}
開發者ID:hackintoshrao,項目名稱:minio,代碼行數:26,代碼來源:notify-redis.go

示例15: NewLogger

// NewLogger returns a log configured with the input parameters.
func NewLogger(level, writer string, maxSize, maxAge, maxBackups int) *logrus.Entry {
	base := logrus.New()

	switch writer {
	case "stdout":
		base.Out = os.Stdout
	case "stderr":
		base.Out = os.Stderr
	case "":
		base.Out = ioutil.Discard
	default:
		base.Out = &lumberjack.Logger{
			Filename:   writer,
			MaxSize:    maxSize,
			MaxAge:     maxAge,
			MaxBackups: maxBackups,
		}
	}

	logrusLevel, err := logrus.ParseLevel(level)
	// if provided level is not supported, default to Info level
	if err != nil {
		base.Error(err)
		logrusLevel = logrus.InfoLevel
	}
	base.Level = logrusLevel

	log := logrus.NewEntry(base)
	return log
}
開發者ID:clawio,項目名稱:clawiod,代碼行數:31,代碼來源:helpers.go


注:本文中的github.com/Sirupsen/logrus.New函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。