-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(runtime): Executor now give a
LogWriter
to all reactors in the…
… constructor This `LogWriter` implements the `io.Writer` interface and also the `Sync()` interface that are used by the `zap` logging framework (and potentially others). The executor will make sure that each time a reactor logs, that the log messages will be correctly associated together with the message the reactor is reacting to.
- Loading branch information
1 parent
f2fa5d2
commit 6d2cbbe
Showing
4 changed files
with
118 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package executorEL | ||
|
||
type LogWriter [][]byte | ||
|
||
func newLogWriter() *LogWriter { | ||
x := LogWriter(make([][]byte, 0, 0)) | ||
return &x | ||
} | ||
|
||
func (lw *LogWriter) dump() []string { | ||
logs := make([]string, 0, len(*lw)) | ||
for _, l := range *lw { | ||
logs = append(logs, string(l)) | ||
} | ||
*lw = LogWriter(make([][]byte, 0, 0)) | ||
return logs | ||
} | ||
|
||
func (_ *LogWriter) Sync() error { | ||
return nil | ||
} | ||
|
||
func (lw *LogWriter) Write(p []byte) (n int, err error) { | ||
if len(p) > 0 { | ||
// make a copy of the line so that it doesn't get changed later | ||
line := make([]byte, len(p)) | ||
copy(line, p) | ||
|
||
// we remove last byte since it is an newline | ||
*lw = append(*lw, line[:len(line)-1]) | ||
} | ||
return len(p), nil | ||
} | ||
|
||
/* | ||
func (lw LogWriter) AppendToLogger(logger *zap.Logger) *zap.Logger { | ||
return logger.WithOptions(zap.WrapCore(func(c zapcore.Core) zapcore.Core { | ||
config := zap.NewDevelopmentEncoderConfig() | ||
config.TimeKey = "" | ||
config.LineEnding = "" | ||
dbLogger := zapcore.NewCore(zapcore.NewConsoleEncoder(config), lw, c) | ||
return zapcore.NewTee(c, dbLogger) | ||
})) | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters