Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 Go to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 1120
Registered: January 2015
Senior Member
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 Smile ), 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 Go to previous messageGo to next message
Naum Spaseski is currently offline Naum SpaseskiFriend
Messages: 81
Registered: February 2016
Location: Sophia Antipolis
Member

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 #1754330 is a reply to message #1754316] Thu, 16 February 2017 12:22 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 1120
Registered: January 2015
Senior Member
Hi Naum,

I believe that the answer to your question is covered in ch 6.3 of the API guide: Logging in Test Ports or External Functions; ch 6.4 Error Recovery during Test Execution could also be relevant.

please let me know if I'm mistaken.


Best regards
Elemer
Re: Logging in Eclipse Titan part III: Custom logger plug-ins [message #1754335 is a reply to message #1754330] Thu, 16 February 2017 12:55 Go to previous messageGo to next message
Naum Spaseski is currently offline Naum SpaseskiFriend
Messages: 81
Registered: February 2016
Location: Sophia Antipolis
Member

Hi Elemer,

My question is actually, when the adapter/codec calls for example: TTCN_Logger::log(TTCN_DEBUG, "test message");, how I can get this string "test meesage" inside the TitanLoggerApi::TitanLogEvent object (or another that is used in the logger)?

Best regards,
Naum
Re: Logging in Eclipse Titan part III: Custom logger plug-ins [message #1754337 is a reply to message #1754335] Thu, 16 February 2017 13:22 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 1120
Registered: January 2015
Senior Member
Hi Naum,

do you have TTCN_DEBUG set in the file mask?

FileMask := LOG_ALL |....| TTCN_DEBUG

Please be aware that LOG_ALL does not include TTCN_DEBUG (nor MATCHING)

see Table 14 First level (coarse) log filtering in Ref.Guide

BR

Elemer



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 Go to previous messageGo to next message
Naum Spaseski is currently offline Naum SpaseskiFriend
Messages: 81
Registered: February 2016
Location: Sophia Antipolis
Member

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 := &lt;unbound>, discoveryResultType := &lt;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 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 1120
Registered: January 2015
Senior Member
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 := &lt;unbound>,
        discoveryResultType := &lt;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 #1755266 is a reply to message #1755255] Wed, 01 March 2017 20:38 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 1120
Registered: January 2015
Senior Member
Hi Naum,

if you want to have a structured log output, e.g. JSON or XML , then instead of the default text logger a custom logger plug-in could be used as described in the original post.
There's no such plug-in at the moment but it should not be very complicated to write one.

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 Go to previous messageGo to next message
Naum Spaseski is currently offline Naum SpaseskiFriend
Messages: 81
Registered: February 2016
Location: Sophia Antipolis
Member

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 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 1120
Registered: January 2015
Senior Member
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 := &lt;unbound>, discoveryResultType := &lt;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 #1774193 is a reply to message #1755289] Wed, 11 October 2017 13:54 Go to previous messageGo to next message
Naum Spaseski is currently offline Naum SpaseskiFriend
Messages: 81
Registered: February 2016
Location: Sophia Antipolis
Member

Hello Elemer,

a quick question: is it possible to have the ttcn3 structures (in the logs) properly indented before print (without using the ttcn3_logformat tool) ?

Thanks in advance.

Best regards,
Naum
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 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 1120
Registered: January 2015
Senior Member
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
Re: Logging in Eclipse Titan part III: Custom logger plug-ins [message #1774198 is a reply to message #1774195] Wed, 11 October 2017 14:54 Go to previous messageGo to next message
Naum Spaseski is currently offline Naum SpaseskiFriend
Messages: 81
Registered: February 2016
Location: Sophia Antipolis
Member

And can I invoke the logformat utility (or one of its functions) just to indent one part of the log i.e. one message? As of now, I didn't found a way to do it (logformat doesn't understand any other format than the titan log's format).

best regards,
Naum
Re: Logging in Eclipse Titan part III: Custom logger plug-ins [message #1774211 is a reply to message #1774198] Wed, 11 October 2017 17:43 Go to previous message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 1120
Registered: January 2015
Senior Member
Hi Naum,

I don't thinks such a feature is readily available.
I suppose it's possible though to extract a part of the log restricted to a message and then format it.
It has to be seen if the existing tools can be combined in a new way to get the desired functionality.

BR
Elemer



[Updated on: Wed, 11 October 2017 18:16]

Report message to a moderator

Previous Topic:TTCN Titan Testport for socketCAN
Next Topic:Support for using tpds (TITAN Project Descriptor) in Eclipse Titan
Goto Forum:
  


Current Time: Tue Apr 23 16:10:24 GMT 2024

Powered by FUDForum. Page generated in 0.03323 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top