diff options
| author | Paul Buetow <paul@buetow.org> | 2023-09-05 14:39:21 +0300 |
|---|---|---|
| committer | Paul Buetow <pbuetow@mimecast.com> | 2023-09-07 15:32:23 +0300 |
| commit | e0cfd91c1df8ce4ab474f27e2c15c58316194a00 (patch) | |
| tree | 45d3bf098c2b69f4aa47fcdeac03ea67cee7c39a | |
| parent | 42ffa0dba95ab773b50b15135c2065da94a8069e (diff) | |
Add `custom1` and `custom2` log formats.
| -rw-r--r-- | doc/logformats.md | 2 | ||||
| -rw-r--r-- | internal/mapr/logformat/custom1.go | 16 | ||||
| -rw-r--r-- | internal/mapr/logformat/custom2.go | 16 | ||||
| -rw-r--r-- | internal/mapr/logformat/parser.go | 16 |
4 files changed, 48 insertions, 2 deletions
diff --git a/doc/logformats.md b/doc/logformats.md index 9d4e55d..839b050 100644 --- a/doc/logformats.md +++ b/doc/logformats.md @@ -148,4 +148,6 @@ func (p *fooParser) MakeFields(maprLine string) (map[string]string, error) { } ``` +Next, `NewParser(...)` in `internal/mapr/logformat/parser.go` needs to be extended, so that the new log format is part of the switch statement. If you don't want to edit `parser.go` then you could instead use `custom1` or `custom2` log formats, there are ready templates available in the `logformat` package. + Once done, recompile DTail. DTail now understands `... logformat foo` (see "Seleting a log format" above). diff --git a/internal/mapr/logformat/custom1.go b/internal/mapr/logformat/custom1.go new file mode 100644 index 0000000..7229f3e --- /dev/null +++ b/internal/mapr/logformat/custom1.go @@ -0,0 +1,16 @@ +package logformat + +import "errors" + +var ErrCustom1NotImplemented error = errors.New("custom1 log format is not implemented") + +// Template for creating a custom log format. +type custom1Parser struct{} + +func newCustom1Parser(hostname, timeZoneName string, timeZoneOffset int) (*custom1Parser, error) { + return &custom1Parser{}, ErrCustom1NotImplemented +} + +func (p *custom1Parser) MakeFields(maprLine string) (map[string]string, error) { + return nil, ErrCustom1NotImplemented +} diff --git a/internal/mapr/logformat/custom2.go b/internal/mapr/logformat/custom2.go new file mode 100644 index 0000000..262c721 --- /dev/null +++ b/internal/mapr/logformat/custom2.go @@ -0,0 +1,16 @@ +package logformat + +import "errors" + +var ErrCustom2NotImplemented error = errors.New("custom2 log format is not implemented") + +// Template for creating a custom log format. +type custom2Parser struct{} + +func newCustom2Parser(hostname, timeZoneName string, timeZoneOffset int) (*custom2Parser, error) { + return &custom2Parser{}, ErrCustom2NotImplemented +} + +func (p *custom2Parser) MakeFields(maprLine string) (map[string]string, error) { + return nil, ErrCustom2NotImplemented +} diff --git a/internal/mapr/logformat/parser.go b/internal/mapr/logformat/parser.go index aa6416c..24290ef 100644 --- a/internal/mapr/logformat/parser.go +++ b/internal/mapr/logformat/parser.go @@ -2,6 +2,7 @@ package logformat import ( "errors" + "fmt" "time" "github.com/mimecast/dtail/internal/config" @@ -26,6 +27,7 @@ func NewParser(logFormatName string, query *mapr.Query) (Parser, error) { now := time.Now() timeZoneName, timeZoneOffset := now.Zone() + // Extend this for adding more log formats! switch logFormatName { case "generic": return newGenericParser(hostname, timeZoneName, timeZoneOffset) @@ -33,8 +35,18 @@ func NewParser(logFormatName string, query *mapr.Query) (Parser, error) { return newGenericKVParser(hostname, timeZoneName, timeZoneOffset) case "mimecast": return newMimecastParser(hostname, timeZoneName, timeZoneOffset) - default: + case "default": return newDefaultParser(hostname, timeZoneName, timeZoneOffset) - + case "custom1": + return newCustom1Parser(hostname, timeZoneName, timeZoneOffset) + case "custom2": + return newCustom2Parser(hostname, timeZoneName, timeZoneOffset) + default: + p, err := newDefaultParser(hostname, timeZoneName, timeZoneOffset) + if err != nil { + return p, fmt.Errorf("No '%s' mapr log format and problem creating default one: %v", + logFormatName, err) + } + return p, fmt.Errorf("No '%s' mapr log format", logFormatName) } } |
