Saturday, April 13, 2024

Tapping The Default Qlik Sense Script Log


Whilst Qlik provides ample system-wide logging, software particular logging stays fairly inaccessible. Additionally, it’s tricky to configure and calls for parsing to acquire what is needed. On this article, we’ll assemble a customized serve as that leverages current Qlik Script logging. This will likely make message customization and retrieval easy, efficient, and reusable.

Logging is important to software construction

Builders know that comments whilst developing an software is important. No software is constructed with out a couple of (or many!) mistakes and hurdles that had been unknown on the outset. The speedier the time between factor id and backbone, the simpler construction will also be. That is the place logging could be a essential piece of the improvement procedure.

There are lots of causes to allow your packages to ship comments. However those two are arguably a very powerful:

  • Establish errant knowledge within the construction cycle
  • Observe any present or doable problems all over the upkeep section

Protecting wanted messages in an available position will also be the variation in a single’s sanity. Whether or not that’s in a Qlik app or easy textual content logs. Relying at the messages created, you’ll additionally make logs to be had to software customers; they may be able to supply self belief that underlying processes are working as anticipated. As an example, they might in finding out whether or not a given document loaded with the anticipated selection of rows or if positive box values had been provide.

Leveraging Qlik script logs

Qlik supplies many forms of logging and no scarcity of data. Alternatively, the logging messages, log location and quantity makes them not up to pleasant to sift via. Through default, Qlik shops its logs at %ProgramDatap.cQlikSenseLog as configured by means of the native log configuration document. Through loading up the focused data contained in those information after which programmatically sifting via it to spot related messages, we will be able to output extra related and available log information to a customized locale.

As a result of our objective is to supply software comments, we will be able to be having a look solely on the script logs. Within the default set up, a Knowledge Supply Connection referred to as ’ServerLogFolder’ is made to be had for log inquiry functions. Perusing the ‘Script’ folder by means of this information supply connection, we discover a multitude of cryptically categorised information. The names of those information correspond to the underlying software identifier referred to as the DocumentName() – to not be puzzled with the DocumentTitle() which states the human-readable software title.  

Qlik log information

Figuring out the positioning, naming conference, and content material lets in conceptual figuring out of find out how to achieve comments messages for builders or customers.  Alternatively, there are a number of hurdles that now provide themselves, now not least of which is the quantity of log information to be had (particularly in a bigger or getting old set up) in addition to the volume of what may well be regarded as noise inside of every log document. 

A handy guide a rough peek at the sort of many information finds a large number of data that we simply gained’t want regularly.

Qlik script log

We will moderately successfully cut back the selection of information searched by means of best making an allowance for the ones matching the appliance GUID identifier – be aware the wildcard load clause for vLogID outlined within the connected document. 

Supposing that we will be able to load those logs right into a Qlik software and filter out them, we will be able to temporarily in finding the wish to upload particular data to this document.  Thankfully, Qlik has equipped the TRACE serve as which now not best writes to the output window all over logging but additionally to the Scripts log.  Loading and filtering the log for customized statements are the foundational elements upon which we’ll construct our log tapping serve as.

1: Including Log Messages by means of Hint

Through merely including the next line to any Qlik software, the present respective log document recognized by means of the DocumentName (or app GUID) will comprise the designated message.

     TRACE My Log message;

If we lengthen our TRACE message with a constant and distinctive prefix, then we will be able to filter out the appliance log for any of our messages.

     SET vPrefix=mymsg;
     TRACE $(vPrefix) - My Log message;
     TRACE $(vPrefix) - Finish Software construct;

Now we will be able to utterly customise our message with variables and ship it to the TRACE command.

2: Leverage dynamic variables to specify customized message

