Documentation ¶
Overview ¶
TODO(dogben) Move slog impl to its own package.
Index ¶
- Constants
- Variables
- func CustomLog(reportName string, payload *LogPayload)
- func InitCloudLogging(c *http.Client, logGrouping, defaultReport string) error
- func NewLogger() sklog_impl.Logger
- func PostInitCloudLogging(c *http.Client) error
- func PreInitCloudLogging(logGrouping, defaultReport string) error
- func SetLogger(lg CloudLogger)
- type CloudLogger
- type CloudLoggerSLogImpl
- type LogPayload
- type SLogLogMode
Constants ¶
const ( CLOUD_LOGGING_WRITE_SCOPE = logging.LoggingWriteScope CLOUD_LOGGING_READ_SCOPE = logging.LoggingReadScope // CLOUD_LOGGING_URL_FORMAT is the URL, where first string is defaultReport, second is logGrouping CLOUD_LOGGING_URL_FORMAT = "" /* 139-byte string literal not displayed */ // WRITE_LOG_ENTRIES_REQUEST_TIMEOUT is the Timeout for making the WriteLogEntriesRequest request. WRITE_LOG_ENTRIES_REQUEST_TIMEOUT = time.Second // MAX_QPS_LOG is the max number of log lines we expect to generate per second. MAX_QPS_LOG = 10000 // LOG_WRITE_SECONDS is the time between batch writes to cloud logging, in seconds. LOG_WRITE_SECONDS = 5 // MAX_LOG_SIZE is the max number of log entries we keep locally. MAX_LOG_SIZE = LOG_WRITE_SECONDS * MAX_QPS_LOG // REQ_SIZE_BASE is the approximate base size in bytes of an empty log // push request in bytes. REQ_SIZE_BASE = 128 // REQ_SIZE_MAX is the maximum size in bytes of a log push request. Give // ourselves 20% headroom just in case our estimates are incorrect. REQ_SIZE_MAX = int(10485760.0 * 0.80) // ENTRY_SIZE_BASE is the approximate size in bytes of a serialized // empty LogEntry object. ENTRY_SIZE_BASE = 512 // ENTRY_SIZE_MAX is the maximum size in bytes of a serialized LogEntry // object. Give ourselves 20% headroom just in case our estimates are // incorrect. ENTRY_SIZE_MAX = int(112640.0 * 0.80) // PAYLOAD_SIZE_MAX is the approximate maximum log line size in bytes. PAYLOAD_SIZE_MAX = ENTRY_SIZE_MAX - ENTRY_SIZE_BASE )
There a variety of Log Entry types, but for simplicity, we have stuck with the "text payload" option
const ( // b/120145392 KUBERNETES_FILE_LINE_NUMBER_WORKAROUND = true )
Variables ¶
var ( // Severities used primarily by Cloud Logging. DEBUG = sklog_impl.Debug.StackdriverString() INFO = sklog_impl.Info.StackdriverString() WARNING = sklog_impl.Warning.StackdriverString() ERROR = sklog_impl.Error.StackdriverString() CRITICAL = "CRITICAL" ALERT = sklog_impl.Fatal.StackdriverString() )
Functions ¶
func CustomLog ¶
func CustomLog(reportName string, payload *LogPayload)
CustomLog allows any clients to write a LogPayload to a report with a custom group name (e.g. "log file name"). This is the simplest way for an app to send logs to somewhere other than the default report name (typically based on the app-name).
func InitCloudLogging ¶
CLIENTS SHOULD NOT CALL InitCloudLogging directly. Instead use common.InitWithCloudLogging. InitCloudLogging initializes the module-level logger. logGrouping refers to the MonitoredResource's name. If blank, logGrouping defaults to the machine's hostname. defaultReportName refers to the default "virtual log file" name that Log Entries will be associated with if no other reportName is given. If an error is returned, cloud logging will not
be used, instead glog will.
InitCloudLogging should be called before the program creates any go routines such that all subsequent logs are properly sent to the Cloud.
func NewLogger ¶
func NewLogger() sklog_impl.Logger
func PostInitCloudLogging ¶
PostInitCloudLogging finishes initializing cloud logging.
CLIENTS SHOULD NOT CALL PostInitCloudLogging directly. Instead use common.InitWith().
func PreInitCloudLogging ¶
PreInitCloudLogging does the first step in initializing cloud logging.
CLIENTS SHOULD NOT CALL PreInitCloudLogging directly. Instead use common.InitWith().
func SetLogger ¶
func SetLogger(lg CloudLogger)
SetLogger changes the package to use the given CloudLogger.
Types ¶
type CloudLogger ¶
type CloudLogger interface { // CloudLog writes creates a Log Entry from the log payload and sends it to Cloud Logging to be // associated with the "virtual log file" given by reportName. Log entries will automatically be // labeled with the machine's hostname. // Most clients will use the convenience methods in sklog.go. The primary use case for using // CloudLog directly is if customizing the reportName, the time, or use one of the less common // severities. CloudLog(reportName string, payload *LogPayload) // Wait until any outstanding writes to Cloud Logging have finished. Flush() }
A CloudLogger interacts with the CloudLogging api
type CloudLoggerSLogImpl ¶
type CloudLoggerSLogImpl struct {
// contains filtered or unexported fields
}
CloudLoggerSLogImpl implements CloudLogger using slog.Logger.
func NewSLogCloudLogger ¶
func NewSLogCloudLogger(l slog.Logger) *CloudLoggerSLogImpl
NewSLogCloudLogger returns a CloudLoggerSLogImpl that uses the given slog.Logger.
func NewStdErrCloudLogger ¶
func NewStdErrCloudLogger(mode SLogLogMode) *CloudLoggerSLogImpl
NewSLogLogger creates a new CloudLoggerSLogImpl that either logs to stderr, or does no logging, depending upon the value of mode. It uses github.com/jcgregorio/logger to implement the slog.Logger interface.
The return value implements CloudLogger.
Usage:
sklog.SetLogger(sklog.NewStdErrCloudLogger(logToStdErr))
func (*CloudLoggerSLogImpl) CloudLog ¶
func (c *CloudLoggerSLogImpl) CloudLog(reportName string, payload *LogPayload)
See CloudLogger.
type LogPayload ¶
type LogPayload struct { // Payload is the text content of the log file. Payload string // Time is the when the log happened. Time time.Time // Severity is one of the strings found in this package, such as DEBUG, ALERT, etc. Severity string // Any additional labels to be added to this Log Entry. hostname is already included. // These labels can be searched on. ExtraLabels map[string]string }
LogPayload represents the contents of a Log Entry with a text payload.
type SLogLogMode ¶
type SLogLogMode int
SLogLogMode is the mode logging enum type.
const ( SLogNone SLogLogMode = iota SLogStderr )
Types of logging that NewSLogLogger supports.