Cleaning up the TM1 Message Log

Introduction

One of the text files on a TM1 system, is the TM1 message log. The file is called tm1server.log and it resides in the TM1 log folder. Usually, for backup reasons, this folder is separated from the TM1 data directory: it is the TM1s.cfg file that holds the location of both these vastly important directories. The TM1 message log contains a chronological log of quite a number of things in TM1:

  • TI Process executions (which TI process, when, by which user, process outcome, …)
  • All information regarding objects that are loaded when the TM1 server is loaded into memory;
  • Cubes that are seen as dependent on each other;
  • Chores that run;
  • And much more

Each time, the entry is marked as INFO or ERROR, indicating possible causes of concern in case the latter is true. There are other options too, for example DEBUG: they are not often needed to be set. If you do need it however, copy the tm1s-log.properties file into the folder where your TM1 configuration file (TM1s.cfg) houses, and set its entries accordingly. The message log can get very long, even though there are certain entries in that tm1s-log.properties file that can make sure the log file size remains under control:

  • MemorySize;
  • MaxFileSize;
  • MaxBackupIndex
In practice, there will be a trade-off between a manageable message log on the one hand, and the need to go back in time to verify the logs, on the other hand. If you do need to clean out the message log, however, you can do so (provided you have access and provided that you know what you are doing). In the end, the file is only a text file so it is not a big deal. Usually, you will want to use Notepad, Notepad++ or WordPad to change the file contents.

And now I come to the meat of this blog article. What about the following situation: in the absence of generic functions in Turbo Integrator (sic), you want to execute a custom TI process with parameters. That is not too difficult nor advanced, but if you execute the process, say, 100,000 times in a loop, there will be 200,000 entries in the message log. (In some extreme cases, you cannot do better than having that many ExecuteProcess statements.) As you are a proficient TM1 guy/gal who writes very fast TI processes, all entries could be showing as:

8456   []   INFO   2013-08-26 20:37:55.647   TM1.Process   Process "Calculate Hours":  finished executing normally, elapsed time 0.02 seconds
8456   []   INFO   2013-08-26 20:37:55.627   TM1.Process   Process "Calculate Hours" executed by user "Wim Gielis"
8456   []   INFO   2013-08-26 20:37:55.627   TM1.Process   Process "Calculate Hours":  finished executing normally, elapsed time 0.02 seconds
8456   []   INFO   2013-08-26 20:37:55.607   TM1.Process   Process "Calculate Hours" executed by user "Wim Gielis"
8456   []   INFO   2013-08-26 20:37:55.607   TM1.Process   Process "Calculate Hours":  finished executing normally, elapsed time 0.02 seconds
8456   []   INFO   2013-08-26 20:37:55.587   TM1.Process   Process "Calculate Hours" executed by user "Wim Gielis"
8456   []   INFO   2013-08-26 20:37:55.587   TM1.Process   Process "Calculate Hours":  finished executing normally, elapsed time 0.02 seconds
8456   []   INFO   2013-08-26 20:37:55.567   TM1.Process   Process "Calculate Hours" executed by user "Wim Gielis"
8456   []   INFO   2013-08-26 20:37:55.567   TM1.Process   Process "Calculate Hours":  finished executing normally, elapsed time 0.02 seconds
8456   []   INFO   2013-08-26 20:37:55.547   TM1.Process   Process "Calculate Hours" executed by user "Wim Gielis"
8456   []   INFO   2013-08-26 20:37:55.547   TM1.Process   Process "Calculate Hours":  finished executing normally, elapsed time 0.02 seconds
8456   []   INFO   2013-08-26 20:37:55.527   TM1.Process   Process "Calculate Hours" executed by user "Wim Gielis"
8456   []   INFO   2013-08-26 20:37:55.527   TM1.Process   Process "Calculate Hours":  finished executing normally, elapsed time 0.02 seconds
8456   []   INFO   2013-08-26 20:37:55.507   TM1.Process   Process "Calculate Hours" executed by user "Wim Gielis"
8456   []   INFO   2013-08-26 20:37:55.507   TM1.Process   Process "Calculate Hours":  finished executing normally, elapsed time 0.02 seconds
8456   []   INFO   2013-08-26 20:37:55.487   TM1.Process   Process "Calculate Hours" executed by user "Wim Gielis"
8456   []   INFO   2013-08-26 20:37:55.487   TM1.Process   Process "Calculate Hours":  finished executing normally, elapsed time 0.02 seconds
8456   []   INFO   2013-08-26 20:37:55.467   TM1.Process   Process "Calculate Hours" executed by user "Wim Gielis"
8456   []   INFO   2013-08-26 20:37:55.467   TM1.Process   Process "Calculate Hours":  finished executing normally, elapsed time 0.02 seconds
8456   []   INFO   2013-08-26 20:37:55.447   TM1.Process   Process "Calculate Hours" executed by user "Wim Gielis"
Imagine this goes on for another 99,990 times - not very appealing, is it? How about removing these lines with a small procedure?

