{"id":26895243,"url":"https://github.com/pwall567/log-front-testk","last_synced_at":"2025-07-14T00:37:41.211Z","repository":{"id":282248003,"uuid":"947692817","full_name":"pwall567/log-front-testk","owner":"pwall567","description":"Test functions for log-front-kotlin library","archived":false,"fork":false,"pushed_at":"2025-03-13T14:24:19.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-21T08:56:25.000Z","etag":null,"topics":["kotlin","library","logging","unit-testing"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pwall567.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-13T05:09:13.000Z","updated_at":"2025-03-13T14:23:58.000Z","dependencies_parsed_at":"2025-03-13T15:40:26.917Z","dependency_job_id":null,"html_url":"https://github.com/pwall567/log-front-testk","commit_stats":null,"previous_names":["pwall567/log-front-testk"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/pwall567/log-front-testk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwall567%2Flog-front-testk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwall567%2Flog-front-testk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwall567%2Flog-front-testk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwall567%2Flog-front-testk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pwall567","download_url":"https://codeload.github.com/pwall567/log-front-testk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwall567%2Flog-front-testk/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265228134,"owners_count":23731067,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["kotlin","library","logging","unit-testing"],"created_at":"2025-04-01T01:54:50.622Z","updated_at":"2025-07-14T00:37:41.193Z","avatar_url":"https://github.com/pwall567.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# log-front-testk\n\n[![Build Status](https://github.com/pwall567/log-front-testk/actions/workflows/build.yml/badge.svg)](https://github.com/pwall567/log-front-testk/actions/workflows/build.yml)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Kotlin](https://img.shields.io/static/v1?label=Kotlin\u0026message=v2.0.21\u0026color=7f52ff\u0026logo=kotlin\u0026logoColor=7f52ff)](https://github.com/JetBrains/kotlin/releases/tag/v2.0.21)\n[![Maven Central](https://img.shields.io/maven-central/v/io.kstuff/log-front-testk?label=Maven%20Central)](https://central.sonatype.com/artifact/io.jstuff/log-front-testk)\n\nTesting functions for the [`log-front-kotlin`](https://github.com/pwall567/log-front-kotlin) logging library.\n\n## Background\n\nWhen testing a Kotlin application that uses logging, a common requirement is to confirm that logging messages were\noutput as expected.\nThis library provides a simple mechanism for testing log output from applications that use the\n[`log-front-kotlin`](https://github.com/pwall567/log-front-kotlin) logging library.\n\n## Quick Start\n\nThe `LogList` class stores a list of all or selected logging messages output using `log-front-kotlin`.\nFor example:\n```kotlin\n        LogList().use { list -\u003e\n            val log = getLogger(\"xxx\")\n            // code that outputs log message to \"log\"\n            list shouldHaveInfo \"Account created\"\n        }\n```\n\n`LogList` makes use of the `LogListener` mechanism in `log-front-kotlin`.\nBecause `LogListener` implements `AutoCloseable`, the easiest way of using it is within a `use` block; that way the\n`LogList` will exist (and be supplied with log events) only for the duration of the test code.\n\n## Reference\n\n### `LogList`\n\nThe simplest form of `LogList` intercepts log events from all `Logger` instances:\n```kotlin\n        val logList = LogList()\n```\n\nBut sometimes it can be preferable to intercept log events for a selected set of `Logger`s; perhaps just one.\nA single `Logger` may be identified by name:\n```kotlin\n        val logList = LogList(\"xxx\")\n```\nOr by class:\n```kotlin\n        val logList = LogList(AccountsService::class)\n```\nOr for more complex cases, a [`StringMatcher`](https://github.com/pwall567/string-matcher) may be supplied:\n```kotlin\n        val logList = LogList(StringMatcher.wildcard(\"Accounts*\"))\n```\n\nThe `LogList` implements `List\u003cLogItem\u003e`, so it is possible to iterate through the list to locate a particular item.\nBut the more convenient way of examining the log output is to use one of the `shouldHaveXxxx` infix functions:\n\n| Name                        | Argument               | Throws `AssertionError` if the list does not contain...          |\n|-----------------------------|------------------------|------------------------------------------------------------------|\n| `shouldHaveTrace`           | `Any`                  | ...a TRACE event with the specified message object               |\n| `shouldHaveDebug`           | `Any`                  | ...a DEBUG event with the specified message object               |\n| `shouldHaveInfo`            | `Any`                  | ...an INFO event with the specified message object               |\n| `shouldHaveWarn`            | `Any`                  | ...a WARN event with the specified message object                |\n| `shouldHaveError`           | `Any`                  | ...an ERROR event with the specified message object              |\n| `shouldHaveTrace`           | `(LogItem) -\u003e Boolean` | ...a TRACE event matching the specified lambda                   |\n| `shouldHaveDebug`           | `(LogItem) -\u003e Boolean` | ...a DEBUG event matching the specified lambda                   |\n| `shouldHaveInfo`            | `(LogItem) -\u003e Boolean` | ...an INFO event matching the specified lambda                   |\n| `shouldHaveWarn`            | `(LogItem) -\u003e Boolean` | ...a WARN event matching the specified lambda                    |\n| `shouldHaveError`           | `(LogItem) -\u003e Boolean` | ...an ERROR event matching the specified lambda                  |\n| `shouldHaveTraceContaining` | `String`               | ...a TRACE event with a message containing the specified string  |\n| `shouldHaveDebugContaining` | `String`               | ...a DEBUG event with a message containing the specified string  |\n| `shouldHaveInfoContaining`  | `String`               | ...an INFO event with a message containing the specified string  |\n| `shouldHaveWarnContaining`  | `String`               | ...a WARN event with a message containing the specified string   |\n| `shouldHaveErrorContaining` | `String`               | ...an ERROR event with a message containing the specified string |\n| `shouldHaveTraceMatching`   | `Regex`                | ...a TRACE event with a message matching the specified `Regex`   |\n| `shouldHaveDebugMatching`   | `Regex`                | ...a DEBUG event with a message matching the specified `Regex`   |\n| `shouldHaveInfoMatching`    | `Regex`                | ...an INFO event with a message matching the specified `Regex`   |\n| `shouldHaveWarnMatching`    | `Regex`                | ...a WARN event with a message matching the specified `Regex`    |\n| `shouldHaveErrorMatching`   | `Regex`                | ...an ERROR event with a message matching the specified `Regex`  |\n\n### `LogItem`\n\nFor those needing to perform more detailed checks on the log entries, the `LogList` stores log events as `LogItem`s,\nwhich contain the following:\n\n| Name        | Type         | Description                                           |\n|-------------|--------------|-------------------------------------------------------|\n| `time`      | `Long`       | the time in milliseconds from the standard epoch      |\n| `name`      | `String`     | the `Logger` name                                     |\n| `level`     | `Level`      | the level of the logging event                        |\n| `message`   | `Any?`       | the log message                                       |\n| `throwable` | `Throwable?` | the `Throwable` associated with the log event, if any |\n\nAll of the logging functions take a message in the form of an `Any?`, as described in the documentation for\n[`log-front-kotlin`](https://github.com/pwall567/log-front-kotlin).\nThe `Any?` form is provided in the `LogItem`, allowing the consumer of the `LogItem` to take advantage of any inherent\nstructure in the message.\n\nA convenience property `messageString` gets the string form of the message (`null` will be returned as an empty string).\n\nIn addition to the usual `toString()` method, `LogItem` has three overloaded versions:\n\n- `toString(separator: Char)`\n- `toString(zoneId: ZoneId)`\n- `toString(separator: Char, zoneId: ZoneId)`\n\nThe `toString()` is intended mainly for debugging, and these additional functions allow the separator (the default is\nspace) and the `ZoneId` to be used when formatting the time (the default is the current default time zone) to be\nspecified.\n\nThere are also a number of extension functions on `LogItem` for checking the log output:\n\n- `LogItem.isTrace(test: (LogItem) -\u003e Boolean)`\n- `LogItem.isTrace(message: Any?)`\n- `LogItem.isTraceContaining(text: String)`\n- `LogItem.isTraceMatching(regex: Regex)`\n- `LogItem.isDebug(test: (LogItem) -\u003e Boolean)`\n- `LogItem.isDebug(message: Any?)`\n- `LogItem.isDebugContaining(text: String)`\n- `LogItem.isDebugMatching(regex: Regex)`\n- `LogItem.isInfo(test: (LogItem) -\u003e Boolean)`\n- `LogItem.isInfo(message: Any?)`\n- `LogItem.isInfoContaining(text: String)`\n- `LogItem.isInfoMatching(regex: Regex)`\n- `LogItem.isWarning(test: (LogItem) -\u003e Boolean)`\n- `LogItem.isWarning(message: Any?)`\n- `LogItem.isWarningContaining(text: String)`\n- `LogItem.isWarningMatching(regex: Regex)`\n- `LogItem.isError(test: (LogItem) -\u003e Boolean)`\n- `LogItem.isError(message: Any?)`\n- `LogItem.isErrorContaining(text: String)`\n- `LogItem.isErrorMatching(regex: Regex)`\n\nThese infix functions all return `Boolean`, and they test whether a `LogItem` matches the specified test.\nThe most general-purpose form is the one that takes a lambda:\n```kotlin\n    if (logItem isError { it.message == \"Bad request\" \u0026\u0026 it.throwable == null }) {\n        // found it\n    }\n```\nOr to check just the message:\n```kotlin\n    if (logItem isInfo \"OK\") {\n        // do something\n    }\n```\nVery often, the message contains variable data, and the test just needs to check the constant portion:\n```kotlin\n    if (logItem isDebugContaining \"Balance=\") {\n        // do something\n    }\n```\nOr to perform a similar test using a `Regex`:\n```kotlin\n    if (logItem isWarningMatching Regex(\"Balance [0-9]{1,8}\\\\.[0-9]{2} DR\")) {\n        // do something\n    }\n```\n\n## Dependency Specification\n\nThe latest version of the library is 6.2 (the version number of this library matches the version of `log-front-kotlin`\nto which it relates), and it may be obtained from the Maven Central repository.\n(The following dependency declarations assume that the library will be included for test purposes; this is expected to\nbe its principal use.)\n\n### Maven\n```xml\n    \u003cdependency\u003e\n      \u003cgroupId\u003eio.kstuff\u003c/groupId\u003e\n      \u003cartifactId\u003elog-front-testk\u003c/artifactId\u003e\n      \u003cversion\u003e6.2\u003c/version\u003e\n      \u003cscope\u003etest\u003c/scope\u003e\n    \u003c/dependency\u003e\n```\n### Gradle\n```groovy\n    testImplementation 'io.kstuff:log-front-testk:6.2'\n```\n### Gradle (kts)\n```kotlin\n    testImplementation(\"io.kstuff:log-front-testk:6.2\")\n```\n\nPeter Wall\n\n2025-02-14\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpwall567%2Flog-front-testk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpwall567%2Flog-front-testk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpwall567%2Flog-front-testk/lists"}