Tapping The Default Qlik Sense Script Log

[ad_1]

Whilst Qlik provides ample system-wide logging, software particular logging stays quite 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 may make message customization and retrieval easy, efficient, and reusable.

Logging is significant to software building

Builders know that comments whilst setting up an software is significant. No software is constructed with out a couple of (or many!) mistakes and hurdles that have been unknown on the outset. The speedier the time between factor id and backbone, the more practical building will also be. That is the place logging is usually a important piece of the advance procedure.

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

  • Establish errant knowledge within the building cycle
  • Word any present or possible problems all the way through the upkeep section

Retaining wanted messages in an obtainable 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 are able to supply self belief that underlying processes are running as anticipated. For instance, they may in finding out whether or not a given document loaded with the predicted selection of rows or if sure box values have been provide.

Leveraging Qlik script logs

Qlik supplies many kinds of logging and no scarcity of data. Alternatively, the logging messages, log location and quantity makes them lower than pleasant to sift via. By means of default, Qlik shops its logs at %ProgramDatapercentQlikSenseLog as configured by means of the native log configuration document. By means of loading up the centered knowledge contained in those information after which programmatically sifting via it to spot related messages, we will output extra related and obtainable log information to a customized locale.

As a result of our goal is to offer software comments, we will be able to be taking a look completely on the script logs. Within the default set up, a Information Supply Connection known 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 at a loss for words with the DocumentTitle() which states the human-readable software identify.  

Qlik log information

Figuring out the site, naming conference, and content material lets in conceptual figuring out of the best way to achieve comments messages for builders or customers.  Alternatively, there are a number of hurdles that now provide themselves, no longer 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 quantity of what might be regarded as noise inside each and every log document. 

A handy guide a rough peek at this kind of many information unearths numerous knowledge that we simply gained’t want frequently.

Qlik script log

We will reasonably successfully cut back the selection of information searched by means of best taking into account the ones matching the appliance GUID identifier – observe the wildcard load clause for vLogID outlined within the hooked up document. 

Supposing that we will load those logs right into a Qlik software and filter out them, we will be able to temporarily in finding the want to upload particular knowledge to this document.  Thankfully, Qlik has supplied the TRACE serve as which no longer best writes to the output window all the way through 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

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

     TRACE My Log message;

If we prolong our TRACE message with a constant and distinctive prefix, then we will 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 totally 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 offer a run-time message inside the TRACE observation.  We’ll customise our log message by means of including variables for Person, Shopper, Software, a delimiter, and message Textual content.  Understand that we use the SET as an alternative of LET command to permit 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 and every software for which we need to deploy our logging serve as.  Due to this fact, we’ll specify our message from inside the TRACE observation 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);

By means of structuring the variable on this method, we will now program the variable task with a sub-routine to build our message in no matter method 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 write down up a callable sub habitual the use of Qlik’s SUB serve as.  Subroutines want to be positioned ahead of the script instructions during which they’re known as so they are able to be to be had.  You’ll be able to then invoke them with CALL when wanted.

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

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

The use of this construction, the logging and log document technology 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);
END SUB;
CALL LOG(‘Insert Message Right here’);

Abstracting from a Qlik software

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

    $(Must_Include=lib://<<FILEPATH>>/fxnGenerateAppLog.txt);
    //NOTE: <<FILEPATH>> represents the site made up our minds by means of document placement. 
    //HINT: If carried out inside 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 set default values for Prefix, Delim, Shopper, and a vPurgeDays variable to outline message retention.  You’ll be able to get admission to the entire code within the document under. Its utilization turns into easy. 

$(Must_Include=lib://<<FILEPATH>>/fxnGenerateAppLog.txt);
//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 observation; this will likely have various results on log overwriting relying on how that is carried out.  For instance, if log information are extra usefully stored by means of Shopper, the vMsgFile variable can merely be reset to vMsgClient. Constant use of the vMsgFile and vMsgPrefix will permit log consolidation.

Conclusion

By means of 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 enhance their building and shopper wishes. Satisfied logging!

Obtain the entire code right here.

Stay Studying: Again To The Fundamentals With Qlik >>

[ad_2]


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *