mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Changes on function/metric loggers (#343)
* initial fix logger * dix DefaultFuncLogger * fix runner and tests * reverting: sending async task stdout to func logger
This commit is contained in:
41
api/runner/func_logger.go
Normal file
41
api/runner/func_logger.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package runner
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
|
||||
"context"
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/iron-io/runner/common"
|
||||
)
|
||||
|
||||
type FuncLogger interface {
|
||||
Writer(context.Context, string, string, string, string) io.Writer
|
||||
}
|
||||
|
||||
// FuncLogger reads STDERR output from a container and outputs it in a parseable structured log format, see: https://github.com/iron-io/functions/issues/76
|
||||
type DefaultFuncLogger struct {
|
||||
}
|
||||
|
||||
func NewFuncLogger() FuncLogger {
|
||||
return &DefaultFuncLogger{}
|
||||
}
|
||||
|
||||
func (l *DefaultFuncLogger) Writer(ctx context.Context, appName, path, image, reqID string) io.Writer {
|
||||
r, w := io.Pipe()
|
||||
|
||||
log := common.Logger(ctx)
|
||||
log = log.WithFields(logrus.Fields{"user_log": true, "app_name": appName, "path": path, "image": image, "call_id": reqID})
|
||||
|
||||
go func(reader io.Reader) {
|
||||
scanner := bufio.NewScanner(reader)
|
||||
for scanner.Scan() {
|
||||
log.Println(scanner.Text())
|
||||
}
|
||||
if err := scanner.Err(); err != nil {
|
||||
log.WithError(err).Println("There was an error with the scanner in attached container")
|
||||
}
|
||||
}(r)
|
||||
|
||||
return w
|
||||
}
|
||||
Reference in New Issue
Block a user