dl

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2022 License: MIT Imports: 20 Imported by: 0

README

NOTICE

If you use Go 1.18 or later, Please use github.com/task4233/dl/v2, not github.com/task4233/dl.

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/cmd/dl@main

Usage

  1. debug your codes with dl package

Playground

package main

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

type T []int

func (t T) append(v int) {
	t = append(t, v)
	dl.Printf("t: %#v, v: %d\n", t, v)
}

func (t T) change(v int) {
	t[0] = v
	dl.Printf("t: %#v, v: %d\n", t, v)
}

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

// Output:
// t: main.T{1, 3, 5}, v: 5
// t: main.T{5, 3}, v: 5
  1. Install dl
$ dl init .
  1. Just commit
  • delog is used in the file.
$ cat main.go 
package main

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

type T []int

func (t T) append(v int) {
	t = append(t, v)
	dl.Printf("t: %#v, v: %d\n", t, v)
}

func (t T) change(v int) {
	t[0] = v
	dl.Printf("t: %#v, v: %d\n", t, v)
}

func main() {
	var t T = []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 show HEAD
index 90a78bd..0e28e8a 100644
--- a/main.go
+++ b/main.go
@@ -1,21 +1,12 @@
package main

type T []int

func (t T) append(v int) {
	t = append(t, v)

}

func (t T) change(v int) {
	t[0] = v

}

func main() {
	var t T = []int{1, 3}
	t.append(5)
	t.change(5)
}
  • removed delog codes are restored(not commited)
$ cat main.go 
package main

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

type T []int

func (t T) append(v int) {
	t = append(t, v)
	dl.Printf("t: %#v, v: %d\n", t, v)
}

func (t T) change(v int) {
	t[0] = v
	dl.Printf("t: %#v, v: %d\n", t, v)
}

func main() {
	var t T = []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

Documentation

Overview

Example
package main

import (
	"fmt"
	"os"

	"github.com/go-logr/logr"
	"github.com/go-logr/zapr"
	"github.com/task4233/dl"
	"go.uber.org/zap"
)

func main() {
	num := 123
	name := "dl"

	dl.Fprintln(os.Stdout, "num: ", num)
	dl.Println("num: ", num)
	dl.Fprintf(os.Stdout, "name: %s\n", name)
	dl.Printf("name: %s", name)

	zapLog, err := zap.NewDevelopment()
	if err != nil {
		panic(fmt.Sprintf("who watches the watchmen (%v)?", err))
	}
	var log logr.Logger = zapr.NewLogger(zapLog)
	dlr := dl.NewLogger(&log)
	dlr.Info("Info: ", "num", num)

}
Output:

num:  123
name: dl

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fprintf

func Fprintf(w io.Writer, format string, v ...interface{}) (int, error)

Fprintf formats according to a format specifier and writes to w. Arguments are handled in the manner of fmt.FPrintf.

Example
package main

import (
	"os"

	"github.com/task4233/dl"
)

func main() {
	type person struct {
		name string
		age  int
	}
	alice := person{
		name: "alice",
		age:  15,
	}

	dl.Fprintf(os.Stdout, "name: %s", alice.name)
}
Output:

name: alice

func Fprintln

func Fprintln(w io.Writer, v ...interface{}) (int, error)

Fprintln formats using the default formats for its operands and writes to w. Spaces are always added between operands and a newline is appended. Arguments are handled in the manner of fmt.FPrintln.

Example
package main

import (
	"os"

	"github.com/task4233/dl"
)

func main() {
	type person struct {
		name string
		age  int
	}
	alice := person{
		name: "alice",
		age:  15,
	}

	dl.Fprintln(os.Stdout, "name:", alice.name)
}
Output:

name: alice

func Printf

func Printf(format string, v ...interface{}) (int, error)

Printf calls Fprintf to print to the standard logger. Arguments are handled in the manner of fmt.Printf.

Example
package main

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

func main() {
	type person struct {
		name string
		age  int
	}
	alice := person{
		name: "alice",
		age:  15,
	}

	// dl.Printf prints to sandard error.
	// name: alice
	dl.Printf("name: %s", alice.name)
}
Output:

func Println

func Println(v ...interface{}) (int, error)

Println calls Fprintln to print to the standard logger. Arguments are handled in the manner of fmt.Printf.

Example
package main

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

func main() {
	type person struct {
		name string
		age  int
	}
	alice := person{
		name: "alice",
		age:  15,
	}

	// dl.Printf prints to sandard error.
	// name: alice
	//
	dl.Println("name:", alice.name)
}
Output:

Types

type CLI added in v0.5.9

type CLI struct {
}

CLI structs.

func New

func New() *CLI

New for running dl package with CLI.

func (*CLI) Run added in v0.5.9

func (d *CLI) Run(ctx context.Context, version string, args []string) error

Run executes each method for dl package.

type Logger added in v0.5.8

type Logger struct {
	*logr.Logger
}

Logger is a struct for preserving *logr.Logger.

func NewLogger added in v0.5.8

func NewLogger(l *logr.Logger) *Logger

NewLogger wraps logr.Logger.

Example
package main

import (
	"fmt"

	"github.com/go-logr/logr"
	"github.com/go-logr/zapr"
	"github.com/task4233/dl"
	"go.uber.org/zap"
)

func main() {
	zapLog, err := zap.NewDevelopment()
	if err != nil {
		panic(fmt.Sprintf("who watches the watchmen (%v)?", err))
	}
	var log logr.Logger = zapr.NewLogger(zapLog)

	// You can use your logr.Logger as it is.
	dlr := dl.NewLogger(&log)

	num := 57
	dlr.Info("Info: ", "num", num)
}
Output:

Directories

Path Synopsis
cmd
dl

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL