Skip to main content
Version: v2.3.1

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:

ValueLog Level
1Trace
2Debug
3Info
4Warning
5Error

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:

logger.go
type Logger interface {
Print(message string)
Trace(message string)
Debug(message string)
Info(message string)
Warning(message string)
Error(message string)
Fatal(message string)
}