Quoting the SNAP Reference Manual: "Since Portal runs on a PC, its script executes in a full Python environment with access to the many libraries, services, and capabilities there."
One example of a capability that you can make use of from Portal is Python's logging capabiility. The attached script shows a quick example of one way to do this. Put logSupport.py in your Portal directory, and then in any script that needs to log something to a file, do:
import logSupport
...
...
...
logSupport.logToFile(root, "MYLOG", "some text goes here")
The first parameter is some object that can be considered the "owner" of the log file (this allows having multiple active log files, just give them distint owner objects).
The second parameter is the "base name" for the log file.
The third parameter is the text to be logged. If you want to include numeric data in the log, simply format up a string containing all the component data.
formattedTemperature = "Temperature is " + str(temperature) + " degrees"
logSupport.logToFile(root, "LOGFILE", formattedTemperature)
In this example, files are rolled over at midnight, and given names that include the date. Each entry into the file is prefixed by a timestamp.
All of these formatting decisions could be changed by customizing logSupport.py
One example of a capability that you can make use of from Portal is Python's logging capabiility. The attached script shows a quick example of one way to do this. Put logSupport.py in your Portal directory, and then in any script that needs to log something to a file, do:
import logSupport
...
...
...
logSupport.logToFile(root, "MYLOG", "some text goes here")
The first parameter is some object that can be considered the "owner" of the log file (this allows having multiple active log files, just give them distint owner objects).
The second parameter is the "base name" for the log file.
The third parameter is the text to be logged. If you want to include numeric data in the log, simply format up a string containing all the component data.
formattedTemperature = "Temperature is " + str(temperature) + " degrees"
logSupport.logToFile(root, "LOGFILE", formattedTemperature)
In this example, files are rolled over at midnight, and given names that include the date. Each entry into the file is prefixed by a timestamp.
All of these formatting decisions could be changed by customizing logSupport.py
Comment