refactor: Refactor logging and profile handling functionalities

- Refactored variable declarations in log package for improved readability and consistency
- Removed redundant code and unnecessary parentheses in logger_test.go
- Simplified variable assignment in logger.go for better code maintainability
This commit is contained in:
moonD4rk 2024-11-24 00:35:40 +08:00
parent 28280220d1
commit faf988d1c1
No known key found for this signature in database
5 changed files with 33 additions and 42 deletions

View File

@ -4,10 +4,8 @@ import (
"github.com/moond4rk/hackbrowserdata/log/level"
)
var (
// defaultLogger is the default logger used by the package-level functions.
defaultLogger = NewLogger(nil)
)
// defaultLogger is the default logger used by the package-level functions.
var defaultLogger = NewLogger(nil)
func SetVerbose() {
defaultLogger.SetLevel(level.DebugLevel)

View File

@ -136,7 +136,7 @@ func (l *baseLogger) prefixPrint(prefix string, args ...any) {
}
func (l *baseLogger) getCallDepth() int {
var defaultCallDepth = 2
defaultCallDepth := 2
pcs := make([]uintptr, 10)
n := runtime.Callers(defaultCallDepth, pcs)
frames := runtime.CallersFrames(pcs[:n])

View File

@ -22,20 +22,18 @@ type baseTestCase struct {
wantedPattern string
}
var (
baseTestCases = []baseTestCase{
{
description: "without trailing newline, logger adds newline",
message: "hello, hacker!",
suffix: "",
},
{
description: "with trailing newline, logger preserves newline",
message: "hello, hacker!",
suffix: "\n",
},
}
)
var baseTestCases = []baseTestCase{
{
description: "without trailing newline, logger adds newline",
message: "hello, hacker!",
suffix: "",
},
{
description: "with trailing newline, logger preserves newline",
message: "hello, hacker!",
suffix: "\n",
},
}
func TestLoggerDebug(t *testing.T) {
for _, tc := range baseTestCases {
@ -121,25 +119,23 @@ type formatTestCase struct {
wantedPattern string
}
var (
formatTestCases = []formatTestCase{
{
description: "message with format prefix",
format: "hello, %s!",
args: []any{"Hacker"},
},
{
description: "message with format prefix",
format: "hello, %d,%d,%d!",
args: []any{1, 2, 3},
},
{
description: "message with format prefix",
format: "hello, %s,%d,%d!",
args: []any{"Hacker", 2, 3},
},
}
)
var formatTestCases = []formatTestCase{
{
description: "message with format prefix",
format: "hello, %s!",
args: []any{"Hacker"},
},
{
description: "message with format prefix",
format: "hello, %d,%d,%d!",
args: []any{1, 2, 3},
},
{
description: "message with format prefix",
format: "hello, %s,%d,%d!",
args: []any{"Hacker", 2, 3},
},
}
func TestLoggerDebugf(t *testing.T) {
for _, tc := range formatTestCases {

View File

@ -41,9 +41,7 @@ func (m *Finder) FindProfiles(rootPath string, browserType types2.BrowserType, d
return profiles, nil
}
var (
defaultExcludeDirs = []string{"Snapshot", "System Profile", "Crash Reports", "def"}
)
var defaultExcludeDirs = []string{"Snapshot", "System Profile", "Crash Reports", "def"}
func (m *Finder) findChromiumProfiles(rootPath string, browserType types2.BrowserType, dataTypes []types2.DataType) (Profiles, error) {
profiles := NewProfiles()

View File

@ -138,5 +138,4 @@ func Test_extractProfileNameFromPath(t *testing.T) {
}
})
}
}