-
Notifications
You must be signed in to change notification settings - Fork 2
Parsing user logs
The application shall allow for parsing user logs. The format of the log will be provided by a user created XML file.
The application shall accept additional option: -u <log_format_file>
The configuration is passed by the first parameter of the source description. The user format shall be passed by the ‘U’ option as follows:: U{<log_format_file>}.
The expected XML configuration structure has been described below.
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!DOCTYPE signals SYSTEM "vcdMaker.dtd">
<signals>
<vector>
<line> Regular expression describing the line including group matching </line>
<timestamp> Timestamp expression </timestamp>
<name> Name expression </name>
<value> Integer value expression </value>
<size> Size expression </size>
</vector>
<real>
<line> Regular expression describing the line including group matching </line>
<timestamp> Timestamp expression </timestamp>
<name> Name expression </name>
<value> Float value expression </value>
</real>
<event>
<line> Regular expression describing the line including group matching </line>
<timestamp> Timestamp expression </timestamp>
<name> Name expression </name>
</event>
…
</signals>
</log_configuration >
There might exist several vector, real or event nodes. According to the user needs. The syntax of the XML file can be verified with the provided DTD file:
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT signals (vector | real | event)*>
<!ELEMENT vector ( line,
timestamp,
name,
value,
size)
>
<!ELEMENT real ( line,
timestamp,
name,
value)
>
<!ELEMENT event ( line,
timestamp,
name)
>
<!ELEMENT line (#PCDATA)>
<!ELEMENT timestamp (#PCDATA)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT value (#PCDATA)>
<!ELEMENT size (#PCDATA)>
To parse the original vcdMaker format one could use the configuration file below:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!DOCTYPE signals SYSTEM "vcdMaker.dtd">
<signals>
<vector>
<line>#([[:d:]]+) ([[:graph:]]+) ([[:d:]]+) ([[:d:]]+)( +.*)?</line>
<timestamp>dec(1)</timestamp>
<name>txt(2)</name>
<value>dec(3)</value>
<size>dec(4)</size>
</vector>
<real>
<line>#([[:d:]]+) ([[:graph:]]+) ([[:d:][:punct:]]+) f( +.*)?</line>
<timestamp>dec(1)</timestamp>
<name>txt(2)</name>
<value>flt(3)</value>
</real>
<event>
<line>#([[:d:]]+) ([[:graph:]]+) e( +.*)?</line>
<timestamp>dec(1)</timestamp>
<name>txt(2)</name>
</event>
</signals >
There are several functions which can be used to construct signal properties and they have been listed below:
-
dec(group_number) It returns the integer representation of the string provided by the regex capture group. It must be a valid decimal string, e.g. '153'.
-
hex(group_number) It returns the integer representation of the string provided by the regex capture group. It must be a valid hexadecimal string, e.g. 'A78'.
-
line() It returns the number of the parsed log line. Hint: it allows for parsing logs not containing timestamps at all. It could be useful in some circumstances.
-
flt(group_number) It returns the float representation of the string provided by the regex capture group. It must be a valid float string, e.g. '3.14159'.
-
txt(group_number) It returns the string captured by the regex group. It must be a valid string, e.g. 'Sensor_1'.
-
group_number– decimal integer in the range from 1 to the last index of the given regex group
The integer expression is a combination of arithmetic operators and expression functions. The precedence of operators is traditional. Available operands: '*', '/', '+', '-', '()'.
Example
10 * (dec(1) + dec(3)) + hex(2)
The value of the expression can be easily calculated applying simple arithmetic. If dec(1) equals 2, hex(2) equals 0xB and dec(3) equals 5 then the calculated output value is 81.
The float expression is a combination of arithmetic operators and the flt() expression function which is the only accepted function in this case. The precedence of operators is traditional. Available operands: '*', '/', '+', '-', '()'.
Example
2.5 * (flt(1) + flt(2)) – 0.9
Again, the value of the expression is based on a simple arithmetic evaluation. If flt(1) equals 2.5, flt(2) equals 1.1 then the calculated output value is 8.1.
It is a combination of strings (in double quotation marks) and regex groups. Available operands: '+'.
Example
"SomeName." + txt(1) + "OtherName" + txt(2) + "1"
So, in the final string 'txt(1)' will be replaced by the first regex capture group while 'txt(2)' will be replaced by the second regex capture group. If txt(1) is "XYZ" while txt(2) is ".ABC" the output string will be: "SomeName.XYZOtherName.ABC1"
This must be a valid integer expression. The timestamps do not have appear in the ascending order. Signals will be properly sorted by a tool. The line() function returns the processed log line number.
This must be a valid string expression. The name of the signal shall follow the vcdMaker signal schema.
For a vector signal this must be a valid integer expression. The line() function returns always 0. For a real signal this must be a valid float expression.
This must be a valid integer expression. The line() function returns always 0.