5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-16 17:09:28 +08:00
wails/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/runtime/log.mdx
github-actions[bot] 4cd873fecb
docs: sync documents (#2443)
Co-authored-by: misitebao <misitebao@users.noreply.github.com>
2023-03-11 17:57:56 +11:00

131 lines
3.6 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
sidebar_position: 3
---
# Log 日志
Wails 运行时提供了一种可以从 Go 或 JavaScript 调用日志记录的机制。 像大多数记录器一样,有许多日志级别:
- Trace追踪
- Debug调试
- Info信息
- Warning警告
- Error错误
- Fatal致命
记录器将输出当前或更高日志级别的任何日志消息。 示例:`Debug`日志级别将输出除`Trace`消息之外的所有消息。
### LogPrint Print 日志
将给定的消息记录为原始消息。
Go: `LogPrint(ctx context.Context, message string)`<br/> JS: `LogPrint(message: string)`
### LogPrintf 格式化 Print 日志
将给定的消息记录为原始消息。
Go: `LogPrintf(ctx context.Context, format string, args ...interface{})`<br/>
### LogTrace Trace 日志
在 `Trace` 日志级别记录给定的消息。
Go: `LogTrace(ctx context.Context, message string)`<br/> JS: `LogTrace(message: string)`
### LogTracef 格式化 Trace 日志
在 `Trace` 日志级别记录给定的消息。
Go: `LogTracef(ctx context.Context, format string, args ...interface{})`<br/>
### LogDebug Debug 日志
在 `Debug` 日志级别记录给定的消息。
Go: `LogDebug(ctx context.Context, message string)`<br/> JS: `LogDebug(message: string)`
### LogDebugf 格式化 Debug 日志
在 `Debug` 日志级别记录给定的消息。
Go: `LogDebugf(ctx context.Context, format string, args ...interface{})`<br/>
### LogInfo Info 日志
在`Info`日志级别记录给定的消息。
Go: `LogInfo(ctx context.Context, message string)`<br/> JS: `LogInfo(message: string)`
### LogInfof 格式化 Info 日志
在`Info`日志级别记录给定的消息。
Go: `LogInfof(ctx context.Context, format string, args ...interface{})`<br/>
### LogWarning Warning 日志
在 `Warning` 日志级别记录给定的消息。
Go: `LogWarning(ctx context.Context, message string)`<br/> JS: `LogWarning(message: string)`
### LogWarningf 格式化 Warning 日志
在 `Warning` 日志级别记录给定的消息。
Go: `LogWarningf(ctx context.Context, format string, args ...interface{})`<br/>
### LogError Error 日志
在 `Error` 日志级别记录给定的消息。
Go: `LogError(ctx context.Context, message string)`<br/> JS: `LogError(message: string)`
### LogErrorf 格式化 Error 日志
在 `Error` 日志级别记录给定的消息。
Go: `LogErrorf(ctx context.Context, format string, args ...interface{})`<br/>
### LogFatal Fatal 日志
在 `Fatal` 日志级别记录给定的消息。
Go: `LogFatal(ctx context.Context, message string)`<br/> JS: `LogFatal(message: string)`
### LogFatalf 格式化 Fatal 日志
在 `Fatal` 日志级别记录给定的消息。
Go: `LogFatalf(ctx context.Context, format string, args ...interface{})`<br/>
### LogSetLogLevel 设置日志级别
设置日志级别。 在 JavaScript 中,该数字与以下日志级别有关:
| 值 | 日志等级 |
| - | ----------- |
| 1 | Trace追踪 |
| 2 | Debug调试 |
| 3 | Info信息 |
| 4 | Warning警告 |
| 5 | Error错误 |
Go: `LogSetLogLevel(ctx context.Context, level logger.LogLevel)`<br/> JS: `LogSetLogLevel(level: number)`
## 使用自定义日志
可以通过使用应用程序参数选项 [日志](../../reference/options#日志) 提供自定义记录器来使用它。 唯一的要求是记录器实现在 `github.com/wailsapp/wails/v2/pkg/logger` 里 `logger.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)
}
```