public static void DecodeAndTraceToConsole(StreamWriter outputfile, CLogDecodedTraceLine bundle, string errorLine, CLogConfigurationFile config, Dictionary <string, IClogEventArg> valueBag, EventInformation eventInfo, bool showTimeStamp, bool showCPUInfo) { try { if (null == bundle) { Console.WriteLine($"Invalid TraceLine : {errorLine}"); return; } StringBuilder toPrint = new StringBuilder(); if (null != eventInfo) { if (showCPUInfo) { if (!String.IsNullOrEmpty(eventInfo.CPUId)) { toPrint.Append("[" + eventInfo.CPUId + "]"); } toPrint.Append("["); bool havePid = false; if (!String.IsNullOrEmpty(eventInfo.ProcessId)) { toPrint.Append(eventInfo.ProcessId); havePid = true; } if (!String.IsNullOrEmpty(eventInfo.ThreadId)) { if (havePid) { toPrint.Append("."); } toPrint.Append(eventInfo.ThreadId); } toPrint.Append("]"); } if (showTimeStamp) { toPrint.Append("[" + eventInfo.Timestamp.ToString("hh:mm:ss.ffffff") + "]"); } } string clean; CLogFileProcessor.CLogTypeContainer[] types = CLogFileProcessor.BuildTypes(config, null, bundle.TraceString, null, out clean); if (0 == types.Length) { toPrint.Append(bundle.TraceString); goto toPrint; } CLogFileProcessor.CLogTypeContainer first = types[0]; if (valueBag.Count > 0) { int argIndex = 0; foreach (CLogFileProcessor.CLogTypeContainer type in types) { var arg = bundle.splitArgs[argIndex]; if (0 != arg.DefinationEncoding.CompareTo(type.TypeNode.DefinationEncoding)) { Console.WriteLine("Invalid Types in Traceline"); throw new Exception("InvalidType : " + arg.DefinationEncoding); } CLogEncodingCLogTypeSearch payload = type.TypeNode; if (!valueBag.TryGetValue(arg.MacroVariableName, out IClogEventArg value)) { toPrint.Append($"<SKIPPED:BUG:MISSINGARG:{arg.MacroVariableName}:{payload.EncodingType}>"); } else { if (string.IsNullOrEmpty(type.TypeNode.CustomDecoder)) { toPrint.Append($"{type.LeadingString}{value.AsString}"); } else { string decodedValue; config.DecodeUsingCustomDecoder(type.TypeNode, value, bundle.match, out decodedValue); toPrint.Append($"{type.LeadingString}{decodedValue}"); } } first = type; ++argIndex; } string tail = bundle.TraceString.Substring(types[types.Length - 1].ArgStartingIndex + types[types.Length - 1].ArgLength); toPrint.Append(tail); } else { toPrint.Clear(); toPrint.Append(bundle.TraceString); } toPrint: if (null == outputfile) { Console.WriteLine(toPrint); } else { outputfile.WriteLine(toPrint); } } catch (Exception e) { Console.WriteLine($"Invalid TraceLine : {errorLine} " + e); } }
public void TraceLineDiscovered(CLogDecodedTraceLine decodedTraceLine, StringBuilder r) { r = null; /* * if (_knownHashes.ContainsKey(decodedTraceLine.UniqueId) && _knownHashes[decodedTraceLine.UniqueId] == decodedTraceLine. * return; */ string argsString = ""; int clogArgCountForMacroAlignment = 2; // decodedTraceLine.splitArgs.Length + 1; foreach (var arg in decodedTraceLine.splitArgs) { switch (decodedTraceLine.configFile.FindType(arg, decodedTraceLine).EncodingType) { case CLogEncodingType.ByteArray: clogArgCountForMacroAlignment += 2; // Verify the input argument contains CLOG_BYTEARRAY - this will aid in debugging if (!arg.UserSuppliedTrimmed.Contains("CLOG_BYTEARRAY")) { CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Err, $"Trace ID '{decodedTraceLine.UniqueId}' contains a ByteArray type that is not using the CLOG_BYTEARRAY macro"); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Err, " Please encode the following argument with CLOG_BYTEARRAY(length, pointer)"); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Err, ""); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Err, $"// {decodedTraceLine.match.MatchedRegEx}"); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Err, ""); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Err, $"Failing Arg: "); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Err, arg.UserSuppliedTrimmed); throw new CLogEnterReadOnlyModeException("ByteArrayNotUsingCLOG_BYTEARRAY", CLogHandledException.ExceptionType.ByteArrayMustUseMacro, decodedTraceLine.match); } break; default: clogArgCountForMacroAlignment++; break; } } string implSignature = $" clogTraceImpl_{clogArgCountForMacroAlignment}_ARGS_TRACE_{decodedTraceLine.UniqueId}("; string macroName = $"_clog_{clogArgCountForMacroAlignment}_ARGS_TRACE_{decodedTraceLine.UniqueId}"; _headerFile.AppendLine($"#ifndef {macroName}"); if (-1 != decodedTraceLine.macro.EncodedArgNumber) { implSignature += "const char *uniqueId"; argsString += "uniqueId"; int idx = 1; foreach (var arg in decodedTraceLine.splitArgs) { CLogEncodingCLogTypeSearch v = decodedTraceLine.configFile.FindType(arg, decodedTraceLine); if (idx == decodedTraceLine.macro.EncodedArgNumber) { implSignature += ", const char *encoded_arg_string"; argsString += ", encoded_arg_string"; } ++idx; if (!v.Synthesized) { implSignature += $", {v.CType} {arg.MacroVariableName}"; argsString += $", {arg.MacroVariableName}"; if (v.EncodingType == CLogEncodingType.ByteArray) { implSignature += $", int {arg.MacroVariableName}_len"; argsString += $", {arg.MacroVariableName}_len"; } } } if (idx == decodedTraceLine.macro.EncodedArgNumber) { implSignature += ", const char *encoded_arg_string"; argsString += ", encoded_arg_string"; } } else { argsString += "uniqueId"; } implSignature += ")"; StringBuilder macroBody = new StringBuilder(); _headerFile.AppendLine(""); _headerFile.AppendLine(""); _headerFile.AppendLine(""); _headerFile.AppendLine("/*----------------------------------------------------------"); _headerFile.AppendLine($"// Decoder Ring for {decodedTraceLine.UniqueId}"); _headerFile.AppendLine($"// {decodedTraceLine.TraceString}"); _headerFile.AppendLine($"// {decodedTraceLine.match.MatchedRegEx}"); foreach (var arg in decodedTraceLine.splitArgs) { _headerFile.AppendLine($"// {arg.MacroVariableName} = {arg.MacroVariableName} = {arg.UserSuppliedTrimmed}"); } _headerFile.AppendLine("----------------------------------------------------------*/"); // // BUGBUG: not fully implemented - the intent of 'implSignature' is to give a turn key // way for a module to emit code without the need for the module to emit its own function // //_headerFile.AppendLine($"void {implSignature};"); macroBody.AppendLine($"#define {macroName}({argsString})" + "\\"); foreach (ICLogOutputModule module in _modules) { CLogConfigurationProfile configProfile = decodedTraceLine.GetMacroConfigurationProfile(); if (module.ManditoryModule || configProfile.ModuleNames.Contains(module.ModuleName.ToUpper())) { if (m_unusedModules.Contains(module)) { module.InitHeader(_headerInit); m_unusedModules.Remove(module); } CLogTraceLineInformation existingTraceInfo; if (!_sidecar.ModuleUniqueness.IsUnique(module, decodedTraceLine, out existingTraceInfo)) { if (decodedTraceLine.configFile.OverwriteHashCollisions || existingTraceInfo.UniquenessHash == Guid.Empty) { CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Wrn, " The signature for the previously defined event is being overwritten:"); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Wrn, $" ConfigFile:{decodedTraceLine.configFile.FilePath}"); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Wrn, $" TraceID:{existingTraceInfo.TraceID}"); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Wrn, $" UniquenessHash:{existingTraceInfo.UniquenessHash}"); _sidecar.RemoveTraceLine(existingTraceInfo); _knownHashes.Remove(decodedTraceLine.UniqueId); _sidecar.TraceLineDiscovered(_inputSourceFile, decodedTraceLine, _sidecar, _headerFile, macroBody, _sourceFile); } else { if (existingTraceInfo.Unsaved) { CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Err, $"Trace ID '{existingTraceInfo.TraceID}' is not unique within this file"); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Err, $""); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Err, $"Previous Declaration: "); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Err, $"File/Line: {CLogConsoleTrace.GetFileLine(existingTraceInfo.PreviousFileMatch.match)}"); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Err, $"{existingTraceInfo.PreviousFileMatch.match}"); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Err, $""); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Err, $""); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Err, $"Current Declaration: "); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Err, $"File/Line: {CLogConsoleTrace.GetFileLine(decodedTraceLine.match)}"); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Err, $"{decodedTraceLine.match}"); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Err, $""); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Err, $""); } else { CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Err, $"Trace ID '{existingTraceInfo.TraceID}' is not unique - somewhere else in your library this unique ID has different"); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Err, " encoding string, or argument types. You either need to back out your change, or use a different unique identifier"); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Err, " If you've made changes that wont impact tools (for example fixing a"); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Err, " typo in a trace string) - have two options to override/refresh the signature check"); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Std, ""); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Std, " Force/Clobber the event signature - indicating you desire breaking the uniqueness contract"); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Std, $" 1. remove UniquenessHash ({existingTraceInfo.UniquenessHash}) frome this TraceID({existingTraceInfo.TraceID}) in file {decodedTraceLine.configFile.FilePath}"); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Std, $" 2. specify the --overwriteHashCollisions command line argument (good if you're making lots of changes that are all safe)"); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Tip, $" 3. set the environment variable CLOG_DEVELOPMENT_MODE=1 ($env:CLOG_DEVELOPMENT_MODE=1)"); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Std, ""); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Std, ""); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Wrn, " The signature for the previously defined event:"); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Wrn, $" ConfigFile:{decodedTraceLine.configFile.FilePath}"); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Wrn, $" TraceID:{existingTraceInfo.TraceID}"); CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Wrn, $" UniquenessHash:{existingTraceInfo.UniquenessHash}"); } throw new CLogEnterReadOnlyModeException("TraceIDNotUnique", CLogHandledException.ExceptionType.TaceIDNotUnique, decodedTraceLine.match); } } if (!_knownHashes.Contains(decodedTraceLine.UniqueId)) { _sidecar.InsertTraceLine(module, decodedTraceLine); var c = decodedTraceLine.configFile.MacroConfigurations[decodedTraceLine.macro.MacroConfiguration[decodedTraceLine.configFile.ProfileName]]; if (!c.SkipProcessing) { module.TraceLineDiscovered(_inputSourceFile, decodedTraceLine, _sidecar, _headerFile, macroBody, _sourceFile); } } } } _knownHashes.Add(decodedTraceLine.UniqueId); _headerFile.AppendLine(macroBody.ToString()); _headerFile.AppendLine("#endif"); _headerFile.AppendLine(""); _headerFile.AppendLine(""); _headerFile.AppendLine(""); _headerFile.AppendLine(""); }