Using LogOutput in a condensed way

Introduction

In TM1 we write and execute processes to load data, copy data, move data, make custom calculations, and so on. These processes can be made generic by using custom parameters. Examples include pYear, pPeriod, pScenario, pVersion, pCompany. However, when executing such a process, there is no standard and built-in way to keep track of the parameter values of the user. I would like to offer the LogOutput function (refer to here and here as of TM1 10.2.2 onwards) to do this task. Below you will find code that you can use and re-use. The idea is to specify the call to the function in a rather neat and condensed way, such that it can be easily applied in different processes.

LogOutput( 'DEBUG', 'a line with DEBUG' );
LogOutput( 'INFO', 'a line with INFO' );
LogOutput( 'WARN', 'a line with WARN' );
LogOutput( 'ERROR', 'a line with ERROR' );
LogOutput( 'FATAL', 'a line with FATAL' );
		

We assume here parameters pScenario, pVersion, pYear, pMonth. For example: pScenario = 'Budget'; pVersion = 'Final Version'; pYear = '2020'; pMonth = 'Mar';

Then we could write a one-liner:

pProcess = GetProcessName;
pScenario = 'Budget';
pVersion = 'Final Version';
pYear = '2020';
pMonth = 'Mar';

LogOutput( 'INFO', Char( 10 ) | Char( 9 ) | '''pProcess'' = ' | pProcess | Char( 10 ) | Char( 9 ) | '''pScenario'' = ' | pScenario | Char( 10 ) | Char( 9 ) | '''pVersion'' = ' | pVersion | Char( 10 ) | Char( 9 ) | '''pYear'' = ' | pYear | Char( 10 ) | Char( 9 ) | '''pMonth'' = ' | pMonth );
		

Char( 9 ) is a Tab character. Char( 10 ) conveniently gives us line breaks and an output that is broken down over multiple lines:

But this syntax can become rather long and not easy to understand / adjust. Variation 2 uses the Expand function:

Sep = Char( 10 ) | Char( 9 );
LogOutput( 'INFO', Expand( '%Sep%''pProcess'' = %pProcess%%Sep%''pScenario'' = %pScenario%%Sep%''pVersion'' = %pVersion%%Sep%''pYear'' = %pYear%%Sep%''pMonth'' = %pMonth%' ));
		

We use a variable "Sep" to hold the separator: an Enter and a Tab character. As you can see, this will reduce the clutter a bit but it's still not very suitable. But we notice twice the names of the different parameters.

We can also use "Eq" as a variable to hold the code for the equal sign, and immediately make "Sep" more useful:

Sep = Char( 10 ) | Char( 9 ) | Char( 39 ); Eq = Char( 39 ) | ' = ';
LogOutput( 'INFO', Expand( '%Sep%pProcess%Eq%%pProcess%%Sep%pScenario%Eq%%pScenario%%Sep%pVersion%Eq%%pVersion%%Sep%pYear%Eq%%pYear%%Sep%pMonth%Eq%%pMonth%' ));
		

The last approach is probably the most useful one in practice. It uses more space but it is much more readable and easy to extend for those who are not too familiar with scripting in general:

Sep = Char( 10 ) | Char( 9 ) | Char( 39 ); Eq = Char( 39 ) | ' = ';
pP = '%Sep%pProcess%Eq%'|GetProcessName;
p1 = '%Sep%pScenario%Eq%%pScenario%';
p2 = '%Sep%pVersion%Eq%%pVersion%';
p3 = '%Sep%pYear%Eq%%pYear%';
p4 = '%Sep%pMonth%Eq%%pMonth%';
LogOutput( 'INFO', Expand( Expand( '%pP%%p1%%p2%%p3%%p4%' )));
		

We notice again 4 variables, and also the process name is part of the LogOutput function. In case of more (or less) variables, just add (or remove) a new "p with a number variable" and change the code within the Expand function. Each parameter is used twice in defining the new p variables.

Please note the double Expand function: calling this function once will not be sufficient since we have layered variables in terms of "px".




Homepage

Section contents

About Wim

Wim Gielis is a Business Intelligence consultant and Excel expert

Other links