1 // recfile -- GNU recutils'es recfiles parser on pure Go
2 // Copyright (C) 2020-2024 Sergey Matveev <stargrave@stargrave.org>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, version 3 of the License.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
24 "go.cypherpunks.ru/recfile"
27 func TestBasic(t *testing.T) {
29 logger := slog.New(NewRecfileHandler(
36 if !logger.Enabled(nil, slog.LevelWarn) {
39 logger.Info("won't catch me")
40 logger.Warn("catch me")
42 r := recfile.NewReader(&buf)
47 if m["Message"] != "catch me" {
50 if m["Urgency"] != "WARN" {
53 if _, err = time.Parse(time.RFC3339Nano, m["Time"]); err != nil {
58 func TestTrimmed(t *testing.T) {
60 logger := slog.New(NewRecfileHandler(&buf, slog.LevelWarn, "", "Message", ""))
61 logger.Warn("catch me")
62 r := recfile.NewReader(&buf)
67 if m["Message"] != "catch me" {
70 if m["Urgency"] != "" {
78 func TestFeatured(t *testing.T) {
80 logger := slog.New(NewRecfileHandler(&buf, slog.LevelInfo, "L", "M", "T"))
81 logger.WithGroup("grou").WithGroup("py").With("foo", "bar").With("bar", "baz").Info(
82 "catch me", "baz", []string{"multi", "line"},
84 r := recfile.NewReader(&buf)
89 if m["M"] != "catch me" {
95 if _, err = time.Parse(time.RFC3339Nano, m["T"]); err != nil {
98 if m["grou_py_foo"] != "bar" {
101 if m["grou_py_bar"] != "baz" {
104 if m["grou_py_baz"] != "multi\nline" {