5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-03 06:01:52 +08:00

Feature: Go logger "f" equivalents

This commit is contained in:
Lea Anthony 2022-04-01 12:27:40 +11:00
parent 073f8202e5
commit 7af39e4819
2 changed files with 89 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package runtime
import (
"context"
"fmt"
"github.com/wailsapp/wails/v2/pkg/logger"
)
@ -47,6 +48,55 @@ func LogFatal(ctx context.Context, message string) {
myLogger.Fatal(message)
}
// LogPrintf prints a Print level message
func LogPrintf(ctx context.Context, format string, args ...interface{}) {
msg := fmt.Sprintf(format, args...)
myLogger := getLogger(ctx)
myLogger.Print(msg)
}
// LogTracef prints a Trace level message
func LogTracef(ctx context.Context, format string, args ...interface{}) {
msg := fmt.Sprintf(format, args...)
myLogger := getLogger(ctx)
myLogger.Trace(msg)
}
// LogDebugf prints a Debug level message
func LogDebugf(ctx context.Context, format string, args ...interface{}) {
msg := fmt.Sprintf(format, args...)
myLogger := getLogger(ctx)
myLogger.Debug(msg)
}
// LogInfof prints a Info level message
func LogInfof(ctx context.Context, format string, args ...interface{}) {
msg := fmt.Sprintf(format, args...)
myLogger := getLogger(ctx)
myLogger.Info(msg)
}
// LogWarningf prints a Warning level message
func LogWarningf(ctx context.Context, format string, args ...interface{}) {
msg := fmt.Sprintf(format, args...)
myLogger := getLogger(ctx)
myLogger.Warning(msg)
}
// LogErrorf prints a Error level message
func LogErrorf(ctx context.Context, format string, args ...interface{}) {
msg := fmt.Sprintf(format, args...)
myLogger := getLogger(ctx)
myLogger.Error(msg)
}
// LogFatalf prints a Fatal level message
func LogFatalf(ctx context.Context, format string, args ...interface{}) {
msg := fmt.Sprintf(format, args...)
myLogger := getLogger(ctx)
myLogger.Fatal(msg)
}
// LogSetLogLevel sets the log level
func LogSetLogLevel(ctx context.Context, level logger.LogLevel) {
myLogger := getLogger(ctx)

View File

@ -27,6 +27,12 @@ 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)`
@ -35,6 +41,12 @@ 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)`
@ -43,6 +55,11 @@ 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
@ -52,6 +69,11 @@ 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
@ -61,6 +83,11 @@ 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
@ -70,14 +97,26 @@ 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)`