Documentation ¶
Overview ¶
Package sdhook provides a logrus compatible logging hook for Google Stackdriver logging.
Index ¶
- Constants
- func FormatStack(err error) (buffer []byte)
- type Option
- func EntriesService(service *logging.EntriesService) Option
- func ErrorClient(errorClient *errorreporting.Client) Option
- func ErrorReportingLogName(name string) Option
- func ErrorReportingService(service string) Option
- func GoogleComputeCredentials(serviceAccount string) Option
- func GoogleLoggingAgent() Option
- func GoogleServiceAccountCredentialsFile(path string) Option
- func GoogleServiceAccountCredentialsJSON(buf []byte) Option
- func HTTPClient(client *http.Client) Option
- func Labels(labels map[string]string) Option
- func Levels(levels ...logrus.Level) Option
- func LogName(name string) Option
- func LoggingService(service *logging.Service) Option
- func MonitoredResource(resource *logging.MonitoredResource) Option
- func PartialSuccess(enabled bool) Option
- func ProjectID(projectID string) Option
- func Resource(typ ResType, labels map[string]string) Option
- type ResType
- type StackdriverHook
Constants ¶
const ( // DefaultName is the default name passed to LogName when using service // account credentials. DefaultName = "default" )
Variables ¶
This section is empty.
Functions ¶
func FormatStack ¶
Types ¶
type Option ¶
type Option func(*StackdriverHook) error
Option represents an option that modifies the Stackdriver hook settings.
func EntriesService ¶
func EntriesService(service *logging.EntriesService) Option
EntriesService is an option that sets the Google API entry service to use with Stackdriver.
func ErrorClient ¶
func ErrorClient(errorClient *errorreporting.Client) Option
ErrorClient is an option that sets the Google API error reporting service to use.
func ErrorReportingLogName ¶
ErrorReportingLogName is an option that sets the log name to send with each error message for error reporting. Only used when ErrorReportingService has been set.
func ErrorReportingService ¶
ErrorReportingService is an option that defines the name of the service being tracked for Stackdriver error reporting. See: https://cloud.google.com/error-reporting/docs/formatting-error-messages
func GoogleComputeCredentials ¶
GoogleComputeCredentials is an option that loads the Google Service Account credentials from the GCE metadata associated with the GCE compute instance. If serviceAccount is empty, then the default service account credentials associated with the GCE instance will be used.
func GoogleLoggingAgent ¶
func GoogleLoggingAgent() Option
func GoogleServiceAccountCredentialsFile ¶
GoogleServiceAccountCredentialsFile is an option that loads Google Service Account credentials for use with the StackdriverHook from the specified file.
Google Service Account credentials can be downloaded from the Google Cloud console: https://console.cloud.google.com/iam-admin/serviceaccounts/
func GoogleServiceAccountCredentialsJSON ¶
GoogleServiceAccountCredentialsJSON is an option that creates the Stackdriver logging service using the supplied Google service account credentials.
Google Service Account credentials can be downloaded from the Google Cloud console: https://console.cloud.google.com/iam-admin/serviceaccounts/
func HTTPClient ¶
HTTPClient is an option that sets the http.Client to be used when creating the Stackdriver service.
func Levels ¶
Levels is an option that sets the logrus levels that the StackdriverHook will create log entries for.
func LogName ¶
LogName is an option that sets the log name to send with each log entry.
Log names are specified as "projects/{projectID}/logs/{logName}" if the projectID is set. Otherwise, it's just "{logName}"
func LoggingService ¶
LoggingService is an option that sets the Google API logging service to use.
func MonitoredResource ¶
func MonitoredResource(resource *logging.MonitoredResource) Option
MonitoredResource is an option that sets the monitored resource to send with each log entry.
func PartialSuccess ¶
PartialSuccess is an option that toggles whether or not to write partial log entries.
type ResType ¶
type ResType string
ResType is a monitored resource descriptor type.
See https://cloud.google.com/logging/docs/api/v2/resource-list
const ( ResTypeAPI ResType = "api" ResTypeAppScriptFunction ResType = "app_script_function" ResTypeAwsEc2Instance ResType = "aws_ec2_instance" ResTypeBigqueryResource ResType = "bigquery_resource" ResTypeBuild ResType = "build" ResTypeClientAuthConfigBrand ResType = "client_auth_config_brand" ResTypeClientAuthConfigClient ResType = "client_auth_config_client" ResTypeCloudDebuggerResource ResType = "cloud_debugger_resource" ResTypeCloudFunction ResType = "cloud_function" ResTypeCloudsqlDatabase ResType = "cloudsql_database" ResTypeContainer ResType = "container" ResTypeDataflowStep ResType = "dataflow_step" ResTypeDataprocCluster ResType = "dataproc_cluster" ResTypeDeployment ResType = "deployment" ResTypeDeploymentManagerType ResType = "deployment_manager_type" ResTypeDNSManagedZone ResType = "dns_managed_zone" ResTypeGaeApp ResType = "gae_app" ResTypeGceAutoscaler ResType = "gce_autoscaler" ResTypeGceBackendService ResType = "gce_backend_service" ResTypeGceDisk ResType = "gce_disk" ResTypeGceFirewallRule ResType = "gce_firewall_rule" ResTypeGceForwardingRule ResType = "gce_forwarding_rule" ResTypeGceHealthCheck ResType = "gce_health_check" ResTypeGceImage ResType = "gce_image" ResTypeGceInstance ResType = "gce_instance" ResTypeGceInstanceGroup ResType = "gce_instance_group" ResTypeGceInstanceGroupManager ResType = "gce_instance_group_manager" ResTypeGceInstanceTemplate ResType = "gce_instance_template" ResTypeGceNetwork ResType = "gce_network" ResTypeGceOperation ResType = "gce_operation" ResTypeGceProject ResType = "gce_project" ResTypeGceReservedAddress ResType = "gce_reserved_address" ResTypeGceRoute ResType = "gce_route" ResTypeGceRouter ResType = "gce_router" ResTypeGceSnapshot ResType = "gce_snapshot" ResTypeGceSslCertificate ResType = "gce_ssl_certificate" ResTypeGceSubnetwork ResType = "gce_subnetwork" ResTypeGceTargetHTTPProxy ResType = "gce_target_http_proxy" ResTypeGceTargetHTTPSProxy ResType = "gce_target_https_proxy" ResTypeGceTargetPool ResType = "gce_target_pool" ResTypeGceURLMap ResType = "gce_url_map" ResTypeGcsBucket ResType = "gcs_bucket" ResTypeGkeCluster ResType = "gke_cluster" ResTypeGlobal ResType = "global" ResTypeHTTPLoadBalancer ResType = "http_load_balancer" ResTypeLoggingLog ResType = "logging_log" ResTypeLoggingSink ResType = "logging_sink" ResTypeMetric ResType = "metric" ResTypeMlJob ResType = "ml_job" ResTypeOrganization ResType = "organization" ResTypeProject ResType = "project" ResTypeServiceAccount ResType = "service_account" ResTypeTestserviceMatrix ResType = "testservice_matrix" ResTypeVpnGateway ResType = "vpn_gateway" )
type StackdriverHook ¶
type StackdriverHook struct {
// contains filtered or unexported fields
}
StackdriverHook provides a logrus hook to Google Stackdriver logging.
func New ¶
func New(opts ...Option) (*StackdriverHook, error)
New creates a StackdriverHook using the provided options that is suitible for using with logrus for logging to Google Stackdriver.
func (*StackdriverHook) Fire ¶
func (sh *StackdriverHook) Fire(entry *logrus.Entry) error
Fire writes the message to the Stackdriver entry service.
func (*StackdriverHook) Levels ¶
func (sh *StackdriverHook) Levels() []logrus.Level
Levels returns the logrus levels that this hook is applied to. This can be set using the Levels Option.
func (*StackdriverHook) Wait ¶
func (sh *StackdriverHook) Wait()
Wait will return after all subroutines have returned. Use in conjunction with logrus return handling to ensure all of your logs are delivered before your program exits. `logrus.RegisterExitHandler(h.Wait)`