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


Golang seelog.ReplaceLogger函数代码示例

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


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

示例1: InitLog

// path can be ""
func InitLog(path string, debug bool) {

	config := `
<seelog type="sync" minlevel="${minlevel}">
    <outputs formatid="main">
        <console/>
        <!-- ${extra} -->
    </outputs>
    <formats>
        <format id="main" format="[EQ-%LEV] %Date(15:04:05.00): %Msg (at %File:%Line) %n"/>
    </formats>
</seelog>`

	if path != "" {
		extra := fmt.Sprintf("<file path=\"%s\"/>", path)
		config = strings.Replace(config, "<!-- ${extra} -->",
			extra, -1)
	}

	Debug = debug
	if debug {
		config = strings.Replace(config, "${minlevel}", "debug", -1)
	} else {
		config = strings.Replace(config, "${minlevel}", "info", -1)
	}

	logger, err := seelog.LoggerFromConfigAsBytes([]byte(config))
	if err != nil {
		panic(err)
	}
	seelog.ReplaceLogger(logger)
	if path != "" {
		seelog.Debugf("Initialized the logger for %s", path)
	}
}
开发者ID:terminiter,项目名称:earthquake,代码行数:36,代码来源:log.go

示例2: setInitLogging

func setInitLogging(logLevel string) {

	logLevel = strings.ToLower(logLevel)

	testConfig := `
	<seelog  type="sync" minlevel="`
	testConfig = testConfig + logLevel
	testConfig = testConfig + `">
		<outputs formatid="main">
			<filter levels="error">
				<file path="./log/gopa.log"/>
			</filter>
			<console formatid="main" />
		</outputs>
		<formats>
			<format id="main" format="[%Date(01-02) %Time] [%LEV] [%File:%Line,%FuncShort] %Msg%n"/>
		</formats>
	</seelog>`

	logger, err := log.LoggerFromConfigAsString(testConfig)
	if err != nil {
		log.Error("init config error,", err)
	}
	err = log.ReplaceLogger(logger)
	if err != nil {
		log.Error("init config error,", err)
	}
}
开发者ID:medcl,项目名称:elasticsearch-migration,代码行数:28,代码来源:log.go

示例3: SetupTestLogging

func SetupTestLogging() {
	var appConfig = `
  <seelog type="sync" minlevel='%s'>
  <outputs formatid="scanner">
    <filter levels="critical,error,warn,info">
      <console formatid="scanner" />
    </filter>
    <filter levels="debug,trace">
      <console formatid="debug" />
    </filter>
  </outputs>
  <formats>
  <format id="scanner" format="test: [%%LEV] %%Msg%%n" />
  <format id="debug" format="test: [%%LEV] %%Func :: %%Msg%%n" />
  </formats>
  </seelog>
`

	var config string
	if testing.Verbose() {
		config = fmt.Sprintf(appConfig, "trace")
	} else {
		config = fmt.Sprintf(appConfig, "info")
	}

	logger, err := log.LoggerFromConfigAsBytes([]byte(config))

	if err != nil {
		fmt.Println(err)
		return
	}

	log.ReplaceLogger(logger)
}
开发者ID:Georgetown-IR-Lab,项目名称:ocr-correction,代码行数:34,代码来源:logging.go

示例4: initLogger

func initLogger() {
	var err error

	// 初始化raven
	if cfg.Sentry != "" {
		Raven, err = raven.NewClient(cfg.Sentry, nil)
		if err != nil {
			log.Error("Init Sentry Error:", err)
		}
	}

	// 初始化logger
	if cfg.Logger != "" {
		// 自定义一个seelog raven receiver
		receiver := &RavenReciver{Client: Raven}
		parseParams := &log.CfgParseParams{
			CustomReceiverProducers: map[string]log.CustomReceiverProducer{
				"sentry": func(log.CustomReceiverInitArgs) (log.CustomReceiver, error) {
					return receiver, nil
				},
			},
		}
		if logger, err := log.LoggerFromParamConfigAsFile(cfg.Logger, parseParams); err == nil {
			log.ReplaceLogger(logger)
		} else {
			log.Error("Parse Logger Error: ", err)
		}

	}

}
开发者ID:jiehua233,项目名称:ginserver,代码行数:31,代码来源:main.go

示例5: DisableLogs

func DisableLogs() {
	logger, err := log.LoggerFromConfigAsString(DEFAULT_DISABLE_LOGS_CONFIG)
	if err != nil {
		panic(err)
	}
	log.ReplaceLogger(logger)
}
开发者ID:netvl,项目名称:imaged,代码行数:7,代码来源:logging.go