A dynamic variable is assigned programmatically on the time it’s run.  We will outline the vLog enter as under to supply a run-time message inside the TRACE commentary.  We’ll customise our log message by means of including variables for Person, Consumer, Software, a delimiter, and message Textual content.  Realize that we use the SET as an alternative of LET command to allow the dynamic variable growth at run time.

    SET vLog = '$(vDelim)$(vMsgPrefix)$(vDelim)$(vMsgUser)$(vDelim)$(vMsgClient)$(vDelim)$(vMsgApp)$(vDelim)$(vMsgText)';

Assigning those variables and structuring their garage and eventual output is programming that we need to do for each software for which we need to deploy our logging serve as.  Subsequently, we’ll specify our message from inside the TRACE commentary with as little added effort as conceivable the use of this Dynamic Variable. The one enter we want at logging time is the message.

     TRACE $(vLog);

Through structuring the variable on this manner, we will be able to now program the variable project with a sub-routine to build our message in no matter manner we would like by means of calling the dynamic variable.

3: Reuse Code with SubRoutines and MustInclude

We’re now in a position to start writing a particular serve as to build our log.  The process here’s to jot down up a callable sub ordinary the use of Qlik’s SUB serve as.  Subroutines wish to be positioned sooner than the script instructions through which they’re referred to as so they may be able to be to be had.  You’ll be able to then invoke them with CALL when wanted.

To exhibit, we’ll get started with a easy variable project for the App GUID and a log message.

     SUB GenerateAppLog
           LET vLogID=DocumentName()&' - $1';
     END SUB;
     CALL GenerateAppLog;
     TRACE $(vLogID(My Log message));

The usage of this construction, the logging and log document era is coded and is made callable.  The Log subroutine is under:

SUB LOG (vMsgText)
     SET vLog = '$(vDelim)$(vMsgPrefix)$(vDelim)$(vMsgUser)$(vDelim)$(vMsgClient)$(vDelim)$(vMsgApp)$(vDelim)$(vMsgText)';
     TRACE $(vLog);
CALL LOG(‘Insert Message Right here’);

Abstracting from a Qlik software

We’ll make a brief departure now to speak about abstracting this from someone Qlik software right into a serve as you’ll leverage throughout packages with only some instructions. Copying the code right into a textual content document and saving it to a Qlik available location lets in us to INCLUDE our new serve as inside of any software on our set up. Use this code:

    //NOTE: <<FILEPATH>> represents the positioning decided by means of document placement. 
    //HINT: If accomplished inside of an current knowledge supply connection no further setup is needed.

Combining the come with and subroutine purposes guarantees – with a unmarried line of code – that our variables are initialized, and our subroutines are outlined and to be had for our use.  That is the place we will be able to set default values for Prefix, Delim, Consumer, and a vPurgeDays variable to outline message retention.  You’ll be able to get admission to all the code within the document under. Its utilization turns into simple. 

//Optionally customise vMsgXXXX variables
//LET vMsgFile = $(vMsgClient);
//LET vMsgPrefix = 'ABC';

CALL LOG ('Insert Message Right here');

//Positioned at finish of software to consolidate and write log document.
CALL GenerateAppLog;

Within the fxnGenerateAppLog.txt document you’ll in finding variables and definitions, a very powerful of which to setup is the output document location, vLogOutput.  Once more, the use of an already outlined knowledge supply location,you’ll do that simply with out further configuration. Alternatively, you’ll customise as the surroundings calls for. You’ll be able to customise variables AFTER the come with commentary; this will likely have various results on log overwriting relying on how that is accomplished.  As an example, if log information are extra usefully saved by means of Consumer, the vMsgFile variable can merely be reset to vMsgClient. Constant use of the vMsgFile and vMsgPrefix will permit log consolidation.


Through tapping Qlik’s default logging scheme and making use of the ideas of TRACE, Dynamic Variables, subroutines and come with statements builders could make customizable logging answers to make stronger their construction and shopper wishes. Satisfied logging!

Obtain all the code right here.

Stay Studying: Again To The Fundamentals With Qlik >>


Please enter your comment!
Please enter your name here

Related Stories