Log
The Wails runtime provides a logging mechanism that may be called from Go or Javascript. Like most loggers, there are a number of log levels:
- Trace
- Debug
- Info
- Warning
- Error
- Fatal
The logger will output any log message at the current, or higher, log level. Example: The Debug
log level will output all messages except Trace
messages.
LogPrint
Logs the given message as a raw message.
Go: LogPrint(ctx context.Context, message string)
JS: LogPrint(message: string)
LogPrintf
Logs the given message as a raw message.
Go: LogPrintf(ctx context.Context, format string, args ...interface{})
LogTrace
Logs the given message at the Trace
log level.
Go: LogTrace(ctx context.Context, message string)
JS: LogTrace(message: string)
LogTracef
Logs the given message at the Trace
log level.
Go: LogTracef(ctx context.Context, format string, args ...interface{})
LogDebug
Logs the given message at the Debug
log level.
Go: LogDebug(ctx context.Context, message string)
JS: LogDebug(message: string)
LogDebugf
Logs the given message at the Debug
log level.
Go: LogDebugf(ctx context.Context, format string, args ...interface{})
LogInfo
Logs the given message at the Info
log level.
Go: LogInfo(ctx context.Context, message string)
JS: LogInfo(message: string)
LogInfof
Logs the given message at the Info
log level.
Go: LogInfof(ctx context.Context, format string, args ...interface{})
LogWarning
Logs the given message at the Warning
log level.
Go: LogWarning(ctx context.Context, message string)
JS: LogWarning(message: string)
LogWarningf
Logs the given message at the Warning
log level.
Go: LogWarningf(ctx context.Context, format string, args ...interface{})
LogError
Logs the given message at the Error
log level.
Go: LogError(ctx context.Context, message string)
JS: LogError(message: string)
LogErrorf
Logs the given message at the Error
log level.
Go: LogErrorf(ctx context.Context, format string, args ...interface{})
LogFatal
Logs the given message at the Fatal
log level.
Go: LogFatal(ctx context.Context, message string)
JS: LogFatal(message: string)
LogFatalf
Logs the given message at the Fatal
log level.
Go: LogFatalf(ctx context.Context, format string, args ...interface{})
LogSetLogLevel
Sets the log level. In Javascript, the number relates to the following log levels:
Value | Log Level |
---|---|
1 | Trace |
2 | Debug |
3 | Info |
4 | Warning |
5 | Error |
Go: LogSetLogLevel(ctx context.Context, level logger.LogLevel)
JS: LogSetLogLevel(level: number)
Using a Custom Logger
A custom logger may be used by providing it using the Logger application option. The only requirement is that the logger implements the logger.Logger
interface defined in github.com/wailsapp/wails/v2/pkg/logger
:
type Logger interface {
Print(message string)
Trace(message string)
Debug(message string)
Info(message string)
Warning(message string)
Error(message string)
Fatal(message string)
}