N.B. LogManager is being phased out and replaced with LogHandler (can be found here)
This is a very basic use of the LogManager
library to create a program which adds a line to a .log file.
The first thing we will have to do after creating a new project is to add the LogManager
library to the project, it can be found in the lib folder of your SIMPOL installation aslogmanager.sml
Base Program
This program so far only has two functions, the first being the main logic function which we will explore more in depth later, and the second is a function which simply outputs a newline constructor:
function new_line()
end function "{d}{a}"
The main function is split into two parts: first you have to declare the variables you will use in your program and then use them. Declartion is done as follows:
function main()
string result;
LogManager log_manager;
string log_file;
end function result
This function, when executed, does nothing (well it returns .nul
). We are declaring three variables: two strings, one of which will be used as the console output and the other will be used to give the filename for the file to which we will write. We are then also declaring a LogManager variable?. The next part of the program is setting values to these variables
function main() string result; LogManager log_manager; string log_file;
result = "Start log test application" + new_line(); log_file = "debug.log" log_manager =@ LogManager.new();
end function result
The first thing we doing is very simple, we are changing the output for the function to something more useful. This consists of some debug text followed by a new line. The next thing we are doing is giving the file name to which we will be writing. And finally we are creating a new LogManager function?? to…
The final piece of code we are inserting will actually, finally, write something to a file:
log_manager.writeLogEntry(log_file, "Add a debug entry");
This function will write to the file we have specified with log_file
with the message "Add a debug entry"
as well as the current date and time