当前位置: 首页>>代码示例>>Golang>>正文


Golang log.Init函数代码示例

本文整理汇总了Golang中github.com/ardanlabs/kit/log.Init函数的典型用法代码示例。如果您正苦于以下问题:Golang Init函数的具体用法?Golang Init怎么用?Golang Init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Init函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestLogLevelDEV

// TestLogLevelDEV tests the basic functioning of the logger in DEV mode.
func TestLogLevelDEV(t *testing.T) {
	t.Log("Given the need to log DEV and USER messages.")
	{
		t.Log("\tWhen we set the logging level to DEV.")
		{
			log.Init(&logdest, func() int { return log.DEV })
			resetLog()
			defer displayLog()

			dt := time.Now().Format("2006/01/02 15:04:05")

			log1 := fmt.Sprintf("%s log_test.go:81: DEV : context : FuncName : Message 1 no format\n", dt)
			log2 := fmt.Sprintf("%s log_test.go:82: USER : context : FuncName : Message 2 with format: A, B\n", dt)
			log3 := fmt.Sprintf("%s log_test.go:83: ERROR : context : FuncName : An error : Message 3 with format: C, D\n", dt)

			log.Dev("context", "FuncName", "Message 1 no format")
			log.User("context", "FuncName", "Message 2 with format: %s, %s", "A", "B")
			log.Error("context", "FuncName", errors.New("An error"), "Message 3 with format: %s, %s", "C", "D")

			if logdest.String() == log1+log2+log3 {
				t.Logf("\t\t%v : Should log the expected trace line.", succeed)
			} else {
				t.Log("***>", logdest.String())
				t.Log("***>", log1+log2+log3)
				t.Errorf("\t\t%v : Should log the expected trace line.", failed)
			}
		}
	}
}
开发者ID:coralproject,项目名称:sponge,代码行数:30,代码来源:log_test.go

示例2: init

func init() {

	// This is being added to showcase configuration.
	os.Setenv("KIT_LOGGING_LEVEL", "1")
	os.Setenv("KIT_MIN_ROUTINES", "1")
	os.Setenv("KIT_MAX_ROUTINES", "10")

	// Init the configuration system.
	if err := cfg.Init(cfg.EnvProvider{Namespace: configKey}); err != nil {
		fmt.Println("Error initalizing configuration system", err)
		os.Exit(1)
	}

	// Init the log system.
	logLevel := func() int {
		ll, err := cfg.Int(cfgLoggingLevel)
		if err != nil {
			return log.USER
		}
		return ll
	}
	log.Init(os.Stderr, logLevel)

	// Log all the configuration options
	log.User("startup", "init", "\n\nConfig Settings: %s\n%s\n", configKey, cfg.Log())
}
开发者ID:DmitryZinchenko,项目名称:kit,代码行数:26,代码来源:main.go

示例3: setup

func setup() {

	// Save original enviroment variables
	oStrategy = os.Getenv("STRATEGY_CONF")
	oPillarURL = os.Getenv("PILLAR_URL")
	oPollingInterval = os.Getenv("POLLING_INTERVAL")

	logLevel := func() int {
		ll, err := cfg.Int("LOGGING_LEVEL")
		if err != nil {
			return log.DEV
		}
		return ll
	}

	log.Init(os.Stderr, logLevel)

	// MOCK STRATEGY CONF
	strategyConf := "../../tests/strategy_test.json"
	e := os.Setenv("STRATEGY_CONF", strategyConf) // IS NOT REALLY SETTING UP THE VARIABLE environment FOR THE WHOLE PROGRAM :(
	if e != nil {
		fmt.Println("It could not setup the mock strategy conf variable")
	}

}
开发者ID:coralproject,项目名称:sponge,代码行数:25,代码来源:sponge_test.go

示例4: main