示例6: testFuncException

func testFuncException() {
	fmt.Println("testFuncException")
	testConfig := `
<seelog type="sync" minlevel="info">
	<exceptions>
		<exception funcpattern="*main.test*Except*" minlevel="error"/>
	</exceptions>
	<outputs>
		<console/>
	</outputs>
</seelog>`

	logger, _ := log.LoggerFromConfigAsBytes([]byte(testConfig))
	log.ReplaceLogger(logger)

	log.Trace("NOT Printed")
	log.Debug("NOT Printed")
	log.Info("NOT Printed")
	log.Warn("NOT Printed")
	log.Error("Printed")
	log.Critical("Printed")

	log.Current.Trace("NOT Printed")
	log.Current.Debug("NOT Printed")
	log.Current.Info("NOT Printed")
	log.Current.Warn("NOT Printed")
	log.Current.Error("Printed")
	log.Current.Critical("Printed")
}
开发者ID:cihub,项目名称:seelog-examples,代码行数:29,代码来源:exceptions_main.go

示例7: NewLogs

func NewLogs() {
	logger, err := log.LoggerFromConfigAsBytes([]byte(default_template))
	if err != nil {
		log.Criticalf("log config err: %v", err)
	}
	log.ReplaceLogger(logger)
}
开发者ID:DavidZhangqin,项目名称:goweb,代码行数:7,代码来源:logger.go

示例8: main

func main() {
	defer log.Flush()
	flag.Parse()
	args := flag.Args()

	if len(args) == 0 {
		usage(actions(nil))
		os.Exit(1)
	}

	logger, err := log.LoggerFromConfigAsString(config.Logger())
	if err != nil {
		die(err)
	}
	log.ReplaceLogger(logger)

	init, err := engine.New()
	if err != nil {
		die(err)
	}
	log.Info(args[0])
	actions := actions(init)
	action, ok := actions[args[0]]
	if !ok {
		usage(actions)
		os.Exit(1)
	}
	err = action.function()
	if err != nil {
		die(err)
	}
}
开发者ID:ColBT,项目名称:amazon-ecs-init,代码行数:32,代码来源:ecs-init.go

示例9: main

func main() {
	//err := LoadConfig("/system/etc/conf.json")
	err := LoadConfig("./conf.json")
	if err != nil {
		fmt.Printf("LoadConfig failed: (%s)", err)
		os.Exit(1)
	}

	//logger, err := log.LoggerFromConfigAsFile("/system/etc/log.xml")
	logger, err := log.LoggerFromConfigAsFile("./log.xml")
	if err != nil {
		fmt.Printf("Load log config failed: (%s)\n", err)
		os.Exit(1)
	}
	log.ReplaceLogger(logger)

	//wg := &sync.WaitGroup{}
	agent := NewAgent()
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT)

	wg := sync.WaitGroup{}
	wg.Add(1)
	go func() {
		agent.Run()
		log.Infof("agent quited")
		wg.Done()
	}()
	sig := <-c
	log.Infof("Received signal '%v', exiting\n", sig)
	agent.Stop()
	wg.Wait()
}
开发者ID:chenyf,项目名称:gibbon,代码行数:33,代码来源:gibbonagent.go

示例10: Init

// ロガーの初期化処理を行う
//
// param ; dir       ログファイルの出力先ディレクトリ。
//
// param : name      ログファイルの種別(例:master、servant)。
//
// param : identifer ロック用ファイルに(付与する識別ID(例:servantはListePort)。
//
// param : level     出力ログレベル(trace,debug,info,warn,error,criticalのいずれかを指定)
//
// param : maxSizeKB ログファイルの最大サイズ。この値を超えるとログローテーションが発生する。
//
// param : maxRolls  ログファイルの最大世代数
//
// param : timeoutSec  ロックのタイムアウト秒
//
// return : エラー情報を返す。
func Init(dir string, name string, identifer string, level string, maxSizeKB int, maxRolls int, timeoutSec int) error {
	var lockErr error
	lockName := lockHeader + name
	if identifer != "" {
		lockName = lockName + "_" + identifer
	}
	lockName = lockName + ".lock"
	locker, lockErr = util.InitLock(lockName)
	if lockErr != nil {
		return lockErr
	}
	if timeoutSec > 0 {
		lockTimeout = timeoutSec * 1000
	}

	logfile := fmt.Sprintf("%s%c%s.log", dir, os.PathSeparator, name)
	if err := makeFileIfNotExist(logfile); err != nil {
		Term()
		return err
	}

	config := generateConfigString(logfile, level, maxSizeKB, maxRolls)
	logger, err := seelog.LoggerFromConfigAsString(config)
	if err != nil {
		Term()
		return err
	}

	seelog.ReplaceLogger(logger)
	valid = true

	return nil
}
开发者ID:unikk,项目名称:cuto,代码行数:50,代码来源:log.go

