Practical: Validating log file entries. If more than 2 'WARNING' entries exist, they are ignored, but 'ERROR' entries are still processed.

ID: 946

				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
var log = "WARNING: low disk. ERROR: service down. WARNING: high CPU. WARNING: queue full.";

var warningRule = t.FromTo("WARNING: {msg}.", "[WARN] {msg}.");
var errorRule = t.FromTo("ERROR: {msg}.", "[ERR] {msg}.");

// Set a rule-specific limit for warnings.
warningRule.Maximum = 2;

t.Filter(log);
Console.WriteLine(t.Matches.Text);
				
			
[ERR] service down.
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   auto log = "WARNING: low disk. ERROR: service down. WARNING: high CPU. WARNING: queue full.";

   auto warningRule = t.FromTo("WARNING: {msg}.", "[WARN] {msg}.");
   auto errorRule = t.FromTo("ERROR: {msg}.", "[ERR] {msg}.");

   // Set a rule-specific limit for warnings.
   warningRule.Maximum(2);

   t.Filter(log);
   cout << t.Matches().Text() << endl;
}
				
			
[ERR] service down.
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      Dim log = "WARNING: low disk. ERROR: service down. WARNING: high CPU. WARNING: queue full."
      
      Dim warningRule = t.FromTo("WARNING: {msg}.", "[WARN] {msg}.")
      Dim errorRule = t.FromTo("ERROR: {msg}.", "[ERR] {msg}.")
      
      '// Set a rule-specific limit for warnings.
      warningRule.Maximum = 2
      
      t.Filter(log)
      Console.WriteLine(t.Matches.Text)
   End Sub
End Module
				
			
[ERR] service down.