本文整理匯總了Golang中github.com/cihub/seelog.LoggerFromConfigAsString函數的典型用法代碼示例。如果您正苦於以下問題:Golang LoggerFromConfigAsString函數的具體用法?Golang LoggerFromConfigAsString怎麽用?Golang LoggerFromConfigAsString使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了LoggerFromConfigAsString函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例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)
}
}
示例3: configureLogging
func configureLogging(verbose bool) {
minLevel := "info"
if verbose {
minLevel = "trace"
}
logger, err := log.LoggerFromConfigAsString(fmt.Sprintf(`
<seelog minlevel="%s">
<outputs formatid="out">
<console />
</outputs>
<formats>
<format id="out" format="%%Date %%Time [%%LEVEL] %%Msg%%n" />
</formats>
</seelog>
`, minLevel))
if err != nil {
panic(err)
}
log.ReplaceLogger(logger)
}
示例4: 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)
}
}
示例5: InitDefaultSyncLogConfig
func InitDefaultSyncLogConfig() {
logger, err := log.LoggerFromConfigAsString(DEFAULT_SYNC_LOG_CONFIG)
if err != nil {
panic(err)
}
log.ReplaceLogger(logger)
}
示例6: DisableLogs
func DisableLogs() {
logger, err := log.LoggerFromConfigAsString(DEFAULT_DISABLE_LOGS_CONFIG)
if err != nil {
panic(err)
}
log.ReplaceLogger(logger)
}
示例7: ServeHttp
// ServeHttp serves IAM Role Credentials for Tasks being managed by the agent.
func ServeHttp(credentialsManager credentials.Manager, containerInstanceArn string, cfg *config.Config) {
// Create and initialize the audit log
// TODO Use seelog's programmatic configuration instead of xml.
logger, err := log.LoggerFromConfigAsString(audit.AuditLoggerConfig(cfg))
if err != nil {
log.Errorf("Error initializing the audit log: %v", err)
// If the logger cannot be initialized, use the provided dummy seelog.LoggerInterface, seelog.Disabled.
logger = log.Disabled
}
auditLogger := audit.NewAuditLog(containerInstanceArn, cfg, logger)
server := setupServer(credentialsManager, auditLogger)
for {
utils.RetryWithBackoff(utils.NewSimpleBackoff(time.Second, time.Minute, 0.2, 2), func() error {
// TODO, make this cancellable and use the passed in context;
err := server.ListenAndServe()
if err != nil {
log.Errorf("Error running http api: %v", err)
}
return err
})
}
}
示例8: SetupLogger
func SetupLogger() {
logger, err := log.LoggerFromConfigAsString(loggerConfig())
if err == nil {
log.ReplaceLogger(logger)
} else {
log.Error(err)
}
}
示例9: reloadLogConfig
func reloadLogConfig() {
logger, err := seelog.LoggerFromConfigAsString(loggerConfig())
if err == nil {
seelog.ReplaceLogger(logger)
} else {
seelog.Error(err)
}
}
示例10: init
func init() {
logger, err := log.LoggerFromConfigAsString(logConfig)
if err != nil {
fmt.Printf("Could not load seelog configuration: %s\n", err)
return
}
log.ReplaceLogger(logger)
}
示例11: initLogging
// Initialize logging from command arguments.
func initLogging(configFile string) {
var err error
log.RegisterReceiver("stderr", &CustomReceiver{})
if configFile == "" {
logger, err = log.LoggerFromConfigAsString(defaultLoggingConfig)
checkLogFatal("Failed to load default logging configuration: %s", err)
} else {
logger, err = log.LoggerFromConfigAsFile(configFile)
checkLogFatal("Failed to initialize custom logging file %s: %s", configFile, err)
}
}
示例12: main
func main() {
logger, err := log.LoggerFromConfigAsString("<seelog type=\"asynctimer\" asyncinterval=\"500000000\"/>")
checkFail(err)
log.ReplaceLogger(logger)
defer log.Flush()
println("start")
log.Info("Hello from Seelog!")
time.Sleep(time.Second * 10)
}
示例13: initLoggerFactory
// Init logger factory.
func initLoggerFactory() error {
c.LoggerFactory = map[string]Log.LoggerInterface{}
for loggerName, config := range c.Config.Logger { // convert logger config to inst
if logInstance, err := Log.LoggerFromConfigAsString(config); err == nil {
c.LoggerFactory[loggerName] = logInstance
} else {
return err
}
}
return nil
}
示例14: main
func main() {
defer seelog.Flush()
seelog.LoggerFromConfigAsString("formatid=\"debug\"")
flag.Parse()
cfg := FtpCfg{*host, *user, *pw, *port}
fClient, err := NewFtpClient(cfg)
if err != nil {
panic(err)
}
iClient, err := NewInfluxClient(*surl, *db)
if err != nil {
panic(err)
}
files := make([]*FtpToInflux, 0)
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
line := scanner.Text()
seelog.Tracef("Handle line '%s'", line)
if strings.HasPrefix(line, commentPrefix) {
//Comment
continue
}
splittedLine := strings.Split(line, space)
if len(splittedLine) != 2 {
seelog.Warnf("Line '%s' has not exactly one space", line)
continue
}
data := &FtpToInflux{splittedLine[0], strings.Split(splittedLine[1], sep)}
files = append(files, data)
}
for _, f := range files {
seelog.Tracef("Start with file '%s'!", f.Filename)
buf, err := fClient.Download(f.Filename)
if err != nil {
seelog.Warnf("Error downloading file '%s': %v", f.Filename, err)
continue
}
datas := Transform(buf)
err = iClient.Write(datas, f.Measurements)
if err != nil {
seelog.Warnf("Error writing Data: %v", err)
continue
}
seelog.Tracef("File '%s' downloaded and written to %d measurements!", f.Filename, len(f.Measurements))
}
}
示例15: main
func main() {
cluster := gocql.NewCluster("127.0.0.1")
cluster.Keyspace = "system"
session, err := cluster.CreateSession()
defer session.Close()
if err != nil {
log.Critical(err)
}
traceSession, err := cluster.CreateSession()
defer session.Close()
if err != nil {
log.Critical(err)
}
// Create a new logger instance that we adjust the stack depth for to get
// more meaningful frames
logger, err := log.LoggerFromConfigAsString(
`<seelog>
<outputs>
<console formatid="fmt"/>
</outputs>
<formats>
<format id="fmt" format="%Date(Jan 02 2006 03:04:05.000) [%LEVEL] %File:%Line - %Msg%n"/>
</formats>
</seelog>
`)
logger.SetAdditionalStackDepth(2)
if err != nil {
log.Critical(err)
}
writer := NewTraceWriter(traceSession, logger)
tracer := gocql.NewTraceWriter(traceSession, writer)
session.SetTrace(tracer)
var count int
iter := session.Query(`select count(*) from schema_keyspaces`).Iter()
iter.Scan(&count)
err = iter.Close()
if err != nil {
log.Critical(err)
}
log.Infof("This instance has %d keyspaces", count)
}