You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Simply create the hook, and add it to a logrus logger:
// create hook using service account credentialsh, err:=sdhook.New(
sdhook.GoogleServiceAccountCredentialsFile("./credentials.json"),
)
// create logger with extra fields//// logrus fields will be converted to Stackdriver labelslogger:=logrus.New().WithFields(logrus.Fields{
"field1": 15,
"field2": 20,
})
// add hooklogger.Hooks.Add(h)
// log somethinglogger.Printf("something %d", 15)
The example above sends log entries directly to the logging API. If you have
the logging agent running, you can send log entries to it instead, with the
added benefit of having extra instance metadata added to your log entries by
the agent. In the example above, the initialization would simply be:
// create hook using the logging agenth, err:=sdhook.New(
sdhook.GoogleLoggingAgent(),
)
If you'd like to enable sending errors to Google's Error Reporting
(https://cloud.google.com/error-reporting/), you have to set the name of the
service, app or system you're running. Following the example above, the
initialization would then be:
// create hook using the logging agenth, err:=sdhook.New(
sdhook.GoogleLoggingAgent(),
sdhook.ErrorReportingService("your-great-app"),
)
Also note that, if you enable error reporting, errors and messages of more
severe levels go into the error log and will not be displayed in the regular
log. The error log name is either defined by the ErrorReportingLogName
function or defaults to <regular-log-name>_errors. This fulfills Google's
Error Reporting requirement that the log name should have the string err in
its name. See more in: https://cloud.google.com/error-reporting/docs/setup/ec2
To fulfill Google's Error Reporting requirement of a payload containing error
stack frame information (file name, function name and line number), it assumes
that this information has been added as a logrus.Field of name caller and
type stack.Frame from Facebook's stack package.
One way to easily achieve this transparently is to use another logrus Hook like
Gurpartap's logrus-stack.