Browse Source

Change package name to "erdi.us/log"

Erdi Chen 9 months ago
parent
commit
2ceef53c10
3 changed files with 20 additions and 13 deletions
  1. 1 1
      go.mod
  2. 11 4
      klog.go
  3. 8 8
      klog_test.go

+ 1 - 1
go.mod

@@ -1,4 +1,4 @@
-module erdi.us/erdi/log
+module erdi.us/log
 
 
 go 1.17
 go 1.17
 
 

+ 11 - 4
klog.go

@@ -67,7 +67,6 @@
 //		"glob" pattern and N is a V level. For instance,
 //		"glob" pattern and N is a V level. For instance,
 //			-vmodule=gopher*=3
 //			-vmodule=gopher*=3
 //		sets the V level to 3 in all Go files whose names begin "gopher".
 //		sets the V level to 3 in all Go files whose names begin "gopher".
-//
 package log
 package log
 
 
 import (
 import (
@@ -91,7 +90,7 @@ import (
 
 
 	"github.com/go-logr/logr"
 	"github.com/go-logr/logr"
 
 
-	"erdi.us/erdi/log/color"
+	"erdi.us/log/color"
 )
 )
 
 
 // severity identifies the sort of log: info, warning etc. It also implements
 // severity identifies the sort of log: info, warning etc. It also implements
@@ -593,8 +592,11 @@ It returns a buffer containing the formatted header and the user's file and line
 The depth specifies how many stack frames above lives the source line to be identified in the log message.
 The depth specifies how many stack frames above lives the source line to be identified in the log message.
 
 
 Log lines have this form:
 Log lines have this form:
+
 	Lmmdd hh:mm:ss.uuuuuu threadid file:line] msg...
 	Lmmdd hh:mm:ss.uuuuuu threadid file:line] msg...
+
 where the fields are defined as follows:
 where the fields are defined as follows:
+
 	L                A single character, representing the log level (eg 'I' for INFO)
 	L                A single character, representing the log level (eg 'I' for INFO)
 	mm               The month (zero padded; ie May is '05')
 	mm               The month (zero padded; ie May is '05')
 	dd               The day (zero padded)
 	dd               The day (zero padded)
