Home » Eclipse Projects » Eclipse Titan » Logging in Eclipse Titan part III: Custom logger plug-ins
Logging in Eclipse Titan part III: Custom logger plug-ins [message #1721571] |
Thu, 28 January 2016 11:15 |
|
We have seen earlier that , although the file and console logs are highly configurable, they have a set format.
Now, as there is no universally accepted logging format, but there are countless formats popular in an area or in another, this raises the following question: what should one do if a specific format is required? What's more, what's the recommendation if the logs should not appear locally , but should be transferred across the network
e.g. to a logging/statistics server?
Luckily (well, it's not exactly luck, it's design ), Titan is equipped with an extensible logging architecture. The test execution events are directed towards the logger plugin interface and this interface can host any number of logger plugins in parallel. The default logger is the LegacyLogger, the one writing into files and to the console, but if desired , the user can create a customized plug-in which will read the raw data from the plug-in interface, format it appropriately, if need be send it across the network, and in general produce the needed output.
A number of such plug-ins are delivered together with Titan and they can be used "as is", or they can constitute a model for writing similar ones.
Their source code can be found under /loggerplugins. There are two versions of a JUnit logger plug-in, which generates output in a JUnit-compatible xml format, and a TSTLogger plug-in which sends its' output to a statistical server in form of HTTP POST messages.
The logger plug-ins are loaded dynamically, unlike the (by default) statically loaded LegacyLogger, so when compiling,
the dynamic runtime library of Titan should be used, and this can be achieved by using the -l switch when generating the Makefile.
The logger plug-ins will have their own configuration parameters that can be read from the [LOGGING] section of the config file.
The logger plug-ins in general and the logger plug-ins delivered with Titan are described in detail in ch 7.2.1 "Logger Plug-ins", and 7.2.2 "Dynamically loaded logger plugins shipped with Titan".
Let's examine the usage of the first JUnit Logger plug-in. Let's consider the below simple example:
module hello {
type component CT {}
testcase tc1() runs on CT {
log("Hello Titan!");
setverdict(pass,"Everything is OK");
}
testcase tc2() runs on CT {
log("Hello Titan!");
setverdict(fail,"Something went wrong");
}
control {
execute(tc1());
execute(tc2());
}
}
The Makefile should be generated with:
makefilegen -fl hello.ttcn
The configuration file to be used is:
[LOGGING]
LogSourceInfo := Yes
SourceInfoFormat := Single
LoggerPlugins := { JUnitLogger := "libjunitlogger" }
*.JUnitLogger.filename_stem := "MyJunitLogFile"
*.JUnitLogger.testsuite_name := "myJUnitTest"
[MODULE_PARAMETERS]
[TESTPORT_PARAMETERS]
[EXECUTE]
hello.control
(see details about cfg parameters in the ref. guide)
The LD_LIBRARY_PATH environment variable should contain both $(TTCN3_DIR)/lib and the current directory in which files are residing and compilation is done.
When the code is executed with:
ttcn3_start hello cfg.cfg
both the standard set of logfiles and a logfile named MyJunitLogFile-XXXX.log are generated (XXXX being a random number), where the content of
MyJunitLogFile-XXXX.log is the following:
<?xml version="1.0"?>
<testsuite name='myJUnitTest'><!-- logger name="JUnitLogger" version="v1.0" -->
<!-- Testcase tc1 started -->
<!-- Testcase tc1 finished in 0.000884, verdict: pass, reason: Everything is OK -->
<testcase classname='hello' name='tc1' time='0.000884'>
</testcase>
<!-- Testcase tc2 started -->
<!-- Testcase tc2 finished in 0.000442, verdict: fail, reason: Something went wrong -->
<testcase classname='hello' name='tc2' time='0.000442'>
<failure type='fail-verdict'>Something went wrong
hello.ttcn:14 hello control part
hello.ttcn:10 tc2 testcase
</failure>
</testcase>
</testsuite>
If someone wishes to implement such a customized logger plug-in, one should read ch. 3 "Logger Plug-ins" of the Titan API guide, which covers
details about implementing, building etc. of logger plug-ins. This information, together with the source code of delivered logger plug-ins should be sufficient
to get one started.
Next, we will look into dynamic re-configuration of logging options.
Best regards
Elemer
|
|
|
Re: Logging in Eclipse Titan part III: Custom logger plug-ins [message #1754316 is a reply to message #1721571] |
Thu, 16 February 2017 10:57 |
|
Hello Elemer,
Thank you for this excellent explication for the logger API and the additional loggers available with Titan.
I have a question regarding the logger API: is it possible to insert the output from the adapters and codecs inside the logger? I can't find how to access the actual data in order to print it.
Thank you in advance.
Best regards,
Naum
|
|
| | | |
Re: Logging in Eclipse Titan part III: Custom logger plug-ins [message #1755252 is a reply to message #1754337] |
Wed, 01 March 2017 16:53 |
|
Hello Elemer,
I forgot to respond here, I found the corresponding messages: for debug and warning messages I should check if it is log event of type debug or warning and get the corresponding (inside Categorized class) text message.
I found also how to get the messages sent by the test port: also by checking if the log event is send or receive event on the port and getting the "Msg__port__send" or "Msg__port__recv" structures.
Now I have another question: As the messages that are sent or received in those "Msg__port__send" and "Msg__port__recv" structures are simple charstrings, is there a way to get at least a pretty-print of the structure that is received/sent to the port? Or better, XML/JSON output? Because, for now the output is like this (output from oneM2MTester): @OneM2M_TestSystem.M2MRequestPrimitive : { requestPrimitive_ := { operation := int1 (1), to_ := "/mobius-yt", from_ := "/mobius-yt", requestIdentifier := "m_createAe", resourceType := int2 (2), name := "MyTestAe002", content := { any_1 := { { AE_create := { name := "MyTestAe002", labels := { "label_test", "ae_create" }, accessControlPolicyIDs := omit, expirationTime := omit, announceTo := omit, announcedAttribute := omit, appName := omit, app_ID := "myAppId", pointOfAccess := { "http://0.0.0.0:7579", "mqtt://0.0.0.0/:mobius-yt" }, ontologyRef := omit, requestReachability := true } } } }, originatingTimestamp := omit, requestExpirationTimestamp := omit, resultExpirationTimestamp := omit, operationExecutionTime := omit, responseType := omit, resultPersistence := omit, resultContent := omit, eventCategory := omit, deliveryAggregation := omit, groupRequestIdentifier := omit, filterCriteria := <unbound>, discoveryResultType := <unbound> }, host := "mobius:7579", xmlNamespace := "m2m=____preserved_1____quot;http://www.onem2m.org/xml/protocols____preserved_1____quot;", protocolBinding := "HTTP", serialization := "json" }
Thanks in advance.
Best regards,
Naum
|
|
|
Re: Logging in Eclipse Titan part III: Custom logger plug-ins [message #1755255 is a reply to message #1755252] |
Wed, 01 March 2017 17:26 |
|
Hi Naum,
I believe you are looking for the "logformat" utility:
logformat
usage: logformat [-i n] [-o outfile] [-s] [-n] [file.log] ...
or logformat -v
OPTIONS:
-i n: set the depth of each indentation to n characters
-o outfile: write the formatted log into file outfile
-s: place the logs of each test case into separate files
-n newline and tab control characters are not modified
-v: print version
which can be used to pretty-print Titan logs.
Your example formatted with logformat looks like this:
@OneM2M_TestSystem.M2MRequestPrimitive : {
requestPrimitive_ := {
operation := int1 (1),
to_ := "/mobius-yt",
from_ := "/mobius-yt",
requestIdentifier := "m_createAe",
resourceType := int2 (2),
name := "MyTestAe002",
content := {
any_1 := {
{
AE_create := {
name := "MyTestAe002",
labels := {
"label_test",
"ae_create"
},
accessControlPolicyIDs := omit,
expirationTime := omit,
announceTo := omit,
announcedAttribute := omit,
appName := omit,
app_ID := "myAppId",
pointOfAccess := {
"http://0.0.0.0:7579",
"mqtt://0.0.0.0/:mobius-yt"
},
ontologyRef := omit,
requestReachability := true
}
}
}
},
originatingTimestamp := omit,
requestExpirationTimestamp := omit,
resultExpirationTimestamp := omit,
operationExecutionTime := omit,
responseType := omit,
resultPersistence := omit,
resultContent := omit,
eventCategory := omit,
deliveryAggregation := omit,
groupRequestIdentifier := omit,
filterCriteria := <unbound>,
discoveryResultType := <unbound>
},
host := "mobius:7579",
xmlNamespace := "m2m=____preserved_1____quot;http://www.onem2m.org/xml/protocols____preserved_1____quot;",
protocolBinding := "HTTP",
serialization := "json"
}
JSON and XML structures are also nicely formatted.
I hope this helps.
BR
Elemer
|
|
| |
Re: Logging in Eclipse Titan part III: Custom logger plug-ins [message #1755268 is a reply to message #1755266] |
Wed, 01 March 2017 20:54 |
|
Hi Elemer,
Yes, in fact I'm trying to do exactly that! For example, I am modifying the jUnit logger plugin to obtain a JSON structure for the log instead of XML. The problem is that inside the JSON, when there is a message sent or received in the test port, the actual message (data transmitted) still will be in the ttcn-3 format shown above.
Is there a way to convert this ttcn-3 structure (it's not a ttcn structure actually, its charstring returned by "Msg__port__recv.parameter()") into JSON or XML?
Thank you and best regards,
Naum
|
|
|
Re: Logging in Eclipse Titan part III: Custom logger plug-ins [message #1755289 is a reply to message #1755268] |
Thu, 02 March 2017 07:54 |
|
Hi Naum,
OK, I get it;
I would try str2ttcn (see refguide 4.13.9 ) which can extract a TTCN-3 template from a string :
module LogTest
{
import from ..... all;
const charstring c_log:="@OneM2M_TestSystem.M2MRequestPrimitive : { requestPrimitive_ := { operation := int1 (1), to_ := \"/mobius-yt\", from_ := \"/mobius-yt\", requestIdentifier := \"m_createAe\", resourceType := int2 (2), name := \"MyTestAe002\", content := { any_1 := { { AE_create := { name := \"MyTestAe002\", labels := { \"label_test\", \"ae_create\" }, accessControlPolicyIDs := omit, expirationTime := omit, announceTo := omit, announcedAttribute := omit, appName := omit, app_ID := \"myAppId\", pointOfAccess := { \"http://0.0.0.0:7579\", \"mqtt://0.0.0.0/:mobius-yt\" }, ontologyRef := omit, requestReachability := true } } } }, originatingTimestamp := omit, requestExpirationTimestamp := omit, resultExpirationTimestamp := omit, operationExecutionTime := omit, responseType := omit, resultPersistence := omit, resultContent := omit, eventCategory := omit, deliveryAggregation := omit, groupRequestIdentifier := omit, filterCriteria := <unbound>, discoveryResultType := <unbound> }, host := \"mobius:7579\", xmlNamespace := \"m2m=____preserved_1____quot;http://www.onem2m.org/xml/protocols____preserved_1____quot;\", protocolBinding := \"HTTP\", serialization := \"json\" }"
control{
var template M2MRequestPrimitive v_reqPrim
log(" ",str2ttcn(c_log,v_reqPrim ) )
}
}
Maybe it needs some formatting but basically should work.
If the extraction is successful, assuming that you have XML or JSON encoding functions for the type of the template ( M2MRequestPrimitive in this case) you can encode it to XML or JSON.
Maybe it's worth to take a look into log2str (refguide 4.13.5 ) as well.
All the above functions str2ttcn, log2str, codecs etc. should be accessible from C++.
It' a bit sketchy but maybe worth a try.
BR
Elemer
|
|
| |
Re: Logging in Eclipse Titan part III: Custom logger plug-ins [message #1774195 is a reply to message #1774193] |
Wed, 11 October 2017 13:59 |
|
Hi Naum,
not that I'm aware of;
the idea at the time was that Titan produces a raw output that will be further post-processed ;
as we are in the logger plug-in topic, I assume it's perfectly possible to write a plug-in that would do that , e.g.
by invoking the logformat utility, before writing it to a file or to the network.
BR
Elemer
|
|
| | |
Goto Forum:
Current Time: Fri Sep 20 22:10:02 GMT 2024
Powered by FUDForum. Page generated in 1.67607 seconds
|