Documentation ¶
Overview ¶
Package log provides a wrapper to the underlying logging library.
Logging should be done by accessing the log.Logger object to issue log statements.
Using any of the base loggers (Debug, Info, Warn, Error) any additional fields will be concatenated onto the "msg" field. This may cause serialization issues.
It's suggested to use the "with" log methods (Debugw, Infow, Warnw, Errorw) to include additional fields in the log line.
Examples:
Log with additional fields in JSON: log.Logger.Infow("My message to log", "key1", "value1", "key2", 9999, "key3", errors.New("an error")) or log.Logger.Infow("My message to log", log.String("key1", "value1")) Log data directly into the message: log.Logger.Info("My message to log with data", " key1: ", SOMEVAR, " key2: ", 9999)
NOT RECOMMENDED
Log data in the message and additional fields: log.Logger.Infow(fmt.Sprintf("My message to log with data 5v"), "error", error) Log data directly into the message without serialization: log.Logger.Infof("My message to log with data %v", 77.33232) log.Logger.Infof("My message to log with data %d", 77.33232)
Note:
When using the logger if you use the "f" methods such as Infof the data in the message will be serialized unless you use Sprintf style in the message and the correct type on the data such as %v, %s, %d. The suggested approach is to separate any data into separate fields for logging.
Index ¶
- Constants
- Variables
- func CloudLoggingClient(ctx context.Context, projectID string) *logging.Client
- func Error(err error) zap.Field
- func Float64(key string, value float64) zap.Field
- func FlushCloudLog()
- func GetLevel() string
- func GetLogFile() string
- func Int64(key string, value int64) zap.Field
- func Print(msg string)
- func SetupLogging(params Parameters)
- func SetupLoggingForTest()
- func SetupLoggingToDiscard()
- func String(key string, value string) zap.Field
- type CloudCore
- func (c *CloudCore) Check(e zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.CheckedEntry
- func (c *CloudCore) Enabled(l zapcore.Level) bool
- func (c *CloudCore) Sync() error
- func (c *CloudCore) With(additionalFields []zapcore.Field) zapcore.Core
- func (c *CloudCore) Write(ze zapcore.Entry, additionalFields []zapcore.Field) error
- type GoogleCloudLogger
- type Parameters
Constants ¶
const ( // LinuxDaemonLogPath is the log path for daemon mode features on linux. LinuxDaemonLogPath = `/var/log/google-cloud-sap-agent.log` // WindowsDaemonLogPath is the log path for daemon mode features on windows. WindowsDaemonLogPath = `C:\Program Files\Google\google-cloud-sap-agent\logs\google-cloud-sap-agent.log` // LinuxOneTimeLogPrefix is the prefix of the log path to be used by One Time Execution features. LinuxOneTimeLogPrefix = `/var/log/google-cloud-sap-agent-` // WindowsOneTimeLogPrefix is the prefix of the log path to be used by One Time Execution features. WindowsOneTimeLogPrefix = `C:\Program Files\Google\google-cloud-sap-agent\logs\google-cloud-sap-agent-` )
Variables ¶
var Logger *zap.SugaredLogger
Logger used for logging structured messages
Functions ¶
func CloudLoggingClient ¶
CloudLoggingClient create a logging.Client for writing logs to CloudLogging, will be nil if a ping fails
func FlushCloudLog ¶
func FlushCloudLog()
FlushCloudLog will flush any buffered log entries to cloud logging if it is enabled.
func Print ¶
func Print(msg string)
Print will use the go default log to print messages to the console, should only be used by main.
func SetupLogging ¶
func SetupLogging(params Parameters)
SetupLogging uses the agent configuration to set up the file Logger.
func SetupLoggingForTest ¶
func SetupLoggingForTest()
SetupLoggingForTest creates the Logger to log to the console during unit tests.
func SetupLoggingToDiscard ¶
func SetupLoggingToDiscard()
SetupLoggingToDiscard provides the configuration of the Logger to discard all logs. Discarding logs is only used when the agent is run remotely during workload manager metrics remote collection.
Types ¶
type CloudCore ¶
type CloudCore struct { GoogleCloudLogger GoogleCloudLogger LogLevel zapcore.Level }
CloudCore that will be used as a zapcore.Core
func (*CloudCore) Check ¶
func (c *CloudCore) Check(e zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.CheckedEntry
Check implements zapcore.Core.
type GoogleCloudLogger ¶
GoogleCloudLogger interface
type Parameters ¶
type Parameters struct { LogToCloud bool CloudLoggingClient *logging.Client OSType string Level cpb.Configuration_LogLevel SubCommandName string LogFileName string CloudLogName string }
Parameters for setting up logging
func SetupDaemonLogging ¶
func SetupDaemonLogging(params Parameters) Parameters
SetupDaemonLogging creates logging config for the agent's daemon mode.
func SetupOneTimeLogging ¶
func SetupOneTimeLogging(params Parameters, subcommandName string) Parameters
SetupOneTimeLogging creates logging config for the agent's one time execution.