I have log files that contain C++ namespace artifacts (indicated by the double colons ::) and XML content embedded within them. After loading and displaying the logs in a browser application, the content has been separated from the Unix timestamps like so:
1564002293071 INFO: ToGroundMessageFilter::addSubscriptionAddress staged subscribe address [uxas.messages.uxnative.KillSer
1564002293073 INFO: *** INITIALIZING:: Service[ToGroundMessageFilter] Service Id[64] with working directory [] ***
1564002293082 INFO: WorldviewTransformationService::configure Location offsets = (lat:0, lon:0, alt:0)
1564002311397 INFO: WatchdogManagerService::<WaypointActual Series="TACE"><Waypoint><Waypoint Series="TACE"><RemediationId>1</RemediationId><StatePlatformId>58</StatePlatformId><LatLonAlt><LatLonAlt Series="TACE"><Altitude>366</Altitude><Latitude>34.97866</Latitude><Longitude>-117.85169</Longitude></LatLonAlt></LatLonAlt><Speed>0</Speed><Heading>0</Heading><Roll>0</Roll><Pitch>0</Pitch><Yaw>0</Yaw></Waypoint></Waypoint><SenderID>68</SenderID><ActualTime>0</ActualTime><PerceivedTime>0</PerceivedTime><SenderPlatformWorld>Constructive</SenderPlatformWorld><SenderPlatformType>Other</SenderPlatformType><Comment></Comment></WaypointActual>
1564002312386 INFO: ProximityConstraintService::<WatchdogConstraintViolation Series="TACE"><ConstraintId>-2</ConstraintId><Latching>true</Latching><Priority>1</Priority><RequestedRemediationId>1</RequestedRemediationId><HasViolation>false</HasViolation><ConstraintName>Proximity</ConstraintName><SenderID>72</SenderID><ActualTime>1564002312385</ActualTime><PerceivedTime>1564002312385</PerceivedTime><SenderPlatformWorld>Live</SenderPlatformWorld><SenderPlatformType>Air</SenderPlatformType><Comment></Comment></WatchdogConstraintViolation>
The next step is to parse out this log and save it as a CSV using JavaScript. However, the challenge lies in the fact that the contents per line are not only XML. JavaScript has XML object parsers, but how do we approach this if the lines are a mix? The goal is to create a CSV with columns for the Unix timestamp, namespace names, and other details (as shown in the sample table below).
Additionally, we have the format of each event namespace. Below are examples of two structured like XML configurations. These configurations are subject to updates as the software evolves. There are about 24+ XML structured "services" defined similarly. Is there a way to have the parser "load XML configs" based on the service name?
WorldViewTransformationService
<AutonomyWaypointActual Series="TACE">
<Waypoint>
<Waypoint Series="TACE">
<RemediationId></RemediationId>
<StatePlatformId></StatePlatformId>
<LatLonAlt>
<LatLonAlt Series="TACE">
<Altitude></Altitude>
<Latitude></Latitude>
<Longitude></Longitude>
</LatLonAlt>
</LatLonAlt>
<Speed></Speed>
<Heading></Heading>
<Roll></Roll>
<Pitch></Pitch>
<Yaw></Yaw>
</Waypoint>
</Waypoint>
<SenderID></SenderID>
<ActualTime></ActualTime>
<PerceivedTime></PerceivedTime>
<SenderPlatformWorld></SenderPlatformWorld>
<SenderPlatformType></SenderPlatformType>
<Comment></Comment>
</AutonomyWaypointActual>
ProximityConstraintService
<ProximityConstraint Series="TACE">
<Radius></Radius>
<OtherPlatformId></OtherPlatformId>
<ConstraintId></ConstraintId>
<PlatformId></PlatformId>
<Latching></Latching>
<Priority></Priority>
<RequestedRemediationId></RequestedRemediationId>
<ConstraintName></ConstraintName>
</ProximityConstraint>
Sample CSV output: (Events like ProximityConstraintService do not have altitude, pitch, or yaw information.)
unix | event | altitude | pitch | yaw | Priority | Latching
1564002293071 ToGroundMessageFilter - - - - -
1564002293073 INITIALIZING - - - - -
1564002293082 WorldviewTransformationService 100 15 4 - -
1564002300983 WorldviewTransformationService 220 16 2 - -
1564002312386 ProximityConstraintService - - - 3 1