@@ -875,8 +877,9 @@ func (rb *redirectBuffer) Write(bytes []byte) (n int, err error) {
 // If set, all log lines will be suppressed from the regular Output, and
 // If set, all log lines will be suppressed from the regular Output, and
 // redirected to the logr implementation.
 // redirected to the logr implementation.
 // Use as:
 // Use as:
-//   ...
-//   klog.SetLogger(zapr.NewLogger(zapLog))
+//
+//	...
+//	klog.SetLogger(zapr.NewLogger(zapLog))
 func SetLogger(logr logr.Logger) {
 func SetLogger(logr logr.Logger) {
 	logging.mu.Lock()
 	logging.mu.Lock()
 	defer logging.mu.Unlock()
 	defer logging.mu.Unlock()
@@ -1299,9 +1302,13 @@ func newVerbose(level Level, b bool) Verbose {
 // The returned value is a struct of type Verbose, which implements Info, Infoln
 // The returned value is a struct of type Verbose, which implements Info, Infoln
 // and Infof. These methods will write to the Info log if called.
 // and Infof. These methods will write to the Info log if called.
 // Thus, one may write either
 // Thus, one may write either
+//
 //	if glog.V(2).Enabled() { klog.Info("log this") }
 //	if glog.V(2).Enabled() { klog.Info("log this") }
+//
 // or
 // or
+//
 //	klog.V(2).Info("log this")
 //	klog.V(2).Info("log this")
+//
 // The second form is shorter but the first is cheaper if logging is off because it does
 // The second form is shorter but the first is cheaper if logging is off because it does
 // not evaluate its arguments.
 // not evaluate its arguments.
 //
 //

+ 8 - 8
klog_test.go

@@ -21,7 +21,7 @@ import (
 	"errors"
 	"errors"
 	"flag"
 	"flag"
 	"fmt"
 	"fmt"
-	"io/ioutil"
+	"io"
 	stdLog "log"
 	stdLog "log"
 	"os"
 	"os"
 	"path/filepath"
 	"path/filepath"
@@ -383,7 +383,7 @@ func TestSetOutputDataRace(t *testing.T) {
 		wg.Add(1)
 		wg.Add(1)
 		go func() {
 		go func() {
 			defer wg.Done()
 			defer wg.Done()
-			SetOutput(ioutil.Discard)
+			SetOutput(io.Discard)
 		}()
 		}()
 	}
 	}
 	for i := 1; i <= 50; i++ {
 	for i := 1; i <= 50; i++ {
@@ -395,7 +395,7 @@ func TestSetOutputDataRace(t *testing.T) {
 		wg.Add(1)
 		wg.Add(1)
 		go func() {
 		go func() {
 			defer wg.Done()
 			defer wg.Done()
-			SetOutputBySeverity("INFO", ioutil.Discard)
+			SetOutputBySeverity("INFO", io.Discard)
 		}()
 		}()
 	}
 	}
 	for i := 1; i <= 50; i++ {
 	for i := 1; i <= 50; i++ {
@@ -514,7 +514,7 @@ func TestOpenAppendOnStart(t *testing.T) {
 		err = e
 		err = e
 	}
 	}
 
 
-	f, err := ioutil.TempFile("", "test_klog_OpenAppendOnStart")
+	f, err := os.CreateTemp("", "test_klog_OpenAppendOnStart")
 	if err != nil {
 	if err != nil {
 		t.Fatalf("unexpected error: %v", err)
 		t.Fatalf("unexpected error: %v", err)
 	}
 	}
@@ -535,7 +535,7 @@ func TestOpenAppendOnStart(t *testing.T) {
 
 
 	// ensure we wrote what we expected
 	// ensure we wrote what we expected
 	logging.flushAll()
 	logging.flushAll()
-	b, err := ioutil.ReadFile(logging.logFile)
+	b, err := os.ReadFile(logging.logFile)
 	if err != nil {
 	if err != nil {
 		t.Fatalf("unexpected error: %v", err)
 		t.Fatalf("unexpected error: %v", err)
 	}
 	}
@@ -552,7 +552,7 @@ func TestOpenAppendOnStart(t *testing.T) {
 	Info(y)
 	Info(y)
 	// ensure we wrote what we expected
 	// ensure we wrote what we expected
 	logging.lockAndFlushAll()
 	logging.lockAndFlushAll()
-	b, err = ioutil.ReadFile(logging.logFile)
+	b, err = os.ReadFile(logging.logFile)
 	if err != nil {
 	if err != nil {
 		t.Fatalf("unexpected error: %v", err)
 		t.Fatalf("unexpected error: %v", err)
 	}
 	}
@@ -561,7 +561,7 @@ func TestOpenAppendOnStart(t *testing.T) {
 	}
 	}
 	// The initial log message should be preserved across create calls.
 	// The initial log message should be preserved across create calls.
 	logging.lockAndFlushAll()
 	logging.lockAndFlushAll()
-	b, err = ioutil.ReadFile(logging.logFile)
+	b, err = os.ReadFile(logging.logFile)
 	if err != nil {
 	if err != nil {
 		t.Fatalf("unexpected error: %v", err)
 		t.Fatalf("unexpected error: %v", err)
 	}
 	}
@@ -645,7 +645,7 @@ func BenchmarkLogs(b *testing.B) {
 	setFlags()
 	setFlags()
 	defer logging.swap(logging.newBuffers())
 	defer logging.swap(logging.newBuffers())
 
 
-	testFile, err := ioutil.TempFile("", "test.log")
+	testFile, err := os.CreateTemp("", "test.log")
 	if err != nil {
 	if err != nil {
 		b.Fatal("unable to create temporary file")
 		b.Fatal("unable to create temporary file")
 	}
 	}