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)
}