func main() {

	// Initialize the configuration
	if err := cfg.Init(cfg.EnvProvider{Namespace: "SPONGE"}); err != nil {
		sponge.Println("Unable to initialize configuration")
		os.Exit(1)
	}

	// Initialize the logging
	logLevel := func() int {
		ll, err := cfg.Int(cfgLoggingLevel)
		if err != nil {
			return log.NONE
		}
		return ll
	}

	log.Init(os.Stderr, logLevel, log.Ldefault)
	sponge.Println("Using log level", logLevel())

	// Add the item commands to the CLI tool.
	sponge.AddCommand(
		cmditem.GetCommands(),
		cmdpattern.GetCommands(),
	)

	// Execute the command.
	sponge.Execute()
}
开发者ID:coralproject,项目名称:xenia,代码行数:29,代码来源:main.go

示例5: Init

// Init is called to initialize the application.
func Init(configKey string) {

	// Init the configuration system.
	if err := cfg.Init(cfg.EnvProvider{Namespace: configKey}); err != nil {
		fmt.Println("Error initalizing configuration system", err)
		os.Exit(1)
	}

	// Init the log system.
	logLevel := func() int {
		ll, err := cfg.Int(cfgLoggingLevel)
		if err != nil {
			return log.USER
		}
		return ll
	}
	log.Init(os.Stderr, logLevel)

	// Log all the configuration options
	log.User("startup", "Init", "\n\nConfig Settings: %s\n%s\n", configKey, cfg.Log())

	// Load user defined custom headers. HEADERS should be key:value,key:value
	if hs, err := cfg.String("HEADERS"); err == nil {
		hdrs := strings.Split(hs, ",")
		for _, hdr := range hdrs {
			if kv := strings.Split(hdr, ":"); len(kv) == 2 {
				log.User("startup", "Init", "User Headers : %s:%s", kv[0], kv[1])
				app.userHeaders[kv[0]] = kv[1]
			}
		}
	}
}
开发者ID:decebal,项目名称:kit,代码行数:33,代码来源:app.go

示例6: setup

func setup() {

	// Save original enviroment variables
	oStrategy = os.Getenv("STRATEGY_CONF")
	oPillarURL = os.Getenv("PILLAR_URL")

	// Initialize log
	logLevel := func() int {
		ll, err := cfg.Int("LOGGING_LEVEL")
		if err != nil {
			return log.DEV
		}
		return ll
	}

	log.Init(os.Stderr, logLevel)

	// Mock strategy configuration
	strategyConf := "../../tests/strategy_test.json"
	//strategyConf := "../../tests/strategy_with_actions_test.json"
	e := os.Setenv("STRATEGY_CONF", strategyConf) // IS NOT REALLY SETTING UP THE VARIABLE environment FOR THE WHOLE PROGRAM :(
	if e != nil {
		fmt.Println("It could not setup the mock strategy conf variable")
	}

	u := uuidimported.New()

	// Initialize fiddler
	Init(u)
}
开发者ID:coralproject,项目名称:sponge,代码行数:30,代码来源:fiddler_test.go

示例7: main

func main() {

	// Initialize logging
	logLevel := func() int {
		ll, err := cfg.Int(cfgLoggingLevel)
		if err != nil {
			return log.USER
		}
		return ll
	}
	log.Init(os.Stderr, logLevel)

	// Generate UUID to use with the logs
	uid := uuid.New()

	if err := sponge.Init(uid); err != nil {
		log.Error(uid, "main", err, "Unable to initialize configuration.")
		os.Exit(-1)
	}

	if err := cmd.RootCmd.Execute(); err != nil {
		log.Error(uid, "main", err, "Unable to execute the command.")
		os.Exit(-1)
	}
}
开发者ID:coralproject,项目名称:sponge,代码行数:25,代码来源:main.go

示例8: main

