Skip to content

Commit

Permalink
refactor: logus is better package name
Browse files Browse the repository at this point in the history
  • Loading branch information
dd84ai committed Feb 11, 2024
1 parent dfaa50a commit 02b5084
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 37 deletions.
8 changes: 4 additions & 4 deletions goutils/utils/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
Expand All @@ -51,15 +51,15 @@ 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)
}

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 {
Expand Down
4 changes: 2 additions & 2 deletions goutils/utils/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
}

Expand Down
6 changes: 3 additions & 3 deletions goutils/utils/regex.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ 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"
)

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()))
}
6 changes: 3 additions & 3 deletions goutils/utils/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand All @@ -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")
}
4 changes: 2 additions & 2 deletions goutils/utils/sleep.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions goutils/utils/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand All @@ -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
}
4 changes: 2 additions & 2 deletions goutils/utils/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions goutils/utils/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package utils_logger
package utils_logus

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package worker_logger
package worker_logus

import (
"log/slog"
Expand Down
16 changes: 8 additions & 8 deletions goutils/worker/worker_temp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand All @@ -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)
}

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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))
}
}
4 changes: 2 additions & 2 deletions goutils/worker/worker_tests/worker_persistent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions goutils/worker/worker_tests/worker_temp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
}

Expand All @@ -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 {
Expand Down

0 comments on commit 02b5084

Please sign in to comment.