Documentation ¶
Overview ¶
Package gcloghook implements a hook for the github.com/sirupsen/logrus package to send structured log records to the Google Cloud Logging service.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type StackDriverHook ¶
func NewStackDriverHook ¶
func NewStackDriverHook(googleProject string, logName string, logInstanceID string, logInstanceName string, logInstanceZone string) (*StackDriverHook, error)
NewStackDriverHook allocates a new hook ready to be used for logrus.AddHook. The hook will send log records to the Google Cloud Logging API, and if the logrus error record uses a level of ErrorLevel or higher, the record will also be forwarded to the Error reporting API.
Example ¶
googleProject := os.Getenv("GOOGLE_CLOUD_PROJECT") myLog := logrus.New() formatter := stackdriver.GAEStandardFormatter( stackdriver.WithProjectID(googleProject), ) myLog.SetFormatter(formatter) myLog.SetOutput(os.Stdout) log_name := os.Getenv("LOG_NAME") if log_name != "" { hook, err := NewStackDriverHook(googleProject, log_name, os.Getenv("LOG_INSTANCEID"), os.Getenv("LOG_INSTANCENAME"), os.Getenv("LOG_INSTANCEZONE")) if err != nil { myLog.WithError(err).Fatal("StackDriver") } myLog.AddHook(hook) myLog.SetOutput(io.Discard) } myLog.Info("Hello world!")
Output:
func (*StackDriverHook) Close ¶
func (sh *StackDriverHook) Close() error
func (*StackDriverHook) Levels ¶
func (sh *StackDriverHook) Levels() []logrus.Level
func (*StackDriverHook) Wait ¶
func (sh *StackDriverHook) Wait()
Click to show internal directories.
Click to hide internal directories.