本文整理汇总了Golang中github.com/cihub/seelog.LoggerFromConfigAsBytes函数的典型用法代码示例。如果您正苦于以下问题:Golang LoggerFromConfigAsBytes函数的具体用法?Golang LoggerFromConfigAsBytes怎么用?Golang LoggerFromConfigAsBytes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LoggerFromConfigAsBytes函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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!")
}
示例2: 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)
}
}
示例3: NewLogs
func NewLogs() {
logger, err := log.LoggerFromConfigAsBytes([]byte(default_template))
if err != nil {
log.Criticalf("log config err: %v", err)
}
log.ReplaceLogger(logger)
}
示例4: 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)
}
示例5: configureLog
func configureLog() {
level := Get("lamp.log.level")
if level == "" {
level = "warn"
printVerboseMessage("Could not get log level from configuration, will use default \"warn\".")
}
logDir := os.Getenv(logDir)
var outPath string
logFile := Get("lamp.log.file")
if logFile == "" {
logFile = "lamp.log"
printVerboseMessage("Could not get log filename from configuration. \"lamp.log\" will be used as log filename.")
}
if logDir != "" {
outPath = logDir + sep + logFile
printVerboseMessage("Will write logs to: \n" + outPath)
} else {
outPath = lampHome() + "logs" + sep + logFile
printVerboseMessage("LAMP_LOGS_DIR environment variable is not set. Will write logs to: \n" + outPath)
}
logConfig := template(outPath, level)
logger, err := seelog.LoggerFromConfigAsBytes([]byte(logConfig))
if err != nil {
fmt.Printf("Error occured while configuring logger: %s\n", err.Error())
}
log.UseLogger(logger)
}
示例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")
}
示例7: ConfigureLogger
// ConfigureLogger configures the new logger according to the configuration and sets it as the current logger.
func ConfigureLogger(testConfig []byte) {
loggr, err := seelog.LoggerFromConfigAsBytes([]byte(testConfig))
if err != nil {
fmt.Printf("error occured: %s\n", err.Error())
}
UseLogger(loggr)
}
示例8: 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")
}
示例9: TestGosnmp
func TestGosnmp(t *testing.T) {
RegisterFailHandler(Fail)
pid := os.Getpid()
loggingConfig := fmt.Sprintf(`
<seelog>
<outputs>
<buffered size="10000" flushperiod="1000" formatid="debug">
<rollingfile type="size" filename="logs/debuglog.log" maxsize="10000000" maxrolls="10" />
</buffered>
</outputs>
<formats>
<format id="debug" format="%d %%Date(Mon Jan _2 15:04:05.000000) [%%LEV] %%File:%%Line %%Msg%%n"/>
</formats>
</seelog>`, pid)
logger, err := seelog.LoggerFromConfigAsBytes([]byte(loggingConfig))
if err != nil {
Fail(fmt.Sprintf("Couldn't initialize logger: %s", err))
}
defer logger.Flush()
testIdGenerator := make(chan string)
go func() {
for i := 0; ; i++ {
testIdGenerator <- fmt.Sprintf("test %-3d", i)
}
}()
setupV2cClientTest(logger, testIdGenerator)
SetupLowLevelContextTest(logger, testIdGenerator)
RunSpecs(t, "gosnmp Suite")
}
示例10: 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)
}
示例11: loadAppConfig
func loadAppConfig() {
appConfig := `
<seelog minlevel="info">
<outputs formatid="common">
<rollingfile type="size" filename="/U8SOFT/turbocrm70/apache/logs/ws/roll.log" maxsize="100000" maxrolls="5"/>
<filter levels="critical">
<file path="/U8SOFT/turbocrm70/apache/logs/ws/critical.log" formatid="critical"/>
</filter>
<filter levels="error">
<file path="/U8SOFT/turbocrm70/apache/logs/ws/error.log" formatid="error"/>
</filter>
</outputs>
<formats>
<format id="common" format="%Date/%Time [%LEV] %Msg%n" />
<format id="critical" format="%File %FullPath %Func %Msg%n" />
<format id="error" format="%Date/%Time %File %FullPath %Func %Msg%n" />
</formats>
</seelog>`
logger, err := seelog.LoggerFromConfigAsBytes([]byte(appConfig))
if err != nil {
fmt.Println(err)
return
}
UseLogger(logger)
}
示例12: loadAppConfig
func loadAppConfig() {
appConfig := `
<seelog type="adaptive" mininterval="2000000" maxinterval="100000000" critmsgcount="500" minlevel="debug">
<exceptions>
<exception filepattern="test*" minlevel="error"/>
</exceptions>
<outputs formatid="all">
<file path="all.log"/>
<filter levels="info">
<console formatid="fmtinfo"/>
</filter>
<filter levels="error,critical" formatid="fmterror">
<console/>
<file path="errors.log"/>
</filter>
</outputs>
<formats>
<format id="fmtinfo" format="[%Level] [%Time] %Msg%n"/>
<format id="fmterror" format="[%LEVEL] [%Time] [%FuncShort @ %File.%Line] %Msg%n"/>
<format id="all" format="[%Level] [%Time] [@ %File.%Line] %Msg%n"/>
<format id="criticalemail" format="Critical error on our server!\n %Time %Date %RelFile %Func %Msg \nSent by Seelog"/>
</formats>
</seelog>
`
logger, err := seelog.LoggerFromConfigAsBytes([]byte(appConfig))
if err != nil {
fmt.Println(err)
return
}
UseLogger(logger)
}
示例13: loadAppConf
func loadAppConf() {
// appConf := `<seelog />`
appConf := `
<seelog minlevel="warn">
<outputs formatid="common">
<rollingfile type="size" filename="/Users/winniewang/source/go-workspace/logs/roll.log" maxsize="100000" maxrolls="5"/>
<filter levels="critical">
<file path="/Users/winniewang/source/go-workspace/logs/critical.log" formatid="critical"/>
<smtp formatid="criticalemail" senderaddress="[email protected]" sendername="Zhou Zhefu" hostname="smtp.gmail.com" hostport="587" username="zhou.zhefu" password="5642326">
<recipient address="[email protected]"/>
</smtp>
</filter>
</outputs>
<formats>
<format id="common" format="%Date/%Time [%LEV] %Msg%n" />
<format id="critical" format="%File %FullPath %Func %Msg%n" />
<format id="criticalemail" format="Critical error on our server!\n %Time %Date %RelFile %Func %Msg \nSent by Seelog"/>
</formats>
</seelog>
`
logger, err := seelog.LoggerFromConfigAsBytes([]byte(appConf))
if err != nil {
fmt.Println(err)
return
}
UseLogger(logger)
}
示例14: createLogger
func createLogger(logName string) (seelog.LoggerInterface, error) {
conf, err := createLogConf(logName)
if err != nil {
fmt.Println("build log conf err", err)
os.Exit(1)
}
return seelog.LoggerFromConfigAsBytes(conf)
}
示例15: setLogLevel
func setLogLevel(level string) {
if level != "error" && level != "warn" {
log.Infof("Setting log level '%s'.", level)
}
logConfig := fmt.Sprintf("<seelog minlevel='%s'>", level)
logger, _ := log.LoggerFromConfigAsBytes([]byte(logConfig))
log.ReplaceLogger(logger)
}