$17 GRAYBYTE WORDPRESS FILE MANAGER $63

SERVER : in-mum-web1330.main-hosting.eu #1 SMP Mon Feb 10 22:45:17 UTC 2025
SERVER IP : 88.222.243.2 | ADMIN IP 216.73.216.215
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/go/pkg/mod/github.com/go-kit/log@v0.2.1/

HOME
Current File : /opt/go/pkg/mod/github.com/go-kit/log@v0.2.1//stdlib_test.go
package log

import (
	"bytes"
	"fmt"
	"log"
	"testing"
	"time"
)

func TestStdlibWriter(t *testing.T) {
	buf := &bytes.Buffer{}
	log.SetOutput(buf)
	log.SetFlags(log.LstdFlags)
	logger := NewLogfmtLogger(StdlibWriter{})
	logger.Log("key", "val")
	timestamp := time.Now().Format("2006/01/02 15:04:05")
	if want, have := timestamp+" key=val\n", buf.String(); want != have {
		t.Errorf("want %q, have %q", want, have)
	}
}

func TestStdlibAdapterUsage(t *testing.T) {
	buf := &bytes.Buffer{}
	logger := NewLogfmtLogger(buf)
	writer := NewStdlibAdapter(logger)
	stdlog := log.New(writer, "", 0)

	now := time.Now()
	date := now.Format("2006/01/02")
	time := now.Format("15:04:05")

	for flag, want := range map[int]string{
		0:                                      "msg=hello\n",
		log.Ldate:                              "ts=" + date + " msg=hello\n",
		log.Ltime:                              "ts=" + time + " msg=hello\n",
		log.Ldate | log.Ltime:                  "ts=\"" + date + " " + time + "\" msg=hello\n",
		log.Lshortfile:                         "caller=stdlib_test.go:44 msg=hello\n",
		log.Lshortfile | log.Ldate:             "ts=" + date + " caller=stdlib_test.go:44 msg=hello\n",
		log.Lshortfile | log.Ldate | log.Ltime: "ts=\"" + date + " " + time + "\" caller=stdlib_test.go:44 msg=hello\n",
	} {
		buf.Reset()
		stdlog.SetFlags(flag)
		stdlog.Print("hello")
		if have := buf.String(); want != have {
			t.Errorf("flag=%d: want %#v, have %#v", flag, want, have)
		}
	}
}

func TestStdLibAdapterExtraction(t *testing.T) {
	buf := &bytes.Buffer{}
	logger := NewLogfmtLogger(buf)
	writer := NewStdlibAdapter(logger)
	for input, want := range map[string]string{
		"hello":                             "msg=hello\n",
		"2009/01/23: hello":                 "ts=2009/01/23 msg=hello\n",
		"2009/01/23 01:23:23: hello":        "ts=\"2009/01/23 01:23:23\" msg=hello\n",
		"01:23:23: hello":                   "ts=01:23:23 msg=hello\n",
		"2009/01/23 01:23:23.123123: hello": "ts=\"2009/01/23 01:23:23.123123\" msg=hello\n",
		"2009/01/23 01:23:23.123123 /a/b/c/d.go:23: hello": "ts=\"2009/01/23 01:23:23.123123\" caller=/a/b/c/d.go:23 msg=hello\n",
		"01:23:23.123123 /a/b/c/d.go:23: hello":            "ts=01:23:23.123123 caller=/a/b/c/d.go:23 msg=hello\n",
		"2009/01/23 01:23:23 /a/b/c/d.go:23: hello":        "ts=\"2009/01/23 01:23:23\" caller=/a/b/c/d.go:23 msg=hello\n",
		"2009/01/23 /a/b/c/d.go:23: hello":                 "ts=2009/01/23 caller=/a/b/c/d.go:23 msg=hello\n",
		"/a/b/c/d.go:23: hello":                            "caller=/a/b/c/d.go:23 msg=hello\n",
	} {
		buf.Reset()
		fmt.Fprint(writer, input)
		if have := buf.String(); want != have {
			t.Errorf("%q: want %#v, have %#v", input, want, have)
		}
	}
}

