1 package fog 2 3 import ( 4 "bytes" 5 "net/http" 6 "time" 7 ) 8 9 // Google cloud log level names, which correspond to functionality provided. GCP 10 // has a DEFAULT log level below DEBUG, but it is not used. 11 // 12 // https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#logseverity 13 const ( 14 Debug = "DEBUG" // Debug or trace information. 15 Info = "INFO" // Routine information, such as ongoing status or performance. 16 Notice = "NOTICE" // Normal but significant events, such as start up, shut down, or a configuration change. 17 Warning = "WARNING" // Warning events might cause problems. 18 Error = "ERROR" // Error events are likely to cause problems. 19 Critical = "CRITICAL" // Critical events cause more severe problems or outages. 20 Alert = "ALERT" // A person must take an action immediately. 21 Emergency = "EMERGENCY" // One or more systems are unusable. 22 ) 23 24 // Zap's log severity levels as ints, these levels get more verbose as the number gets smaller and more important 25 // and the number gets larger (DebugLevel is -1, InfoLevel is 0, WarnLevel is 1, and so on). 26 const ( 27 DEBUG = -1 28 INFO = 0 29 WARN = 1 30 ERROR = 2 31 DPANIC = 3 32 PANIC = 4 33 FATAL = 5 34 ) 35 36 // Constants for Google cloud structured logging keys 37 // https://cloud.google.com/logging/docs/agent/logging/configuration#special-fields 38 const ( 39 TimeKey = "time" 40 LevelKey = "severity" 41 CallerKey = "caller" 42 MessageKey = "message" 43 StacktraceKey = "stacktrace" 44 SourceKey = "logging.googleapis.com/sourceLocation" 45 labelsKey = "logging.googleapis.com/labels" 46 operationKey = "logging.googleapis.com/operation" 47 ) 48 49 const ( 50 // errorKey is the key that error values are logged with 51 errorKey = "error" 52 // lvlKey is the key that numeric V level values are logged with 53 lvlKey = "level" 54 // gcpLabelKey is the constant that is used to check if a map is one that is passed in by the Label command 55 gcpLabelKey = "gcpLabel." 56 // gcpOperationKey is the constant that is used to check if a map is one that is passed in by the Operation command 57 gcpOperationKey = "gcpOperation." 58 ) 59 60 const ( 61 OperationKey = "logging.googleapis.com/operation" 62 SeverityKey = "severity" 63 ) 64 65 // MiddlewareContext is a struct through which the middleware logger obtains http request information, including status 66 // and request size, as well as response body information from the middleware handler 67 68 type MiddlewareContext struct { 69 Request *http.Request 70 Status int 71 Size int 72 Body *bytes.Buffer 73 Time time.Duration 74 } 75 76 // Option controls how the underlying Zap logger is constructed. 77 type Option func(*options) 78