Skip to content
/ zltest Public

Package zltest provides facilities to test zerolog log messages.

License

Notifications You must be signed in to change notification settings

rzajac/zltest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

04b6e73 · Jan 27, 2022

History

16 Commits
Sep 17, 2021
Oct 5, 2020
Oct 5, 2020
Mar 29, 2021
Jan 22, 2022
Jan 22, 2022
Jan 27, 2022
Jan 27, 2022
Sep 14, 2021
Sep 14, 2021
Sep 21, 2021
Sep 17, 2021

Repository files navigation

Go Report Card GoDoc

Logging is an integral part of most applications and as such it has tobe tested. Package zltest provides facilities to test zerolog log messages.

In general zltest.Tester provides methods to test values (or existence) of specific fields in logged messages.

Installation

go get github.com/rzajac/zltest

Examples

func Test_ServiceLogsProperly(t *testing.T) {
    // --- Given ---
    // Crate zerolog test helper. 
    tst := zltest.New(t)

    // Configure zerolog and pas tester as a writer.     
    log := zerolog.New(tst).With().Timestamp().Logger()
    
    // Inject log to tested service or package.
    srv := MyService(log)

    // --- When ---
    srv.ExecuteSomeLogic()

    // --- Then ---

    // Test if log messages were generated properly.
    ent := tst.LastEntry()
    ent.ExpNum("key0", 123)
    ent.ExpMsg("message")
    ent.ExpLevel(zerolog.ErrorLevel)
}

License

BSD-2-Clause