mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-05-19 18:58:03 +02:00
e48f35cfd3
* refactor: Refactor logging to use structured slog package. - Remove `gookit` dependencies from `go.sum` - Improve error logging in multiple packages by replacing `log` with `log/slog` - Update dependencies in `go.mod` - Add new `logger` package with test cases - Refactor logging statements in multiple packages to use `slog` instead of `log` - Change logging format and level in multiple packages for better structured logging * refactor: Refactor logger package and add handler interface - Refactor logger package - Rename `defaultHandler` to `DefaultLogger` - Move `ReplaceAttr` function to `Logger` struct - Implement `LogHandler` struct with `slog.Handler` interface - Add new `Logger` methods for configuration - Add `SetMaxLevel`, `SetJSONHandler`, `SetTextHandler`, `SetOutput`, `SetVerbose`, `SetReplaceAttrFunc` - Add verbose flag to `cmd/hack-browser-data/main.go` to increase logging * refactor: Refactor logger package to use simplified handler initialization. - Refactor logger package to use Default instead of DefaultLogger - Update `NewHandler` method to correctly reference `Default` logger and simplify handler initialization - Update tests for logger to reflect changes in Default usage - Rename `DefaultLogger` to `Default` and update comments to better reflect its purpose - Update function calls in hack-browser-data main.go to reflect logger package updates * refactor: Refactor logging in Chromium implementation Refactor logging and simplify decryption in chromium files - Replace logger package import with shared slog package - Change logging messages to use slog instead of logger - Simplify decryption process by removing first 5 characters of encrypted key - Refactor error logging in linux file to use shared slog package - Replace string concatenation with formatted string in linux error message
69 lines
1.5 KiB
Go
69 lines
1.5 KiB
Go
package logger
|
|
|
|
import (
|
|
"bytes"
|
|
"log/slog"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestConfigure(t *testing.T) {
|
|
asserts := assert.New(t)
|
|
buf := new(bytes.Buffer)
|
|
|
|
opts := &Logger{
|
|
AddSource: true,
|
|
IsVerbose: false,
|
|
IsJSONHandler: true,
|
|
Output: buf,
|
|
}
|
|
Configure(opts)
|
|
|
|
slog.Warn("test message")
|
|
|
|
output := buf.String()
|
|
asserts.Contains(output, "test message", "Log output should contain the test message")
|
|
}
|
|
|
|
func TestSetVerbose(t *testing.T) {
|
|
asserts := assert.New(t)
|
|
buf := new(bytes.Buffer)
|
|
|
|
logger := Default.clone()
|
|
logger.SetVerbose()
|
|
logger.SetOutput(buf)
|
|
Configure(logger)
|
|
|
|
slog.Debug("verbose test")
|
|
|
|
output := buf.String()
|
|
asserts.Contains(output, "verbose test", "Verbose mode should enable debug level logs")
|
|
}
|
|
|
|
func TestLogger_SetJSONHandler(t *testing.T) {
|
|
asserts := assert.New(t)
|
|
|
|
logger := Default.clone()
|
|
logger.SetJSONHandler()
|
|
asserts.True(logger.IsJSONHandler, "IsJSONHandler should be true")
|
|
}
|
|
|
|
func TestOptionsClone(t *testing.T) {
|
|
asserts := assert.New(t)
|
|
|
|
original := &Logger{
|
|
AddSource: true,
|
|
IsVerbose: true,
|
|
IsJSONHandler: true,
|
|
Output: os.Stdout,
|
|
}
|
|
cloned := original.clone()
|
|
|
|
asserts.Equal(original.AddSource, cloned.AddSource, "AddSource should be equal")
|
|
asserts.Equal(original.IsVerbose, cloned.IsVerbose, "IsVerbose should be equal")
|
|
asserts.Equal(original.IsJSONHandler, cloned.IsJSONHandler, "IsJSONHandler should be equal")
|
|
asserts.Equal(original.Output, cloned.Output, "Output should be equal")
|
|
}
|