I am trying to filter out the logs and its full context using Select-String in powershell. I know the parameters of context and their meanings but this limits to what I am trying to achieve. Below is the log snippet and I want to search the log with date as a search parameter to select-string filter.
[AD Thread-Metric Reporter1] 16 Dec 2019 19:03:32,371 ERROR ManagedMonitorDelegate - Error sending metrics - will requeue for later transmission
com.singularity.ee.agent.commonservices.metricgeneration.metrics.MetricSendException: Connection back off limitation in effect: /controller/instance/417/metrics
at com.singularity.ee.agent.commonservices.metricgeneration.AMetricSubscriber.publish(AMetricSubscriber.java:350)
at com.singularity.ee.agent.commonservices.metricgeneration.MetricReporter.run(MetricReporter.java:113)
at com.singularity.ee.util.javaspecific.scheduler.AgentScheduledExecutorServiceImpl$SafeRunnable.run(AgentScheduledExecutorServiceImpl.java:122)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at com.singularity.ee.util.javaspecific.scheduler.ADFutureTask$Sync.innerRunAndReset(ADFutureTask.java:335)
at com.singularity.ee.util.javaspecific.scheduler.ADFutureTask.runAndReset(ADFutureTask.java:152)
at com.singularity.ee.util.javaspecific.scheduler.ADScheduledThreadPoolExecutor$ADScheduledFutureTask.access$101(ADScheduledThreadPoolExecutor.java:119)
at com.singularity.ee.util.javaspecific.scheduler.ADScheduledThreadPoolExecutor$ADScheduledFutureTask.runPeriodic(ADScheduledThreadPoolExecutor.java:206)
at com.singularity.ee.util.javaspecific.scheduler.ADScheduledThreadPoolExecutor$ADScheduledFutureTask.run(ADScheduledThreadPoolExecutor.java:236)
at com.singularity.ee.util.javaspecific.scheduler.ADThreadPoolExecutor$Worker.runTask(ADThreadPoolExecutor.java:694)
at com.singularity.ee.util.javaspecific.scheduler.ADThreadPoolExecutor$Worker.run(ADThreadPoolExecutor.java:726)
at java.lang.Thread.run(Thread.java:748)
[AD Thread Pool-Global0] 16 Dec 2019 19:03:37,956 ERROR SystemAgentPollingForUpdate - Fatal transport error while connecting to URL [/controller/instance/417/systemagentpolling]: org.apache.http.conn.ConnectTimeoutException: Connect to imswt01.ecbt1.tadnet.net:8090 [imswt01.ecbt1.tadnet.net/10.228.18.71] failed: connect timed out
[AD Thread Pool-Global0] 16 Dec 2019 19:03:37,956 WARN SystemAgentPollingForUpdate - Invalid response for configuration request from controller/could not connect. Msg: Fatal transport error while connecting to URL [/controller/instance/417/systemagentpolling]
[AD Thread Pool-Global0] 16 Dec 2019 19:03:37,956 WARN SystemAgentPollingForUpdate - System configuration request failed 5 times consecutively.
[AD Thread-Metric Reporter1] 16 Dec 2019 19:03:42,362 ERROR ManagedMonitorDelegate - Error sending metrics - will requeue for later transmission
com.singularity.ee.agent.commonservices.metricgeneration.metrics.MetricSendException: Connection back off limitation in effect: /controller/instance/417/metrics
at com.singularity.ee.agent.commonservices.metricgeneration.AMetricSubscriber.publish(AMetricSubscriber.java:350)
at com.singularity.ee.agent.commonservices.metricgeneration.MetricReporter.run(MetricReporter.java:113)
at com.singularity.ee.util.javaspecific.scheduler.AgentScheduledExecutorServiceImpl$SafeRunnable.run(AgentScheduledExecutorServiceImpl.java:122)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at com.singularity.ee.util.javaspecific.scheduler.ADFutureTask$Sync.innerRunAndReset(ADFutureTask.java:335)
at com.singularity.ee.util.javaspecific.scheduler.ADFutureTask.runAndReset(ADFutureTask.java:152)
at com.singularity.ee.util.javaspecific.scheduler.ADScheduledThreadPoolExecutor$ADScheduledFutureTask.access$101(ADScheduledThreadPoolExecutor.java:119)
at com.singularity.ee.util.javaspecific.scheduler.ADScheduledThreadPoolExecutor$ADScheduledFutureTask.runPeriodic(ADScheduledThreadPoolExecutor.java:206)
at com.singularity.ee.util.javaspecific.scheduler.ADScheduledThreadPoolExecutor$ADScheduledFutureTask.run(ADScheduledThreadPoolExecutor.java:236)
at com.singularity.ee.util.javaspecific.scheduler.ADThreadPoolExecutor$Worker.runTask(ADThreadPoolExecutor.java:694)
at com.singularity.ee.util.javaspecific.scheduler.ADThreadPoolExecutor$Worker.run(ADThreadPoolExecutor.java:726)
at java.lang.Thread.run(Thread.java:748)
If I run my code
Select-String "16 Dec 2019" -context 0,10
Then it filters 10 lines below the match expression. My problem is, what if the context of the log entry is bigger with many lines? Is there anyway we keep searching and printing until the new log entry is recorded? like and we get the whole Log entry context without limiting the context?
Many thanks in advance,
Select-String
can be made to work but it would be cumbersome impov. I'd use a switch statement instead implementing a simple state machine.Edit cudo's to mklement0
Edit2 poc using provided example