func TestStdLibAdapterPrefixedExtraction(t *testing.T) {
	buf := &bytes.Buffer{}
	logger := NewLogfmtLogger(buf)
	writer := NewStdlibAdapter(logger, Prefix("some prefix ", false))
	for input, want := range map[string]string{
		"some prefix hello":                                            "msg=hello\n",
		"some prefix 2009/01/23: hello":                                "ts=2009/01/23 msg=hello\n",
		"some prefix 2009/01/23 01:23:23: hello":                       "ts=\"2009/01/23 01:23:23\" msg=hello\n",
		"some prefix 01:23:23: hello":                                  "ts=01:23:23 msg=hello\n",
		"some prefix 2009/01/23 01:23:23.123123: hello":                "ts=\"2009/01/23 01:23:23.123123\" msg=hello\n",
		"some prefix 2009/01/23 01:23:23.123123 /a/b/c/d.go:23: hello": "ts=\"2009/01/23 01:23:23.123123\" caller=/a/b/c/d.go:23 msg=hello\n",
		"some prefix 01:23:23.123123 /a/b/c/d.go:23: hello":            "ts=01:23:23.123123 caller=/a/b/c/d.go:23 msg=hello\n",
		"some prefix 2009/01/23 01:23:23 /a/b/c/d.go:23: hello":        "ts=\"2009/01/23 01:23:23\" caller=/a/b/c/d.go:23 msg=hello\n",
		"some prefix 2009/01/23 /a/b/c/d.go:23: hello":                 "ts=2009/01/23 caller=/a/b/c/d.go:23 msg=hello\n",
		"some prefix /a/b/c/d.go:23: hello":                            "caller=/a/b/c/d.go:23 msg=hello\n",
		"/a/b/c/d.go:23: some prefix hello":                            "caller=/a/b/c/d.go:23 msg=hello\n",
	} {
		buf.Reset()
		fmt.Fprint(writer, input)
		if have := buf.String(); want != have {
			t.Errorf("%q: want %#v, have %#v", input, want, have)
		}
	}
}

func TestStdLibAdapterPrefixedExtractionWithJoinToMessage(t *testing.T) {
	buf := &bytes.Buffer{}
	logger := NewLogfmtLogger(buf)
	writer := NewStdlibAdapter(logger, Prefix("some prefix ", true))
	for input, want := range map[string]string{
		"some prefix hello":                                            "msg=\"some prefix hello\"\n",
		"some prefix 2009/01/23: hello":                                "ts=2009/01/23 msg=\"some prefix hello\"\n",
		"some prefix 2009/01/23 01:23:23: hello":                       "ts=\"2009/01/23 01:23:23\" msg=\"some prefix hello\"\n",
		"some prefix 01:23:23: hello":                                  "ts=01:23:23 msg=\"some prefix hello\"\n",
		"some prefix 2009/01/23 01:23:23.123123: hello":                "ts=\"2009/01/23 01:23:23.123123\" msg=\"some prefix hello\"\n",
		"some prefix 2009/01/23 01:23:23.123123 /a/b/c/d.go:23: hello": "ts=\"2009/01/23 01:23:23.123123\" caller=/a/b/c/d.go:23 msg=\"some prefix hello\"\n",
		"some prefix 01:23:23.123123 /a/b/c/d.go:23: hello":            "ts=01:23:23.123123 caller=/a/b/c/d.go:23 msg=\"some prefix hello\"\n",
		"some prefix 2009/01/23 01:23:23 /a/b/c/d.go:23: hello":        "ts=\"2009/01/23 01:23:23\" caller=/a/b/c/d.go:23 msg=\"some prefix hello\"\n",
		"some prefix 2009/01/23 /a/b/c/d.go:23: hello":                 "ts=2009/01/23 caller=/a/b/c/d.go:23 msg=\"some prefix hello\"\n",
		"some prefix /a/b/c/d.go:23: hello":                            "caller=/a/b/c/d.go:23 msg=\"some prefix hello\"\n",
		"/a/b/c/d.go:23: some prefix hello":                            "caller=/a/b/c/d.go:23 msg=\"some prefix hello\"\n",
	} {
		buf.Reset()
		fmt.Fprint(writer, input)
		if have := buf.String(); want != have {
			t.Errorf("%q: want %#v, have %#v", input, want, have)
		}
	}
}

