Parses log entries to extract an optional error code, providing a default status when it's missing by using the `{!var:...}` fallback syntax.

ID: 1205

				
					using uCalcSoftware;

var uc = new uCalc();
var t = new uCalc.Transformer();
// Pattern: Match "Log:", an optional level, and the message.
// Replacement: Use `{!level:INFO}` to insert 'INFO' if {level} is empty.
t.FromTo("Log: [{level: ERROR | WARN}] {msg}",
"Status:{!level:INFO}{level} | Msg:{msg}");

// Case 1: Level is present
Console.WriteLine(t.Transform("Log: ERROR File not found"));

// Case 2: Level is missing, so the fallback is used
Console.WriteLine(t.Transform("Log: System started successfully"));
				
			
Status:ERROR | Msg:File not found
Status:INFO | Msg:System started successfully
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc::Transformer t;
   // Pattern: Match "Log:", an optional level, and the message.
   // Replacement: Use `{!level:INFO}` to insert 'INFO' if {level} is empty.
   t.FromTo("Log: [{level: ERROR | WARN}] {msg}",
   "Status:{!level:INFO}{level} | Msg:{msg}");

   // Case 1: Level is present
   cout << t.Transform("Log: ERROR File not found") << endl;

   // Case 2: Level is missing, so the fallback is used
   cout << t.Transform("Log: System started successfully") << endl;
}
				
			
Status:ERROR | Msg:File not found
Status:INFO | Msg:System started successfully
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t As New uCalc.Transformer()
      '// Pattern: Match "Log:", an optional level, and the message.
      '// Replacement: Use `{!level:INFO}` to insert 'INFO' if {level} is empty.
      t.FromTo("Log: [{level: ERROR | WARN}] {msg}",
      "Status:{!level:INFO}{level} | Msg:{msg}")
      
      '// Case 1: Level is present
      Console.WriteLine(t.Transform("Log: ERROR File not found"))
      
      '// Case 2: Level is missing, so the fallback is used
      Console.WriteLine(t.Transform("Log: System started successfully"))
   End Sub
End Module
				
			
Status:ERROR | Msg:File not found
Status:INFO | Msg:System started successfully