Home Business Analytics Tapping The Default Qlik Sense Script Log

Tapping The Default Qlik Sense Script Log

0
Tapping The Default Qlik Sense Script Log

[ad_1]

Whereas Qlik presents considerable system-wide logging, utility particular logging stays considerably inaccessible. Furthermore, it’s troublesome to configure and requires parsing to acquire what’s required. On this article, we’ll assemble a customized operate that leverages current Qlik Script logging. It will make message customization and retrieval easy, efficient, and reusable.

Logging is vital to utility growth

Builders know that suggestions whereas establishing an utility is vital. No utility is constructed with no few (or many!) errors and hurdles that have been unknown on the outset. The faster the time between situation identification and backbone, the more practical growth will be. That is the place logging could be a vital piece of the event course of.

There are a lot of causes to allow your functions to ship suggestions. However these two are arguably a very powerful:

  • Establish errant information within the growth cycle
  • Notice any present or potential points in the course of the upkeep part

Retaining wanted messages in an accessible place will be the distinction in a single’s sanity. Whether or not that’s in a Qlik app or easy textual content logs. Relying on the messages created, it’s also possible to make logs obtainable to utility customers; they will present confidence that underlying processes are working as anticipated. For instance, they might discover out whether or not a given file loaded with the anticipated variety of rows or if sure subject values have been current.

Leveraging Qlik script logs

Qlik gives many kinds of logging and no scarcity of knowledge. Nonetheless, the logging messages, log location and quantity makes them lower than pleasant to sift by way of. By default, Qlik shops its logs at %ProgramDatapercentQlikSenseLog as configured by the native log configuration file. By loading up the focused info contained in these recordsdata after which programmatically sifting by way of it to establish related messages, we will output extra related and accessible log recordsdata to a customized locale.

As a result of our objective is to supply utility suggestions, we will likely be wanting completely on the script logs. Within the default set up, a Information Supply Connection known as ’ServerLogFolder’ is made obtainable for log inquiry functions. Perusing the ‘Script’ folder by way of this information supply connection, we discover a multitude of cryptically labeled recordsdata. The names of those recordsdata correspond to the underlying utility identifier generally known as the DocumentName() – to not be confused with the DocumentTitle() which states the human-readable utility title.  

Qlik log recordsdata

Understanding the situation, naming conference, and content material permits conceptual understanding of the best way to purchase suggestions messages for builders or customers.  Nonetheless, there are a number of hurdles that now current themselves, not least of which is the amount of log recordsdata obtainable (particularly in a bigger or growing older set up) in addition to the quantity of what could possibly be thought of noise inside every log file. 

A fast peek at considered one of these many recordsdata reveals plenty of info that we simply gained’t want frequently.

Qlik script log

We will fairly successfully cut back the variety of recordsdata searched by solely contemplating these matching the applying GUID identifier – notice the wildcard load clause for vLogID outlined within the connected file. 

Supposing that we will load these logs right into a Qlik utility and filter them, we’ll shortly discover the necessity to add particular info to this file.  Thankfully, Qlik has supplied the TRACE operate which not solely writes to the output window throughout logging but additionally to the Scripts log.  Loading and filtering the log for customized statements are the foundational parts upon which we’ll construct our log tapping operate.

1: Including Log Messages by way of Hint

By merely including the next line to any Qlik utility, the present respective log file recognized by the DocumentName (or app GUID) will include the designated message.

     TRACE My Log message;

If we lengthen our TRACE message with a constant and distinctive prefix, then we will filter the applying log for any of our messages.

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

Now we will 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 assertion.  We’ll customise our log message by including variables for Person, Shopper, Software, a delimiter, and message Textual content.  Discover that we use the SET as a substitute 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 these variables and structuring their storage and eventual output is programming that we need to do for each utility for which we need to deploy our logging operate.  Due to this fact, we’ll specify our message from inside the TRACE assertion with as little added effort as attainable utilizing this Dynamic Variable. The one enter we want at logging time is the message.

     TRACE $(vLog);

By structuring the variable on this means, we will now program the variable task with a sub-routine to assemble our message in no matter means we would like by calling the dynamic variable.

3: Reuse Code with SubRoutines and MustInclude

We’re now prepared to start writing a selected operate to assemble our log.  The tactic right here is to put in writing up a callable sub routine utilizing Qlik’s SUB operate.  Subroutines should be positioned earlier than the script instructions wherein they’re known as to allow them to be obtainable.  You’ll be able to then invoke them with CALL when wanted.

To exhibit, we’ll begin 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));

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

Abstracting from a Qlik utility

We’ll make a brief departure now to debate abstracting this from any particular person Qlik utility right into a operate you’ll be able to leverage throughout functions with just some instructions. Copying the code right into a textual content file and saving it to a Qlik accessible location permits us to INCLUDE our new operate inside any utility on our set up. Use this code:

    $(Must_Include=lib://<<FILEPATH>>/fxnGenerateAppLog.txt);
    //NOTE: <<FILEPATH>> represents the situation decided by file placement. 
    //HINT: If accomplished inside an current information supply connection no further setup is required.

Combining the embody and subroutine capabilities ensures – with a single line of code – that our variables are initialized, and our subroutines are outlined and obtainable 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 entry the whole code within the file under. Its utilization turns into simple. 

$(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 utility to consolidate and write log file.
CALL GenerateAppLog;

Within the fxnGenerateAppLog.txt file you’ll discover variables and definitions, a very powerful of which to setup is the output file location, vLogOutput.  Once more, utilizing an already outlined information supply location,you are able to do this simply with out further configuration. Nonetheless, you’ll be able to customise because the surroundings calls for. You’ll be able to customise variables AFTER the embody assertion; this may have various results on log overwriting relying on how that is accomplished.  For instance, if log recordsdata are extra usefully saved by Shopper, the vMsgFile variable can merely be reset to vMsgClient. Constant use of the vMsgFile and vMsgPrefix will enable log consolidation.

Conclusion

By tapping Qlik’s default logging scheme and making use of the ideas of TRACE, Dynamic Variables, subroutines and embody statements builders could make customizable logging options to assist their growth and client wants. Blissful logging!

Obtain the whole code right here.

Preserve Studying: Again To The Fundamentals With Qlik >>

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here