Parses a log file and uses the `FocusableOnly` option to quickly extract only the critical error entries.
ID: 1081
See: GetMatches
using uCalcSoftware;
var uc = new uCalc();
var t = new uCalc.Transformer();
var log = "INFO: Task started. ERROR: Connection failed. INFO: Task finished.";
t.Text = log;
// Rules for different log levels. Only errors are focusable.
t.Pattern("INFO: {msg}.").SetFocusable(false);
t.Pattern("ERROR: {msg}.").SetFocusable(true);
t.Find();
Console.WriteLine("All log entries:");
Console.WriteLine(t.GetMatches().Text);
Console.WriteLine("");
Console.WriteLine("Critical errors only:");
// Use the option to filter for only the important entries
var errorMatches = t.GetMatches(MatchesOption.FocusableOnly);
Console.WriteLine(errorMatches.Text);
All log entries:
INFO: Task started.
ERROR: Connection failed.
INFO: Task finished.
Critical errors only:
ERROR: Connection failed. using uCalcSoftware; var uc = new uCalc(); var t = new uCalc.Transformer(); var log = "INFO: Task started. ERROR: Connection failed. INFO: Task finished."; t.Text = log; // Rules for different log levels. Only errors are focusable. t.Pattern("INFO: {msg}.").SetFocusable(false); t.Pattern("ERROR: {msg}.").SetFocusable(true); t.Find(); Console.WriteLine("All log entries:"); Console.WriteLine(t.GetMatches().Text); Console.WriteLine(""); Console.WriteLine("Critical errors only:"); // Use the option to filter for only the important entries var errorMatches = t.GetMatches(MatchesOption.FocusableOnly); Console.WriteLine(errorMatches.Text);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uCalc::Transformer t;
auto log = "INFO: Task started. ERROR: Connection failed. INFO: Task finished.";
t.Text(log);
// Rules for different log levels. Only errors are focusable.
t.Pattern("INFO: {msg}.").SetFocusable(false);
t.Pattern("ERROR: {msg}.").SetFocusable(true);
t.Find();
cout << "All log entries:" << endl;
cout << t.GetMatches().Text() << endl;
cout << "" << endl;
cout << "Critical errors only:" << endl;
// Use the option to filter for only the important entries
auto errorMatches = t.GetMatches(MatchesOption::FocusableOnly);
cout << errorMatches.Text() << endl;
}
All log entries:
INFO: Task started.
ERROR: Connection failed.
INFO: Task finished.
Critical errors only:
ERROR: Connection failed. #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uCalc::Transformer t; auto log = "INFO: Task started. ERROR: Connection failed. INFO: Task finished."; t.Text(log); // Rules for different log levels. Only errors are focusable. t.Pattern("INFO: {msg}.").SetFocusable(false); t.Pattern("ERROR: {msg}.").SetFocusable(true); t.Find(); cout << "All log entries:" << endl; cout << t.GetMatches().Text() << endl; cout << "" << endl; cout << "Critical errors only:" << endl; // Use the option to filter for only the important entries auto errorMatches = t.GetMatches(MatchesOption::FocusableOnly); cout << errorMatches.Text() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t As New uCalc.Transformer()
Dim log = "INFO: Task started. ERROR: Connection failed. INFO: Task finished."
t.Text = log
'// Rules for different log levels. Only errors are focusable.
t.Pattern("INFO: {msg}.").SetFocusable(false)
t.Pattern("ERROR: {msg}.").SetFocusable(true)
t.Find()
Console.WriteLine("All log entries:")
Console.WriteLine(t.GetMatches().Text)
Console.WriteLine("")
Console.WriteLine("Critical errors only:")
'// Use the option to filter for only the important entries
Dim errorMatches = t.GetMatches(MatchesOption.FocusableOnly)
Console.WriteLine(errorMatches.Text)
End Sub
End Module
All log entries:
INFO: Task started.
ERROR: Connection failed.
INFO: Task finished.
Critical errors only:
ERROR: Connection failed. Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t As New uCalc.Transformer() Dim log = "INFO: Task started. ERROR: Connection failed. INFO: Task finished." t.Text = log '// Rules for different log levels. Only errors are focusable. t.Pattern("INFO: {msg}.").SetFocusable(false) t.Pattern("ERROR: {msg}.").SetFocusable(true) t.Find() Console.WriteLine("All log entries:") Console.WriteLine(t.GetMatches().Text) Console.WriteLine("") Console.WriteLine("Critical errors only:") '// Use the option to filter for only the important entries Dim errorMatches = t.GetMatches(MatchesOption.FocusableOnly) Console.WriteLine(errorMatches.Text) End Sub End Module