func TestStdlibAdapterSubexps(t *testing.T) {
	for input, wantMap := range map[string]map[string]string{
		"hello world": {
			"date": "",
			"time": "",
			"file": "",
			"msg":  "hello world",
		},
		"hello\nworld": {
			"date": "",
			"time": "",
			"file": "",
			"msg":  "hello\nworld",
		},
		"2009/01/23: hello world": {
			"date": "2009/01/23",
			"time": "",
			"file": "",
			"msg":  "hello world",
		},
		"2009/01/23 01:23:23: hello world": {
			"date": "2009/01/23",
			"time": "01:23:23",
			"file": "",
			"msg":  "hello world",
		},
		"01:23:23: hello world": {
			"date": "",
			"time": "01:23:23",
			"file": "",
			"msg":  "hello world",
		},
		"2009/01/23 01:23:23.123123: hello world": {
			"date": "2009/01/23",
			"time": "01:23:23.123123",
			"file": "",
			"msg":  "hello world",
		},
		"2009/01/23 01:23:23.123123 /a/b/c/d.go:23: hello world": {
			"date": "2009/01/23",
			"time": "01:23:23.123123",
			"file": "/a/b/c/d.go:23",
			"msg":  "hello world",
		},
		"01:23:23.123123 /a/b/c/d.go:23: hello world": {
			"date": "",
			"time": "01:23:23.123123",
			"file": "/a/b/c/d.go:23",
			"msg":  "hello world",
		},
		"2009/01/23 01:23:23 /a/b/c/d.go:23: hello world": {
			"date": "2009/01/23",
			"time": "01:23:23",
			"file": "/a/b/c/d.go:23",
			"msg":  "hello world",
		},
		"2009/01/23 /a/b/c/d.go:23: hello world": {
			"date": "2009/01/23",
			"time": "",
			"file": "/a/b/c/d.go:23",
			"msg":  "hello world",
		},
		"/a/b/c/d.go:23: hello world": {
			"date": "",
			"time": "",
			"file": "/a/b/c/d.go:23",
			"msg":  "hello world",
		},
		"2009/01/23 01:23:23.123123 C:/a/b/c/d.go:23: hello world": {
			"date": "2009/01/23",
			"time": "01:23:23.123123",
			"file": "C:/a/b/c/d.go:23",
			"msg":  "hello world",
		},
		"01:23:23.123123 C:/a/b/c/d.go:23: hello world": {
			"date": "",
			"time": "01:23:23.123123",
			"file": "C:/a/b/c/d.go:23",
			"msg":  "hello world",
		},
		"2009/01/23 01:23:23 C:/a/b/c/d.go:23: hello world": {
			"date": "2009/01/23",
			"time": "01:23:23",
			"file": "C:/a/b/c/d.go:23",
			"msg":  "hello world",
		},
		"2009/01/23 C:/a/b/c/d.go:23: hello world": {
			"date": "2009/01/23",
			"time": "",
			"file": "C:/a/b/c/d.go:23",
			"msg":  "hello world",
		},
		"C:/a/b/c/d.go:23: hello world": {
			"date": "",
			"time": "",
			"file": "C:/a/b/c/d.go:23",
			"msg":  "hello world",
		},
		"2009/01/23 01:23:23.123123 C:/a/b/c/d.go:23: :.;<>_#{[]}\"\\": {
			"date": "2009/01/23",
			"time": "01:23:23.123123",
			"file": "C:/a/b/c/d.go:23",
			"msg":  ":.;<>_#{[]}\"\\",
		},
		"01:23:23.123123 C:/a/b/c/d.go:23: :.;<>_#{[]}\"\\": {
			"date": "",
			"time": "01:23:23.123123",
			"file": "C:/a/b/c/d.go:23",
			"msg":  ":.;<>_#{[]}\"\\",
		},
		"2009/01/23 01:23:23 C:/a/b/c/d.go:23: :.;<>_#{[]}\"\\": {
			"date": "2009/01/23",
			"time": "01:23:23",
			"file": "C:/a/b/c/d.go:23",
			"msg":  ":.;<>_#{[]}\"\\",
		},
		"2009/01/23 C:/a/b/c/d.go:23: :.;<>_#{[]}\"\\": {
			"date": "2009/01/23",
			"time": "",
			"file": "C:/a/b/c/d.go:23",
			"msg":  ":.;<>_#{[]}\"\\",
		},
		"C:/a/b/c/d.go:23: :.;<>_#{[]}\"\\": {
			"date": "",
			"time": "",
			"file": "C:/a/b/c/d.go:23",
			"msg":  ":.;<>_#{[]}\"\\",
		},
	} {
		haveMap := subexps([]byte(input))
		for key, want := range wantMap {
			if have := haveMap[key]; want != have {
				t.Errorf("%q: %q: want %q, have %q", input, key, want, have)
			}
		}
	}
}

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
25 Jan 2024 4.43 PM
root / root
0755
.github
--
25 Jan 2024 4.43 PM
root / root
0555
level
--
25 Jan 2024 4.43 PM
root / root
0555
syslog
--
25 Jan 2024 4.43 PM
root / root
0555
term
--
25 Jan 2024 4.43 PM
root / root
0555
.gitignore
0.263 KB
25 Jan 2024 4.43 PM
root / root
0444
LICENSE
1.038 KB
25 Jan 2024 4.43 PM
root / root
0444
README.md
5.19 KB
25 Jan 2024 4.43 PM
root / root
0444
benchmark_test.go
0.433 KB
25 Jan 2024 4.43 PM
root / root
0444
concurrency_test.go
0.638 KB
25 Jan 2024 4.43 PM
root / root
0444
doc.go
5.229 KB
25 Jan 2024 4.43 PM
root / root
0444
example_test.go
2.714 KB
25 Jan 2024 4.43 PM
root / root
0444
go.mod
0.08 KB
25 Jan 2024 4.43 PM
root / root
0444
go.sum
0.169 KB
25 Jan 2024 4.43 PM
root / root
0444
json_logger.go
2.03 KB
25 Jan 2024 4.43 PM
root / root
0444
json_logger_test.go
4.609 KB
25 Jan 2024 4.43 PM
root / root
0444
log.go
6.315 KB
25 Jan 2024 4.43 PM
root / root
0444
log_test.go
8.65 KB
25 Jan 2024 4.43 PM
root / root
0444
logfmt_logger.go
1.345 KB
25 Jan 2024 4.43 PM
root / root
0444
logfmt_logger_test.go
1.378 KB
25 Jan 2024 4.43 PM
root / root
0444
nop_logger.go
0.201 KB
25 Jan 2024 4.43 PM
root / root
0444
nop_logger_test.go
0.49 KB
25 Jan 2024 4.43 PM
root / root
0444
staticcheck.conf
0.017 KB
25 Jan 2024 4.43 PM
root / root
0444
stdlib.go
4.163 KB
25 Jan 2024 4.43 PM
root / root
0444
stdlib_test.go
9.264 KB
25 Jan 2024 4.43 PM
root / root
0444
sync.go
3.176 KB
25 Jan 2024 4.43 PM
root / root
0444
sync_test.go
1.993 KB
25 Jan 2024 4.43 PM
root / root
0444
value.go
3.335 KB
25 Jan 2024 4.43 PM
root / root
0444
value_test.go
3.837 KB
25 Jan 2024 4.43 PM
root / root
0444

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF