dl

package module
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2022 License: MIT Imports: 14 Imported by: 0

README

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

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

Description

dl provides a package for logging instantly such as dubugging and one command to remove them all.

Installation

Go1.18
$ go install github.com/task4233/dl/cmd/dl@latest

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 add .
$ 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

Documentation

Overview

Example
package main

import (
	"os"

	"github.com/task4233/dl"
)

func main() {
	num := 123
	name := "dl"
	type MyInt int
	var myNum MyInt = 123

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

}
Output:

num:  123
name: dl
[DeLog] info: 123 (dl_test.MyInt) log_example_test.go:17

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func FInfo

func FInfo[T any](w io.Writer, v T) (int, error)

FInfo gives a val, a type, a file name, a line number and writes to w..

func Fprintf

func Fprintf(w io.Writer, format string, v ...any) (int, error)

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

func Fprintln

func Fprintln(w io.Writer, v ...any) (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.

func Info

func Info[T any](v T) (int, error)

Info gives a val, a type, a file name, a line number to print to the standard logger.

func Printf

func Printf(format string, v ...any) (int, error)

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

func Println

func Println(v ...any) (int, error)

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

Types

type DeLog

type DeLog struct {
	*Sweeper
}

DeLog structs

func New

func New() *DeLog

New for running dl package with CLI

func (*DeLog) Clean

func (d *DeLog) Clean(ctx context.Context, baseDir string) error

Clean deletes all methods related to dl in ".go" files under the given directory path

func (*DeLog) Init

func (d *DeLog) Init(ctx context.Context, baseDir string) error

Init inserts dl command into git pre-commit hook

func (*DeLog) Run

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

Run executes each method for dl package

type Sweeper

type Sweeper struct {
	// contains filtered or unexported fields
}

func NewSweeper

func NewSweeper() *Sweeper

func (*Sweeper) Sweep

func (d *Sweeper) Sweep(ctx context.Context, targetPath string) error

Sweep deletes all methods related to dl

Directories

Path Synopsis
cmd
dl command

Jump to

Keyboard shortcuts

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