[go server] enable configurable writer (#775)
This commit is contained in:
Родитель
1a7b608671
Коммит
2f37479daf
|
@ -2,6 +2,8 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
- Enable configurable Writer for log output (`go_server`) ([#775](https://github.com/mozilla/glean_parser/pull/775))
|
||||
|
||||
## 15.2.1
|
||||
|
||||
- Allow earlier versions of platformdirs ([#769](https://github.com/mozilla/glean_parser/pull/769))
|
||||
|
|
|
@ -11,6 +11,7 @@ package glean
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
|
@ -20,10 +21,15 @@ import (
|
|||
// log type string used to identify logs to process in the Moz Data Pipeline
|
||||
var gleanEventMozlogType string = "glean-server-event"
|
||||
|
||||
// A GleanEventsLogger produces output in the required format for Glean to ingest.
|
||||
// Glean ingestion requires the output to be written to os.Stdout. Writing to a different
|
||||
// output will require the consumer to handle any closing as appropriate for the Writer.
|
||||
// e.g. if writing to a file.
|
||||
type GleanEventsLogger struct {
|
||||
AppID string // Application Id to identify application per Glean standards
|
||||
AppDisplayVersion string // Version of application emitting the event
|
||||
AppChannel string // Channel to differentiate logs from prod/beta/staging/devel
|
||||
Writer io.Writer // Writer to output to. Normal operation expects os.Stdout
|
||||
}
|
||||
|
||||
// exported type for public method parameters
|
||||
|
@ -157,7 +163,9 @@ func (g GleanEventsLogger) record(
|
|||
if envelopeErr != nil {
|
||||
panic("Unable to marshal log envelope to json")
|
||||
}
|
||||
fmt.Println(string(envelopeJson))
|
||||
if g.Writer != nil {
|
||||
fmt.Fprintln(g.Writer, string(envelopeJson))
|
||||
}
|
||||
}
|
||||
{# if any ping has an event metric, create methods and types for them #}
|
||||
{% if events %}
|
||||
|
|
|
@ -10,6 +10,7 @@ package glean
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
|
@ -19,10 +20,15 @@ import (
|
|||
// log type string used to identify logs to process in the Moz Data Pipeline
|
||||
var gleanEventMozlogType string = "glean-server-event"
|
||||
|
||||
// A GleanEventsLogger produces output in the required format for Glean to ingest.
|
||||
// Glean ingestion requires the output to be written to os.Stdout. Writing to a different
|
||||
// output will require the consumer to handle any closing as appropriate for the Writer.
|
||||
// e.g. if writing to a file.
|
||||
type GleanEventsLogger struct {
|
||||
AppID string // Application Id to identify application per Glean standards
|
||||
AppDisplayVersion string // Version of application emitting the event
|
||||
AppChannel string // Channel to differentiate logs from prod/beta/staging/devel
|
||||
Writer io.Writer // Writer to output to. Normal operation expects os.Stdout
|
||||
}
|
||||
|
||||
// exported type for public method parameters
|
||||
|
@ -155,7 +161,9 @@ func (g GleanEventsLogger) record(
|
|||
if envelopeErr != nil {
|
||||
panic("Unable to marshal log envelope to json")
|
||||
}
|
||||
fmt.Println(string(envelopeJson))
|
||||
if g.Writer != nil {
|
||||
fmt.Fprintln(g.Writer, string(envelopeJson))
|
||||
}
|
||||
}
|
||||
|
||||
func newGleanEvent(category, name string, extra map[string]string) gleanEvent {
|
||||
|
|
|
@ -10,6 +10,7 @@ package glean
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
|
@ -19,10 +20,15 @@ import (
|
|||
// log type string used to identify logs to process in the Moz Data Pipeline
|
||||
var gleanEventMozlogType string = "glean-server-event"
|
||||
|
||||
// A GleanEventsLogger produces output in the required format for Glean to ingest.
|
||||
// Glean ingestion requires the output to be written to os.Stdout. Writing to a different
|
||||
// output will require the consumer to handle any closing as appropriate for the Writer.
|
||||
// e.g. if writing to a file.
|
||||
type GleanEventsLogger struct {
|
||||
AppID string // Application Id to identify application per Glean standards
|
||||
AppDisplayVersion string // Version of application emitting the event
|
||||
AppChannel string // Channel to differentiate logs from prod/beta/staging/devel
|
||||
Writer io.Writer // Writer to output to. Normal operation expects os.Stdout
|
||||
}
|
||||
|
||||
// exported type for public method parameters
|
||||
|
@ -155,7 +161,9 @@ func (g GleanEventsLogger) record(
|
|||
if envelopeErr != nil {
|
||||
panic("Unable to marshal log envelope to json")
|
||||
}
|
||||
fmt.Println(string(envelopeJson))
|
||||
if g.Writer != nil {
|
||||
fmt.Fprintln(g.Writer, string(envelopeJson))
|
||||
}
|
||||
}
|
||||
|
||||
func newGleanEvent(category, name string, extra map[string]string) gleanEvent {
|
||||
|
|
|
@ -10,6 +10,7 @@ package glean
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
|
@ -19,10 +20,15 @@ import (
|
|||
// log type string used to identify logs to process in the Moz Data Pipeline
|
||||
var gleanEventMozlogType string = "glean-server-event"
|
||||
|
||||
// A GleanEventsLogger produces output in the required format for Glean to ingest.
|
||||
// Glean ingestion requires the output to be written to os.Stdout. Writing to a different
|
||||
// output will require the consumer to handle any closing as appropriate for the Writer.
|
||||
// e.g. if writing to a file.
|
||||
type GleanEventsLogger struct {
|
||||
AppID string // Application Id to identify application per Glean standards
|
||||
AppDisplayVersion string // Version of application emitting the event
|
||||
AppChannel string // Channel to differentiate logs from prod/beta/staging/devel
|
||||
Writer io.Writer // Writer to output to. Normal operation expects os.Stdout
|
||||
}
|
||||
|
||||
// exported type for public method parameters
|
||||
|
@ -155,7 +161,9 @@ func (g GleanEventsLogger) record(
|
|||
if envelopeErr != nil {
|
||||
panic("Unable to marshal log envelope to json")
|
||||
}
|
||||
fmt.Println(string(envelopeJson))
|
||||
if g.Writer != nil {
|
||||
fmt.Fprintln(g.Writer, string(envelopeJson))
|
||||
}
|
||||
}
|
||||
|
||||
func newGleanEvent(category, name string, extra map[string]string) gleanEvent {
|
||||
|
|
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"glean/glean"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -10,6 +11,7 @@ func main() {
|
|||
AppID: "glean.test",
|
||||
AppDisplayVersion: "0.0.1",
|
||||
AppChannel: "nightly",
|
||||
Writer: os.Stdout,
|
||||
}
|
||||
|
||||
/* CODE */
|
||||
|
|
Загрузка…
Ссылка в новой задаче