VBA-code

You could do this in a number of ways:

  • VBScript or VBA-code
  • Turbo Integrator code
  • A different tool / programming language
For TI code, you will create a custom script that takes the tm1server.log file as data source, process the entries, create a new file with every record you still need (based on your own logic), delete the old tm1server.log and rename the created file to tm1server.log. Coding this should not be the end of the world. With VBA-code or VBScript, the coding can be easy if you happen to know some advanced tricks. Here is my custom VBA code:

Sub Clean_Up_Message_Log()
' Wim Gielis ' https://www.wimgielis.com
''''' ' Cleaning out the TM1 Message Log with VBA ' 08/26/13 '''''
Const MessageLog As String = "C:\TM1Logfiles\tm1server.log" Const DeleteWhat As String = "Process ""Calculate Hours""" 'get the file contents Open MessageLog For Input As #1 c0 = Input(LOF(1), #1) Close #1 'remove all unnecessary message log entries c0 = Join(Filter(Split(c0, vbCr), DeleteWhat, False), vbCr) 'write to the message log again Open MessageLog For Output As #1 Print #1, c0; Close #1
End Sub

The code above shows some nice tricks/constructs:

  • Opening a text file and filling a variable with its contents, requires 3 lines of code here;
  • After that, we split up the text file contents by Carriage return, filter out the entries with the desired text string, and join the remainder again with Carriage returns;
  • Writing the result to the text file again takes only 3 lines of code;
  • When writing to the text file again, we avoid extra line breaks at the bottom of the file, by putting the semicolon at the end of the Print statement.

That is all code it takes. Wanna try with other unnecessary message log entries in your TM1 message log? Please feel free to use these coding tricks in other projects of yours.

To continue towards a Turbo Integrator solution, here is the VBScript code:

' Wim Gielis ' https://www.wimgielis.com
''''' ' Cleaning out the TM1 Message Log with VBScript '''''
Const MessageLog As String = "C:\TM1Logfiles\tm1server.log" Const DeleteWhat As String = "TM1.Process Process ""Calculate Hours""" With CreateObject("Scripting.FileSystemObject") 'get the file contents With .OpenTextFile(MessageLog, 1) c0 = .ReadAll .Close End With 'remove all unnecessary message log entries c0 = Join(Filter(Split(c0, vbCr), DeleteWhat, False), vbCr) 'write to the message log again With .OpenTextFile(MessageLog, 2) .WriteLine Left(c0,Len(c0)-2) .Close End With End With

Lastly, the TI code that calls the VBS:

# Wim Gielis # https://www.wimgielis.com
##### # Calling a VBScript code through TI to clean up the TM Message Log #####
ExecuteCommand( 'cscript "clean_up_message_log.vbs"', 1);

Hereby I assume that you paste the .vbs file into the TM1 Data Directory (by default, in the absence of a path, TM1 will look for files in its Data Directory). Good luck with it and let me know when you can make my codes to good use.




Homepage

Section contents

About Wim

Wim Gielis is a Business Intelligence consultant and Excel expert

Other links