Documentation ¶
Overview ¶
Description: This package provides utility functions for logging.
Index ¶
- Constants
- func GetComponent() string
- func GetComponentCustom(skip int, includeFuncPath, includeFile, includeFilePath, includeLine bool) string
- func GetComponentWithFile() string
- func GetTrace(ctx context.Context, traceKey interface{}) string
- type GoogleLogEntry
- type LogLevel
- type Logger
- func (l *Logger) Debug(entry GoogleLogEntry)
- func (l *Logger) Error(entry GoogleLogEntry)
- func (l *Logger) Info(entry GoogleLogEntry)
- func (l *Logger) JSONLog(ctx context.Context, level LogLevel, data interface{}, emoji string, ...)
- func (l *Logger) Log(ctx context.Context, level LogLevel, message, component string)
- func (l *Logger) SLog(ctx context.Context, level LogLevel, emoji string, messages ...string)
- func (l *Logger) Warn(entry GoogleLogEntry)
- type LoggerPort
Constants ¶
const ( GoogleMessageKey googleLogKey = "message" GoogleSeverityKey googleLogKey = "severity" GoogleTimestampKey googleLogKey = "timestamp" GoogleComponentKey googleLogKey = "component" GoogleTraceKey googleLogKey = "trace" )
Variables ¶
This section is empty.
Functions ¶
func GetComponent ¶
func GetComponent() string
GetComponent returns details about the caller function, including the function name and line number.
This information is used to populate the component field of a log entry when concise caller information is sufficient.
If the caller's details cannot be retrieved, it returns a string indicating that the caller information could not be obtained.
func GetComponentCustom ¶ added in v1.15.12
func GetComponentCustom(skip int, includeFuncPath, includeFile, includeFilePath, includeLine bool) string
GetComponentCustom returns details about the caller function, including the function name, file, and line number.
This information is used to populate the component field of a log entry.
If the caller's details cannot be retrieved, it returns a string indicating that the caller information could not be obtained.
func GetComponentWithFile ¶
func GetComponentWithFile() string
GetComponentWithFile returns details about the caller function, including the function name, file name, and line number.
This information is used to populate the component field of a log entry when detailed caller information is required.
If the caller's details cannot be retrieved, it returns a string indicating that the caller information could not be obtained.
Types ¶
type GoogleLogEntry ¶ added in v1.15.12
type GoogleLogEntry struct { Message string `json:"message"` Trace string `json:"logging.googleapis.com/trace,omitempty"` Component string `json:"component,omitempty"` }
GoogleLogEntry represents a log entry for Google's logging service.
It includes a message, trace, and component information.
type Logger ¶ added in v1.15.12
type Logger struct {
// contains filtered or unexported fields
}
func (*Logger) Debug ¶ added in v1.15.12
func (l *Logger) Debug(entry GoogleLogEntry)
Error logs an error message with the specified component and trace.
func (*Logger) Error ¶ added in v1.15.12
func (l *Logger) Error(entry GoogleLogEntry)
Error logs an error message with the specified component and trace.
func (*Logger) Info ¶ added in v1.15.12
func (l *Logger) Info(entry GoogleLogEntry)
Info logs an info message with the specified component and trace.
func (*Logger) JSONLog ¶ added in v1.15.12
func (l *Logger) JSONLog(ctx context.Context, level LogLevel, data interface{}, emoji string, messages ...string)
JSONLog logs a structured message with the specified level, emoji & messages, in a structured way following Google Cloud's logging guidelines.
The data parameter is expected to be a struct or map that can be marshaled into JSON.
Message field will be populated with the indent JSON string of the data.
If the data is nil, the message field will be populated with a message indicating that the data is nil.
If the data cannot be indented into a JSON string, the message field will be populated with a message indicating that the data could not be indented.
Trace is retrieved from the context using the logger's trace key.
func (*Logger) Log ¶ added in v1.15.12
Log logs a message with the specified level & component.
Trace is retrieved from the context using the logger's trace key.
func (*Logger) SLog ¶ added in v1.15.12
SLog logs a structured message with the specified level, emoji & messages, in a structured way following Google Cloud's logging guidelines.
Trace is retrieved from the context using the logger's trace key.
func (*Logger) Warn ¶ added in v1.15.12
func (l *Logger) Warn(entry GoogleLogEntry)
Warn logs a warning message with the specified component and trace.
type LoggerPort ¶ added in v1.15.12
type LoggerPort interface { Info(entry GoogleLogEntry) Error(entry GoogleLogEntry) Debug(entry GoogleLogEntry) Warn(entry GoogleLogEntry) Log(ctx context.Context, level LogLevel, message, component string) SLog(ctx context.Context, level LogLevel, emoji string, messages ...string) JSONLog(ctx context.Context, level LogLevel, data interface{}, emoji string, message ...string) }