func main() {
	if err := cfg.Init(cfg.EnvProvider{Namespace: cfgNamespace}); err != nil {
		kit.Println("Unable to initialize configuration")
		os.Exit(1)
	}

	logLevel := func() int {
		ll, err := cfg.Int(cfgLoggingLevel)
		if err != nil {
			return log.NONE
		}
		return ll
	}
	log.Init(os.Stderr, logLevel)

	cfg := mongo.Config{
		Host:     cfg.MustString(cfgMongoHost),
		AuthDB:   cfg.MustString(cfgMongoAuthDB),
		DB:       cfg.MustString(cfgMongoDB),
		User:     cfg.MustString(cfgMongoUser),
		Password: cfg.MustString(cfgMongoPassword),
	}

	if err := db.RegMasterSession("startup", cfg.DB, cfg); err != nil {
		kit.Println("Unable to initialize MongoDB")
		os.Exit(1)
	}

	kit.AddCommand(
		cmdauth.GetCommands(cfg.DB),
		cmddb.GetCommands(cfg.DB),
	)
	kit.Execute()
}
开发者ID:decebal,项目名称:kit,代码行数:34,代码来源:main.go

示例9: init

func init() {
	logLevel := func() int {
		ll, err := cfg.Int("LOGGING_LEVEL")
		if err != nil {
			return log.DEV
		}
		return ll
	}

	log.Init(os.Stderr, logLevel)
}
开发者ID:coralproject,项目名称:sponge,代码行数:11,代码来源:source_test.go

示例10: Init

// Init initializes the log package.
func Init(cfgKey string) {
	cfg.Init(cfg.EnvProvider{Namespace: cfgKey})

	logLevel := func() int {
		ll, err := cfg.Int("LOGGING_LEVEL")
		if err != nil {
			return log.USER
		}
		return ll
	}
	log.Init(&logdash, logLevel)
}
开发者ID:DmitryZinchenko,项目名称:kit,代码行数:13,代码来源:tests.go

示例11: Init

// Init is called to initialize the application.
func Init(configKey string) {

	// Init the configuration system.
	if err := cfg.Init(cfg.EnvProvider{Namespace: configKey}); err != nil {
		fmt.Println("Error initalizing configuration system", err)
		os.Exit(1)
	}

	// Init the log system.
	logLevel := func() int {
		ll, err := cfg.Int(cfgLoggingLevel)
		if err != nil {
			return log.USER
		}
		return ll
	}
	log.Init(os.Stderr, logLevel)

	// Log all the configuration options
	log.User("startup", "Init", "\n\nConfig Settings: %s\n%s\n", configKey, cfg.Log())

	// Init MongoDB if configured.
	if _, err := cfg.String(cfgMongoHost); err == nil {
		app.useMongo = true

		cfg := mongo.Config{
			Host:     cfg.MustString(cfgMongoHost),
			AuthDB:   cfg.MustString(cfgMongoAuthDB),
			DB:       cfg.MustString(cfgMongoDB),
			User:     cfg.MustString(cfgMongoUser),
			Password: cfg.MustString(cfgMongoPassword),
		}

		if err := mongo.Init(cfg); err != nil {
			log.Error("startup", "Init", err, "Initializing MongoDB")
			os.Exit(1)
		}
	}

	// Load user defined custom headers. HEADERS should be key:value,key:value
	if hs, err := cfg.String("HEADERS"); err == nil {
		hdrs := strings.Split(hs, ",")
		for _, hdr := range hdrs {
			if kv := strings.Split(hdr, ":"); len(kv) == 2 {
				log.User("startup", "Init", "User Headers : %s:%s", kv[0], kv[1])
				app.userHeaders[kv[0]] = kv[1]
			}
		}
	}
}
开发者ID:ramakrishna580,项目名称:kit,代码行数:51,代码来源:app.go

示例12: Init

