mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 02:30:48 +08:00

* docs: update changelog * feat: update website config * feat(website): add formatting configuration * docs: fix image resource paths and format documents * feat(website): update community guide page Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
153 lines
3.4 KiB
Plaintext
153 lines
3.4 KiB
Plaintext
---
|
|
sidebar_position: 3
|
|
---
|
|
|
|
# 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:
|
|
|
|
| Value | Log Level |
|
|
| ----- | --------- |
|
|
| 1 | Trace |
|
|
| 2 | Debug |
|
|
| 3 | Info |
|
|
| 4 | Warning |
|
|
| 5 | Error |
|
|
|
|
## Using a Custom Logger
|
|
|
|
A custom logger may be used by providing it using the [Logger](../options.mdx#logger)
|
|
application option. The only requirement is that the logger implements the `logger.Logger` interface
|
|
defined in `github.com/wailsapp/wails/v2/pkg/logger`:
|
|
|
|
```go title="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)
|
|
}
|
|
```
|