dl(Debug x Log) – The instant logger package for debug

Go Reference .github/workflows/ci.yml Go Report Card codecov MIT License

Description

Who doesn’t write wrong codes? No one. Then, programs don’t work well, and developers write logs for debugging to understand what happens.

However, some developers forget to delete their logs after resolving the problem and push their codes. In the worse case, the logs might be released.

dl is developed to resolve their problems.

Moreover, dl provides utility logging functions which focus on debugging.

Features

  • Logging package for debug in Go
  • Command for Sweeping all functions of this package
  • Command for installing git pre-commit hook

Installation

Go1.18

$ go install github.com/task4233/dl/cmd/[email protected]

Use Case

Debug

Playground

package main

import (
	"os"

	"github.com/task4233/dl"
)

type T[T1 any] []T1

func (t T[T1]) append(v T1) {
	t = append(t, v)
	dl.Info(t)
}

func (t T[T1]) change(v T1) {
	t[0] = v
	dl.FInfo(os.Stdout, t)
}

func main() {
	t := T[int]([]int{1, 3})
	t.append(5)
	t.change(5)
}

// Output:
// [DeLog] info: main.T[int]{1, 3, 5} (main.T[int]) prog.go:13
// [DeLog] info: main.T[int]{5, 3} (main.T[int]) prog.go:18

Adds dl into pre-commit of Git

  1. Please run commands below to install dl in your Git repository.
dl init .
  1. Just commit
  • delog is used in the file.

$ cat main.go 
package main

import (
	"fmt"
	
	"github.com/task4233/dl"
)

func SayHi[T any](v T) {
	dl.Printf("Type: %T, v: %v\n", v, v) // This statement can be removed by `$ dl clean main.go`
	fmt.Println("Hi, ", v)
}

func main() {
    SayHi("hoge")
}
  • invoke $ git commit

$ git add main.go
$ git commit -m "feat: add main.go"
remove dl from main.go # automatically removed
[master 975ecf9] feat: add main.go
 1 file changed, 12 insertions(+), 21 deletions(-)
 rewrite main.go (91%)
  • delog is removed automatically

$ git diff HEAD^
diff --git a/main.go b/main.go
index 90a78bd..0e28e8a 100644
--- a/main.go
+++ b/main.go
@@ -1,21 +1,12 @@
 package main

+import (
+       "fmt"
+)
 
+func SayHi[T any](v T) {
+       fmt.Println("Hi, ", v)
+}

 func main() {
+       SayHi("hoge")
 }

Contribution

Please feel free to make issues and pull requests.

Author

task4233

GitHub

View Github