// Init sets up the configuration and logging systems.
func Init(p cfg.Provider) {
	if err := cfg.Init(p); err != nil {
		fmt.Println("Error initalizing configuration system", err)
		os.Exit(1)
	}

	// Init the log system.
	logLevel := func() int {
		ll, err := cfg.Int(cfgLoggingLevel)
		if err != nil {
			return log.USER
		}
		return ll
	}
	log.Init(os.Stderr, logLevel, log.Ldefault)
}
开发者ID:coralproject,项目名称:xenia,代码行数:17,代码来源:app.go

示例13: ExampleDev

// ExampleDev shows how to use the log package.
func ExampleDev(t *testing.T) {
	// Init the log package for stdout. Hardcode the logging level
	// function to use USER level logging.
	log.Init(os.Stdout, func() int { return log.USER })

	// Write a simple log line with no formatting.
	log.User("context", "ExampleDev", "This is a simple line with no formatting")

	// Write a simple log line with formatting.
	log.User("context", "ExampleDev", "This is a simple line with no formatting %d", 10)

	// Write a message error for the user.
	log.Error("context", "ExampleDev", errors.New("A user error"), "testing error")

	// Write a message error for the user with formatting.
	log.Error("context", "ExampleDev", errors.New("A user error"), "testing error %s", "value")

	// Write a message error for the developer only.
	log.Dev("context", "ExampleDev", "Formatting %v", 42)
}
开发者ID:coralproject,项目名称:sponge,代码行数:21,代码来源:log_examples_test.go

示例14: setupMongo

func setupMongo() {

	// Initialize logging
	logLevel := func() int {
		ll, err := cfg.Int(cfgLoggingLevel)
		if err != nil {
			return log.USER
		}
		return ll
	}
	log.Init(os.Stderr, logLevel)

	oStrategy = os.Getenv("STRATEGY_CONF")

	// MOCK STRATEGY CONF
	strategyConf := os.Getenv("GOPATH") + "/src/github.com/coralproject/sponge/tests/strategy_wapo_test.json"
	e := os.Setenv("STRATEGY_CONF", strategyConf)
	if e != nil {
		fmt.Println("It could not setup the mock strategy conf variable")
	}

	var ok bool

	u := uuidimported.New()
	s, e := Init(u)
	if e != nil {
		fmt.Printf("Error when initializing strategy, %v.\n", e)
	}

	m, e := New(s) // setting up new source
	if e != nil {
		fmt.Printf("Error when calling the function, %v.\n", e)
	}

	mdb, ok = m.(MongoDB)
	if !ok {
		fmt.Println("It should return a type MontoDB")
	}
}
开发者ID:coralproject,项目名称:sponge,代码行数:39,代码来源:source_test.go

示例15: setupPostgreSQL

func setupPostgreSQL() {

	// Initialize logging
	logLevel := func() int {
		ll, err := cfg.Int(cfgLoggingLevel)
		if err != nil {
			return log.USER
		}
		return ll
	}
	log.Init(os.Stderr, logLevel)

	oStrategy = os.Getenv("STRATEGY_CONF")

	// MOCK STRATEGY CONF
	strategyConf := os.Getenv("GOPATH") + "/src/github.com/coralproject/sponge/tests/strategy_discourse_test.json"
	e := os.Setenv("STRATEGY_CONF", strategyConf) // IS NOT REALLY SETTING UP THE VARIABLE environment FOR THE WHOLE PROGRAM :(
	if e != nil {
		fmt.Println("It could not setup the mock strategy conf variable")
	}

	var ok bool

	u := uuidimported.New()

	s, e := Init(u)
	if e != nil {
		fmt.Printf("Error when initializing strategy, %v.\n", e)
	}
	m, e := New(s) // setup new source
	if e != nil {
		fmt.Printf("Error when calling the function, %v.\n", e)
	}

	mp, ok = m.(PostgreSQL)
	if !ok {
		fmt.Println("It should return a type PostgreSQL")
	}
}
开发者ID:coralproject,项目名称:sponge,代码行数:39,代码来源:source_test.go


注:本文中的github.com/ardanlabs/kit/log.Init函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。