示例11: InitDefaultSyncLogConfig

func InitDefaultSyncLogConfig() {
	logger, err := log.LoggerFromConfigAsString(DEFAULT_SYNC_LOG_CONFIG)
	if err != nil {
		panic(err)
	}
	log.ReplaceLogger(logger)
}
开发者ID:netvl,项目名称:imaged,代码行数:7,代码来源:logging.go

示例12: dateTimeFormat

func dateTimeFormat() {
	fmt.Println("Date time format")

	testConfig := `
<seelog type="sync">
	<outputs formatid="main">
		<console/>
	</outputs>
	<formats>
		<format id="main" format="%Date/%Time [%LEV] %Msg%n"/>
	</formats>
</seelog>`

	logger, err := log.LoggerFromConfigAsBytes([]byte(testConfig))

	if err != nil {
		fmt.Println(err)
	}

	loggerErr := log.ReplaceLogger(logger)

	if loggerErr != nil {
		fmt.Println(loggerErr)
	}

	log.Trace("Test message!")
}
开发者ID:cihub,项目名称:seelog-examples,代码行数:27,代码来源:formats_main.go

示例13: configLogger

func configLogger() {
	config := `
<seelog type="sync">
	<outputs>
		<filter levels="trace">
			<console formatid="skipped"/>
		</filter>
		<filter levels="debug">
			<console formatid="unchanged"/>
		</filter>
		<filter levels="info">
			<console formatid="plain"/>
		</filter>
		<filter levels="warn,error,critical">
			<console formatid="error"/>
		</filter>
	</outputs>
	<formats>
		<format id="error" format="%EscM(31)%Msg%EscM(0)%n"/>
		<format id="plain" format="%Msg%n"/>
		<format id="unchanged" format="%EscM(32)%Msg%EscM(0)%n"/>
		<format id="skipped" format="%EscM(34)%Msg%EscM(0)%n"/>
	</formats>
</seelog>`

	logger, err := log.LoggerFromConfigAsBytes([]byte(config))
	if err != nil {
		panic(err)
	}
	log.ReplaceLogger(logger)
}
开发者ID:hnakamur,项目名称:commango,代码行数:31,代码来源:main.go

示例14: setup_logging

func setup_logging() {
	level := "info"
	if *g_debug == true {
		level = "debug"
	}
	config := fmt.Sprintf(`
<seelog type="sync" minlevel="%s">
	<outputs formatid="main">
		<console/>
	</outputs>
	<formats>
		<format id="main" format="%%Date %%Time [%%LEVEL] %%File|%%FuncShort|%%Line: %%Msg%%n"/>
	</formats>
</seelog>`, level)

	logger, err := log.LoggerFromConfigAsBytes([]byte(config))

	if err != nil {
		fmt.Println("Failed to config logging:", err)
		os.Exit(1)
	}

	log.ReplaceLogger(logger)

	log.Info("Logging config is successful")
}
开发者ID:RouGang,项目名称:gossipd,代码行数:26,代码来源:gossipd.go

示例15: main

func main() {
	logConfigFile := flag.String("l", "./conf/log.xml", "Log config file")
	configFile := flag.String("c", "./conf/conf.json", "Config file")

	flag.Parse()

	logger, err := log.LoggerFromConfigAsFile(*logConfigFile)
	if err != nil {
		fmt.Printf("Load log config failed: (%s)\n", err)
		os.Exit(1)
	}

	log.ReplaceLogger(logger)

	err = conf.LoadConfig(*configFile)
	if err != nil {
		log.Warnf("LoadConfig (%s) failed: (%s)\n", *configFile, err)
		os.Exit(1)
	}

	http.HandleFunc("/api/v1/notify", postNotify)
	err = http.ListenAndServe(conf.Config.Notify.Addr, nil)
	if err != nil {
		log.Warnf("failed to ListenAndServe: ", err)
		os.Exit(1)
	}
}
开发者ID:houcy,项目名称:push,代码行数:27,代码来源:notify.go


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