Skip to main content
Version: v2.0.0-beta.44

Log

Overview

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

Go Signature: LogPrint(ctx context.Context, message string)

JS Signature: LogPrint(message: string)

Logs the given message as a raw message.

LogPrintf

Go Signature: LogPrintf(ctx context.Context, format string, args ...interface{})

Logs the given message as a raw message.

LogTrace

Go Signature: LogTrace(ctx context.Context, message string)

JS Signature: LogTrace(message: string)

Logs the given message at the Trace log level.

LogTracef

Go Signature: LogTracef(ctx context.Context, format string, args ...interface{})

Logs the given message at the Trace log level.

LogDebug

Go Signature: LogDebug(ctx context.Context, message string)

JS Signature: LogDebug(message: string)

Logs the given message at the Debug log level.

LogDebugf

Go Signature: LogDebugf(ctx context.Context, format string, args ...interface{})

Logs the given message at the Debug log level.

LogInfo

Go Signature: LogInfo(ctx context.Context, message string)

JS Signature: LogInfo(message: string)

Logs the given message at the Info log level.

LogInfof

Go Signature: LogInfof(ctx context.Context, format string, args ...interface{})

Logs the given message at the Info log level.

LogWarning

Go Signature: LogWarning(ctx context.Context, message string)

JS Signature: LogWarning(message: string)

Logs the given message at the Warning log level.

LogWarningf

Go Signature: LogWarningf(ctx context.Context, format string, args ...interface{})

Logs the given message at the Warning log level.

LogError

Go Signature: LogError(ctx context.Context, message string)

JS Signature: LogError(message: string)

Logs the given message at the Error log level.

LogErrorf

Go Signature: LogErrorf(ctx context.Context, format string, args ...interface{})

Logs the given message at the Error log level.

LogFatal

Go Signature: LogFatal(ctx context.Context, message string)

JS Signature: LogFatal(message: string)

Logs the given message at the Fatal log level.

LogFatalf

Go Signature: LogFatalf(ctx context.Context, format string, args ...interface{})

Logs the given message at the Fatal log level.

LogSetLogLevel

Go Signature: LogSetLogLevel(ctx context.Context, level logger.LogLevel)

JS Signature: LogSetLogLevel(level: number)

Sets the log level. In Javascript, the number relates to the following log levels:

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

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