Unfortunately, since logging is set up early in the Initialization
phase of your AL, you can't use substitution (TDI Expressions) to set
the log file name. So you'll have to script a little.
The simplest approach would be something along the lines of this:
AL Prolog Hook (e.g. Before Initialize)
---
logfile = system.openFileForOutput("logs/"
+ work.serviceName + "_"
+ system.formatDate(new java.util.Date(),"YYYY-MM-DD hh:mm"))
---
Assuming there is an Attribute in work called 'serviceName'. Then when
you want to log something, instead of task.logmsg() you do:
---
logfile.write("some message")
logfile.newLine() // adds newline char(s), depending on platform
---
You could even wrap this in your own scripted function, and then write
messages out to the console so that when the solution is deployed, the
admin will see log messages:
---
function log(msg) {
// using 'lazy init' here: create logfile if it doesn't exist, e.g.
first call to log()
if (typeof(logfile) == "undefined") {
logfile = system.openFileForOutput("logs/"
+ work.serviceName + "_"
+ system.formatDate(new java.util.Date(),"YYYY-MM-DD
hh:mm"))
}
logfile.write(msg)
logfile.newLine()
java.lang.System.out.println(msg)
}
---
With the 'lazy init' approach above, you don't need the Prolog script
at the top of this post. Instead, this last snippet could either be in
a Prolog Hook, or in a Resources library script that you include as a
'Global Prolog' for the AL.
Hope this helps!
-Eddie