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