TCL : Useful proc to write message to log file

Logging application activity to a log file is a best practice to do by a programmer. Here is how we can do it in Tcl scripting language.

Line 1 to 7 is a proc definition named writelog with a parameter. Parameter will contain message to be written to log file located in d:/applogYYYYMMDD.txt based on current date of clock command. Different day will have a different log file.

Line 9 to 17 is some test to writelog. If we pass hello as parameter to writelog command then “YYYY-MM-DD HH:mm:ss : hello” will be written to log file. Every call to writelog will create new line and put current date time on the beginning of line.

Bye!

 

Leave a Reply

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