From 02b5084b4aa6fb538e4617e5d9bb0f9a16c11f10 Mon Sep 17 00:00:00 2001 From: dd84ai Date: Sun, 11 Feb 2024 14:23:59 +0100 Subject: [PATCH] refactor: logus is better package name --- goutils/utils/file.go | 8 ++++---- goutils/utils/os.go | 4 ++-- goutils/utils/regex.go | 6 +++--- goutils/utils/shell.go | 6 +++--- goutils/utils/sleep.go | 4 ++-- goutils/utils/template.go | 6 +++--- goutils/utils/tests.go | 4 ++-- goutils/utils/time.go | 4 ++-- .../utils/{utils_logger => utils_logus}/logus.go | 2 +- .../{worker_logger => worker_logus}/logus.go | 2 +- goutils/worker/worker_temp.go | 16 ++++++++-------- .../worker_tests/worker_persistent_test.go | 4 ++-- goutils/worker/worker_tests/worker_temp_test.go | 8 ++++---- 13 files changed, 37 insertions(+), 37 deletions(-) rename goutils/utils/{utils_logger => utils_logus}/logus.go (96%) rename goutils/worker/{worker_logger => worker_logus}/logus.go (96%) diff --git a/goutils/utils/file.go b/goutils/utils/file.go index 35fb5e2..3a3e47d 100644 --- a/goutils/utils/file.go +++ b/goutils/utils/file.go @@ -5,7 +5,7 @@ import ( "fmt" "os" - "github.com/darklab8/darklab_goutils/goutils/utils/utils_logger" + "github.com/darklab8/darklab_goutils/goutils/utils/utils_logus" "github.com/darklab8/darklab_goutils/goutils/utils/utils_types" ) @@ -26,7 +26,7 @@ func NewReadFile(filepath utils_types.FilePath, callback func(*FileRead)) { file, err := os.Open(string(f.filepath)) f.file.file = file - utils_logger.Log.CheckFatal(err, "failed to open", utils_logger.FilePath(f.filepath)) + utils_logus.Log.CheckFatal(err, "failed to open", utils_logus.FilePath(f.filepath)) defer f.file.file.Close() callback(f) @@ -51,7 +51,7 @@ func NewWriteFile(filepath utils_types.FilePath, callback func(*FileWrite)) { file, err := os.Create(string(f.filepath)) f.file.file = file - utils_logger.Log.CheckFatal(err, "failed to open ", utils_logger.FilePath(f.filepath)) + utils_logus.Log.CheckFatal(err, "failed to open ", utils_logus.FilePath(f.filepath)) defer f.file.file.Close() callback(f) } @@ -59,7 +59,7 @@ func NewWriteFile(filepath utils_types.FilePath, callback func(*FileWrite)) { func (f *FileWrite) WritelnF(msg string) { _, err := f.file.file.WriteString(fmt.Sprintf("%v\n", msg)) - utils_logger.Log.CheckFatal(err, "failed to write string to file") + utils_logus.Log.CheckFatal(err, "failed to write string to file") } func FileExists(filename utils_types.FilePath) bool { diff --git a/goutils/utils/os.go b/goutils/utils/os.go index a5b8a12..9b0d416 100644 --- a/goutils/utils/os.go +++ b/goutils/utils/os.go @@ -5,7 +5,7 @@ import ( "path/filepath" "runtime" - "github.com/darklab8/darklab_goutils/goutils/utils/utils_logger" + "github.com/darklab8/darklab_goutils/goutils/utils/utils_logus" "github.com/darklab8/darklab_goutils/goutils/utils/utils_types" ) @@ -25,7 +25,7 @@ func GetProjectDir() utils_types.FilePath { if folder_override, ok := os.LookupEnv("AUTOGIT_PROJECT_FOLDER"); ok { path = folder_override } - utils_logger.Log.CheckFatal(err, "unable to get workdir") + utils_logus.Log.CheckFatal(err, "unable to get workdir") return utils_types.FilePath(path) } diff --git a/goutils/utils/regex.go b/goutils/utils/regex.go index c29072a..68f34b9 100644 --- a/goutils/utils/regex.go +++ b/goutils/utils/regex.go @@ -3,7 +3,7 @@ package utils import ( "regexp" - "github.com/darklab8/darklab_goutils/goutils/utils/utils_logger" + "github.com/darklab8/darklab_goutils/goutils/utils/utils_logus" "github.com/darklab8/darklab_goutils/goutils/utils/utils_types" ) @@ -11,6 +11,6 @@ func InitRegexExpression(regex **regexp.Regexp, expression utils_types.RegExp) { var err error *regex, err = regexp.Compile(string(expression)) - utils_logger.Log.CheckFatal(err, "failed to init regex", - utils_logger.Regex(expression), utils_logger.FilePath(GetCurrentFile())) + utils_logus.Log.CheckFatal(err, "failed to init regex", + utils_logus.Regex(expression), utils_logus.FilePath(GetCurrentFile())) } diff --git a/goutils/utils/shell.go b/goutils/utils/shell.go index 160b473..9a34885 100644 --- a/goutils/utils/shell.go +++ b/goutils/utils/shell.go @@ -5,12 +5,12 @@ import ( "os" "os/exec" - "github.com/darklab8/darklab_goutils/goutils/utils/utils_logger" + "github.com/darklab8/darklab_goutils/goutils/utils/utils_logus" "github.com/darklab8/go-typelog/typelog" ) func ShellRunArgs(program string, args ...string) { - utils_logger.Log.Debug(fmt.Sprintf("OK attempting to run: %s", program), typelog.Args(args)) + utils_logus.Log.Debug(fmt.Sprintf("OK attempting to run: %s", program), typelog.Args(args)) executable, _ := exec.LookPath(program) args = append([]string{""}, args...) @@ -22,5 +22,5 @@ func ShellRunArgs(program string, args ...string) { } err := command.Run() - utils_logger.Log.CheckFatal(err, "failed to run shell command") + utils_logus.Log.CheckFatal(err, "failed to run shell command") } diff --git a/goutils/utils/sleep.go b/goutils/utils/sleep.go index e901ed7..4fee09a 100644 --- a/goutils/utils/sleep.go +++ b/goutils/utils/sleep.go @@ -6,7 +6,7 @@ import ( "sync" "syscall" - "github.com/darklab8/darklab_goutils/goutils/utils/utils_logger" + "github.com/darklab8/darklab_goutils/goutils/utils/utils_logus" ) func SleepAwaitCtrlC() { @@ -16,7 +16,7 @@ func SleepAwaitCtrlC() { } func SleepForever() { - utils_logger.Log.Debug("awaiting smth forever in SleepForever") + utils_logus.Log.Debug("awaiting smth forever in SleepForever") mu := sync.Mutex{} mu.Lock() mu.Lock() diff --git a/goutils/utils/template.go b/goutils/utils/template.go index 2d25cdf..36c665c 100644 --- a/goutils/utils/template.go +++ b/goutils/utils/template.go @@ -5,14 +5,14 @@ import ( "strings" "text/template" - "github.com/darklab8/darklab_goutils/goutils/utils/utils_logger" + "github.com/darklab8/darklab_goutils/goutils/utils/utils_logus" "github.com/darklab8/darklab_goutils/goutils/utils/utils_types" ) func TmpRender(templateRef *template.Template, data interface{}) string { header := bytes.Buffer{} err := templateRef.Execute(&header, data) - utils_logger.Log.CheckFatal(err, "failed to render template") + utils_logus.Log.CheckFatal(err, "failed to render template") return header.String() } @@ -24,6 +24,6 @@ func TmpInit(content utils_types.TemplateExpression) *template.Template { var err error templateRef, err := template.New("test").Funcs(funcs).Parse(string(content)) - utils_logger.Log.CheckFatal(err, "failed to init template") + utils_logus.Log.CheckFatal(err, "failed to init template") return templateRef } diff --git a/goutils/utils/tests.go b/goutils/utils/tests.go index 0618678..6dbc9c6 100644 --- a/goutils/utils/tests.go +++ b/goutils/utils/tests.go @@ -3,12 +3,12 @@ package utils import ( "os" - "github.com/darklab8/darklab_goutils/goutils/utils/utils_logger" + "github.com/darklab8/darklab_goutils/goutils/utils/utils_logus" ) func RegenerativeTest(callback func() error) error { if os.Getenv("DARK_TEST_REGENERATE") != "true" { - utils_logger.Log.Debug("Skipping test data regenerative code") + utils_logus.Log.Debug("Skipping test data regenerative code") return nil } diff --git a/goutils/utils/time.go b/goutils/utils/time.go index 89ff640..2318a85 100644 --- a/goutils/utils/time.go +++ b/goutils/utils/time.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "github.com/darklab8/darklab_goutils/goutils/utils/utils_logger" + "github.com/darklab8/darklab_goutils/goutils/utils/utils_logus" "github.com/darklab8/go-typelog/typelog" ) @@ -23,7 +23,7 @@ func NewTimeMeasure(msg string, ops ...typelog.LogType) *timeMeasurer { } func (t *timeMeasurer) Close() { - utils_logger.Log.Debug(fmt.Sprintf("time_measure %v | %s", time.Since(t.time_started), t.msg), t.ops...) + utils_logus.Log.Debug(fmt.Sprintf("time_measure %v | %s", time.Since(t.time_started), t.msg), t.ops...) } func TimeMeasure(callback func(), msg string, ops ...typelog.LogType) { diff --git a/goutils/utils/utils_logger/logus.go b/goutils/utils/utils_logus/logus.go similarity index 96% rename from goutils/utils/utils_logger/logus.go rename to goutils/utils/utils_logus/logus.go index 633f473..a58cfdf 100644 --- a/goutils/utils/utils_logger/logus.go +++ b/goutils/utils/utils_logus/logus.go @@ -1,4 +1,4 @@ -package utils_logger +package utils_logus import ( "fmt" diff --git a/goutils/worker/worker_logger/logus.go b/goutils/worker/worker_logus/logus.go similarity index 96% rename from goutils/worker/worker_logger/logus.go rename to goutils/worker/worker_logus/logus.go index 15faf34..e987d47 100644 --- a/goutils/worker/worker_logger/logus.go +++ b/goutils/worker/worker_logus/logus.go @@ -1,4 +1,4 @@ -package worker_logger +package worker_logus import ( "log/slog" diff --git a/goutils/worker/worker_temp.go b/goutils/worker/worker_temp.go index 38350fb..c13b7d6 100644 --- a/goutils/worker/worker_temp.go +++ b/goutils/worker/worker_temp.go @@ -4,7 +4,7 @@ import ( "errors" "time" - "github.com/darklab8/darklab_goutils/goutils/worker/worker_logger" + "github.com/darklab8/darklab_goutils/goutils/worker/worker_logus" "github.com/darklab8/darklab_goutils/goutils/worker/worker_types" ) @@ -97,7 +97,7 @@ func NewTaskPool(opts ...TaskPoolOption) *TaskPool { } func (j *TaskPool) launchWorker(worker_id worker_types.WorkerID, tasks <-chan ITask) { - worker_logger.Log.Info("worker started", worker_logger.WorkerID(worker_id)) + worker_logus.Log.Info("worker started", worker_logus.WorkerID(worker_id)) for task := range tasks { task_err := make(chan error, 1) @@ -111,9 +111,9 @@ func (j *TaskPool) launchWorker(worker_id worker_types.WorkerID, tasks <-chan IT // An alternative way to wait for multiple goroutines is to use a WaitGroup. case <-time.After(time.Duration(j.taskTimeout) * time.Second): task.setError(errors.New("timed out")) - worker_logger.Log.Error("finished tasks with timeout", worker_logger.StatusCode(CodeTimeout)) + worker_logus.Log.Error("finished tasks with timeout", worker_logus.StatusCode(CodeTimeout)) case task_err := <-task_err: - worker_logger.Log.CheckError(task_err, "finished tasks with timeout", worker_logger.StatusCode(CodeFailure)) + worker_logus.Log.CheckError(task_err, "finished tasks with timeout", worker_logus.StatusCode(CodeFailure)) task.setError(task_err) } @@ -122,7 +122,7 @@ func (j *TaskPool) launchWorker(worker_id worker_types.WorkerID, tasks <-chan IT task_observer(task) } } - worker_logger.Log.Info("worker finished", worker_logger.WorkerID(worker_id)) + worker_logus.Log.Info("worker finished", worker_logus.WorkerID(worker_id)) } /// Temporal @@ -167,7 +167,7 @@ func RunTasksInTempPool(tasks []ITask, opts ...TaskPoolOption) { } } else { runTasksinTemporalWorkers(tasks, taskPool) - worker_logger.Log.Debug("results", LogusStatusCodes(tasks)) + worker_logus.Log.Debug("results", LogusStatusCodes(tasks)) for _ = range tasks { finished_tasks = append(finished_tasks, <-result_channel) @@ -177,8 +177,8 @@ func RunTasksInTempPool(tasks []ITask, opts ...TaskPoolOption) { for task_number, task := range tasks { task_id := worker_types.TaskID(task_number) if !task.IsDone() && !taskPool.allow_failed_tasks { - worker_logger.Log.Error("task failed", worker_logger.TaskID(task_id)) + worker_logus.Log.Error("task failed", worker_logus.TaskID(task_id)) } - worker_logger.Log.Debug("task succeed", worker_logger.TaskID(task_id)) + worker_logus.Log.Debug("task succeed", worker_logus.TaskID(task_id)) } } diff --git a/goutils/worker/worker_tests/worker_persistent_test.go b/goutils/worker/worker_tests/worker_persistent_test.go index da17afa..65daed4 100644 --- a/goutils/worker/worker_tests/worker_persistent_test.go +++ b/goutils/worker/worker_tests/worker_persistent_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/darklab8/darklab_goutils/goutils/worker" - "github.com/darklab8/darklab_goutils/goutils/worker/worker_logger" + "github.com/darklab8/darklab_goutils/goutils/worker/worker_logus" "github.com/darklab8/darklab_goutils/goutils/worker/worker_types" "github.com/stretchr/testify/assert" @@ -40,7 +40,7 @@ func TestWorkerPersistent(t *testing.T) { done_count := 0 failed_count := 0 for task_number, task := range tasks { - worker_logger.Log.Debug(fmt.Sprintf("task.Done=%t", task.IsDone()), worker_logger.TaskID(worker_types.TaskID(task_number)), TaskResult(task.result)) + worker_logus.Log.Debug(fmt.Sprintf("task.Done=%t", task.IsDone()), worker_logus.TaskID(worker_types.TaskID(task_number)), TaskResult(task.result)) if task.IsDone() { done_count += 1 } else { diff --git a/goutils/worker/worker_tests/worker_temp_test.go b/goutils/worker/worker_tests/worker_temp_test.go index 0d07d83..4309d71 100644 --- a/goutils/worker/worker_tests/worker_temp_test.go +++ b/goutils/worker/worker_tests/worker_temp_test.go @@ -7,7 +7,7 @@ import ( "time" "github.com/darklab8/darklab_goutils/goutils/worker" - "github.com/darklab8/darklab_goutils/goutils/worker/worker_logger" + "github.com/darklab8/darklab_goutils/goutils/worker/worker_logus" "github.com/darklab8/darklab_goutils/goutils/worker/worker_types" "github.com/darklab8/go-typelog/typelog" @@ -29,10 +29,10 @@ func NewTaskTest(id worker_types.TaskID) *TaskTest { } func (data *TaskTest) RunTask(worker_id worker_types.WorkerID) error { - worker_logger.Log.Debug("task test started", worker_logger.WorkerID(worker_id), worker_logger.TaskID(data.GetID())) + worker_logus.Log.Debug("task test started", worker_logus.WorkerID(worker_id), worker_logus.TaskID(data.GetID())) time.Sleep(time.Second * time.Duration(data.GetID())) data.result = data.GetID() * 1 - worker_logger.Log.Debug("task test finished", worker_logger.WorkerID(worker_id), worker_logger.TaskID(data.GetID())) + worker_logus.Log.Debug("task test finished", worker_logus.WorkerID(worker_id), worker_logus.TaskID(data.GetID())) return nil } @@ -57,7 +57,7 @@ func TestWorkerTemp(t *testing.T) { done_count := 0 failed_count := 0 for task_number, task := range tasks { - worker_logger.Log.Debug(fmt.Sprintf("task.Done=%t", task.IsDone()), worker_logger.TaskID(worker_types.TaskID(task_number))) + worker_logus.Log.Debug(fmt.Sprintf("task.Done=%t", task.IsDone()), worker_logus.TaskID(worker_types.TaskID(task_number))) if task.IsDone() { done_count += 1 } else {