dl icon indicating copy to clipboard operation
dl copied to clipboard

The logger not committed to Git for debug

dl - The logger not committed to Git for debug

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

delog.gif

Description

Who doesn't write wrong codes? No one.
Then, programs don't work well, and developers write logs for debug 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.

Features

Installation

Go 1.17 or earlier

It doesn't contain a generics feature.

$ go install github.com/task4233/dl/cmd/dl@v1

Go 1.18

$ go install github.com/task4233/dl/v2/cmd/dl@main

Usage

  1. debug your codes with dl package

Playground

package main

import (
	"os"

	"github.com/task4233/dl/v2"
)

type U[T any] []T

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

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

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


// Output:
// [DeLog] info: main.U[int]{1, 3, 5} (main.U[int]) prog.go:13
// [DeLog] info: main.U[int]{5, 3} (main.U[int]) prog.go:18
  1. Install dl
$ dl init .
  1. Just commit
  • delog is used in the file.
$ cat main.go 
package main

import (
	"os"

	"github.com/task4233/dl/v2"
)

type U[T any] []T

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

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

func main() {
	t := U[int]([]int{1, 3})
	t.append(5)
	t.change(5)
}
  • 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
@@ -0,0 +1,27 @@
+package main
+
+import (
+       "os"
+
+       "github.com/task4233/dl/v2"
+)
+
+type U[T any] []T
+
+func (t U[T]) append(v T) {
+       t = append(t, v)
+       // debug
+
+}
+
+func (t U[T]) change(v T) {
+       t[0] = v
+       // debug
+
+}
+
+func main() {
+       t := U[int]([]int{1, 3})
+       t.append(5)
+       t.change(5)
+}
  • removed delog codes are restored(not commited)
$ cat main.go 
package main

import (
	"os"

	"github.com/task4233/dl/v2"
)

type U[T any] []T

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

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

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

Remove dl from GitHooks

$ dl remove .

Contribution

Please feel free to make issues and pull requests.

Author

task4233