Documentation ¶
Overview ¶
Package cflog helps with logging GCP Cloud Functions.
Example (JsonString) ¶
package main import ( "context" "github.com/mvndaai/cflog" ) var ctx = context.Background() func main() { cflog.Warn(ctx, `{"message": "json string"}`) }
Output:
Example (JsonStruct) ¶
package main import ( "context" "github.com/mvndaai/cflog" ) var ctx = context.Background() func main() { type s struct { Message string `json:"message"` } cflog.Error(ctx, s{Message: "json struct"}) }
Output:
Example (String) ¶
package main import ( "context" "github.com/mvndaai/cflog" ) var ctx = context.Background() func main() { cflog.Debug(ctx, "string") }
Output:
Index ¶
- Constants
- func Critical(ctx context.Context, payload interface{})
- func Debug(ctx context.Context, payload interface{})
- func Error(ctx context.Context, payload interface{})
- func Info(ctx context.Context, payload interface{})
- func Log(ctx context.Context, severity Severity, payload interface{})
- func Warn(ctx context.Context, payload interface{})
- type Client
- type Severity
Examples ¶
Constants ¶
View Source
const ( SeverityDefault = Severity(ltype.LogSeverity_DEFAULT) SeverityDebug = Severity(ltype.LogSeverity_DEBUG) SeverityInfo = Severity(ltype.LogSeverity_INFO) SeverityNotice = Severity(ltype.LogSeverity_NOTICE) SeverityWarning = Severity(ltype.LogSeverity_WARNING) SeverityError = Severity(ltype.LogSeverity_ERROR) SeverityCritical = Severity(ltype.LogSeverity_CRITICAL) SeverityAlert = Severity(ltype.LogSeverity_ALERT) SeverityEmergency = Severity(ltype.LogSeverity_EMERGENCY) )
Using the log packages severity. https://godoc.org/google.golang.org/genproto/googleapis/logging/type#LogSeverity
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client holds a logging client and the resources needed for logging.
func NewClient ¶
NewClient creates a client for writing logs using environment variable. Use this if you want to want full control over the client. https://cloud.google.com/functions/docs/env-var
Example ¶
package main import ( "context" "github.com/mvndaai/cflog" ) func main() { c, err := cflog.NewClient(context.Background()) if err != nil { //... } defer c.Close() if err := c.Log(context.Background(), cflog.SeverityDebug, "Debug message"); err != nil { //... } }
Output:
Click to show internal directories.
Click to hide internal directories.