{"record":{"id":"c067037223e033fd","repo":"testcontainers/testcontainers-java","slug":"timed-out-waiting-for-log-output-matching-s","errorCode":null,"errorMessage":"Timed out waiting for log output matching '%s'","messagePattern":"Timed out waiting for log output matching '(.+?)'","errorType":"exception","errorClass":"ContainerLaunchException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/testcontainers/containers/wait/strategy/LogMessageWaitStrategy.java","lineNumber":47,"sourceCode":"            .withFollowStream(true)\n            .withSince(0)\n            .withStdOut(true)\n            .withStdErr(true);\n\n        try (FrameConsumerResultCallback callback = new FrameConsumerResultCallback()) {\n            callback.addConsumer(OutputFrame.OutputType.STDOUT, waitingConsumer);\n            callback.addConsumer(OutputFrame.OutputType.STDERR, waitingConsumer);\n\n            cmd.exec(callback);\n\n            Predicate<OutputFrame> waitPredicate = outputFrame -> {\n                // (?s) enables line terminator matching (equivalent to Pattern.DOTALL)\n                return outputFrame.getUtf8String().matches(\"(?s)\" + regEx);\n            };\n            try {\n                waitingConsumer.waitUntil(waitPredicate, startupTimeout.getSeconds(), TimeUnit.SECONDS, times);\n            } catch (TimeoutException e) {\n                throw new ContainerLaunchException(\"Timed out waiting for log output matching '\" + regEx + \"'\");\n            }\n        }\n    }\n\n    public LogMessageWaitStrategy withRegEx(String regEx) {\n        this.regEx = regEx;\n        return this;\n    }\n\n    public LogMessageWaitStrategy withTimes(int times) {\n        this.times = times;\n        return this;\n    }\n}\n","sourceCodeStart":29,"sourceCodeEnd":62,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/core/src/main/java/org/testcontainers/containers/wait/strategy/LogMessageWaitStrategy.java#L29-L62","documentation":"LogMessageWaitStrategy watches container stdout/stderr for a line matching a configured regex (withRegEx) and throws ContainerLaunchException when no matching log message appears within the startup timeout. It means the container ran but never printed the expected 'ready' marker.","triggerScenarios":"waitUntilReady calls waitingConsumer.waitUntil(predicate, startupTimeout) and a TimeoutException is raised because no output frame matches '(?s)' + regEx before the timeout.","commonSituations":"Regex doesn't match the app's actual log format (log format changed between versions); app logs the message to a file instead of stdout; app failed to start entirely; startup timeout too short for slow apps.","solutions":["Print container.getLogs() and adjust the regex in .withRegEx(...) to match the real output","Increase .withStartupTimeout(Duration.ofSeconds(120))","Confirm the app logs the ready message to stdout/stderr, not a log file","Check the container didn't crash-loop — look for exit codes/restarts in logs"],"exampleFix":"// before\nnew LogMessageWaitStrategy().withRegEx(\".*Server started.*\").withStartupTimeout(Duration.ofSeconds(30));\n// after\nnew LogMessageWaitStrategy().withRegEx(\".*Started .*Application in .*\\\\n\").withStartupTimeout(Duration.ofSeconds(90));","handlingStrategy":"retry","validationCode":"// Confirm the app emits the marker to stdout before waiting on logs\nString logs = container.getLogs();\nif (!logs.matches(\"(?s).*Started .*Application.*\")) {\n    System.out.println(\"No ready marker yet; current logs: \" + logs);\n}","typeGuard":null,"tryCatchPattern":"try {\n    container.waitingFor(new LogMessageWaitStrategy().withRegEx(\".*ready.*\\\\n\")).start();\n} catch (ContainerLaunchException e) {\n    if (e.getMessage().startsWith(\"Timed out waiting for log output matching\")) {\n        System.err.println(\"Container logs: \" + container.getLogs());\n    }\n    throw e;\n}","preventionTips":["Verify the exact log line format with a manual docker run first","Log the ready message to stdout/stderr, never only to a file","Raise withStartupTimeout for slow apps and test regexes against real output"],"tags":["timeout","logs","wait-strategy","regex","testcontainers"],"backgroundTag":"wait-strategy-timeout","analyzedSha":"8e549514e3f01c57d70546fbb8599d138f3903e5","analyzedAt":"2026-09-12T14:56:41.227Z","contentChangedAt":"2026-09-12T14:56:41.227Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}