Пример #1
0
// NewLogSink creates a new *LogSink for GAE
func NewLogSink(format string) *LogSink {
	return &LogSink{
		formatter: wcg.NewLogRecordFormatter(format),
		ctx:       nil,
		bigquery:  nil,
	}
}
Пример #2
0
// NewIOLogSink creates a new *IOLogSink object.
// format string can have following variables.
//
//   - $TIMESTAMP   : timestamp of a log record
//   - $LOGLEVEL    : log level
//   - $SOURCE_FILE : source file name where a record is produced.
//   - $SOURCE_LINE : a line no of source file where a record is produced.
//   - $GOROUTINE   : Goroutine ID
//   - $SESSSION_ID : Session ID
//   - $REQUEST_ID  : Request ID
//   - $USER_ID     : User ID
//   - $TEXT        : text message produced by app.
//
// and if it is "", "[$GOROUTINE:$USER_ID:$SESSION_ID:$REQUEST_ID] $TEXT ($SOURCE_FILE#$SOURCE_LINE)" is used.
func NewIOLogSink(format string, writer io.Writer, useColor bool) *IOLogSink {
	return &IOLogSink{
		formatter: wcg.NewLogRecordFormatter(format),
		factory:   &writerFactory{writer},
		color:     useColor,
	}
}
Пример #3
0
func newIOLogSinkFromConfig(cfg *logSinkFileConfig) *IOLogSink {
	return &IOLogSink{
		formatter:  wcg.NewLogRecordFormatter(cfg.Format),
		factory:    cfg.newFactory(),
		color:      cfg.Color,
		stacklevel: cfg.StackLevel,
	}
}
Пример #4
0
func UseStdout() {
	stdout := &IOLogSink{}
	stdout.formatter = wcg.NewLogRecordFormatter("")
	stdout.factory = &writerFactory{os.Stdout}
	stdout.color = true
	stdout.stacklevel = wcg.LogLevelDebug
	wcg.DefaultLogConfig.AddSink(stdout, wcg.LogLevelDebug)
}
Пример #5
0
// NewLogSinkWithContext creates a new *LogSink for GAE
func NewLogSinkWithContext(format string, ctx context.Context) *LogSink {
	var _bq *bigquery.Service
	if LogSinkConfig.IsBigQueryEnabled() {
		client, err := bq.NewHTTPClient(ctx)
		if err == nil {
			_bq, _ = bigquery.New(client)
		}
	}
	return &LogSink{
		formatter: wcg.NewLogRecordFormatter(format),
		ctx:       ctx,
		bigquery:  _bq,
	}
}