SBM ModScript Reference → Programming SBM ModScript → Application Objects → Object Types → Log
(On-premise only)
A class for writing output messages and appending an output log file. Optionally, datestamps can be pre-pended to output messages.
Log(): Creates a log object.
Open( s ): Opens the log object pointing to file "s". "s" contains the file name and sub-path (if desired) to be appended to the AE "log" folder path. If a sub-path is requested, that folder must already exist on the OS. Returns true if successful.
Return: (bool)
Close(): Closes the log.
SetBackUpLogFile( bool v ): If called with a true value, if the log size exceeds the SetMaxSize, the log will rename the file with a date stamp in the new name, and start a fresh file with the original name. See SetMaxSize for the size that triggers this behavior. Returns bool value passed in. (default: false). If this is set to False, when the SetMaxSize is reached, ALL previous log data will be lost. This is the default behaivor if SetBackUpLogFile is not set.
Return: (bool)
SetMaxSize( v ): Number of bytes the log file should grow to before it is truncated. Returns int value passed in. (default: 20971520 bytes)
Return: (int)
Note the following:
SetWantTimeStamp( bool v ): Determines if you want the log to add timestamps to entries. Returns bool value passed in. (default: true).
Return: (bool)
SetReportingLevel( int v ): Expects an integer value, from 1 to 4; constant values are available by using the member functions NONE through VERBOSE, or using the LogLevelConstants global, which has members NONE through VERBOSE. Calls to "Message" functions with a higher value will be ignored. This allows code to be written that writes frequent log messages at the VERBOSE level, but perhaps most of those messages can be ignored most of the time when not debugging, so the log level is set to MINIMAL unless the script writer is debugging. Returns int value passed in. (default: AVERAGE)
Return: (int)
IsOpen(): Returns true if the log is open.
Return: (bool)
GetFileName(): Returns file name log has been opened with (including full system path).
Return: (string)
GetReportingLevel(): Returns the current logging level as an integer, from 1 to 4, constant values are available by using the member functions NONE through VERBOSE, or using the LogLevelConstants global, which has members NONE through VERBOSE. See SetReportingLevel.
Return: (int)
int NONE(): Returns the constant value 1. Used with SetReportingLevel.
int MINIMAL(): Returns the constant value 2. Used with SetReportingLevel.
int AVERAGE(): Returns the constant value 3. Used with SetReportingLevel.
int VERBOSE(): Returns the constant value 4. Used with SetReportingLevel.
Message( level, v ): Write a message to the log using the level provided (if the log is set to a lower level than the level passed in, this message will be ignored and not written to the log). See comments on SetReportingLevel.
Message( level, fmt, v0 [, v1 [, v2 [, v3 [, v4 ]]]]): Write a message to the log using the level provided (if the log is set to a lower level than the level passed in, this message will be ignored and not written to the log). See comments on SetReportingLevel. The "fmt" parameter is a format string with places for up to five values in it. Those places are encoded in the string in {0} format, where the number is the zero based index of the parameter to be placed in that location. Indexes can be repeated in the format string if that variable should be placed into the string more than one time. Literal "{" must be escaped by single ticks, literal single ticks must be escaped by single ticks.
Example:
//Basic example of working with the Log class
var filePath = "Script.log";
//Creates a Log Object
var myLog = Log();
//Opens the Log Object
var isOpened = myLog.Open( filePath );
myLog.Message(1, "Is log opened " + isOpened);
//Starts a new Log file when MaxSize is reached
var backUpFileSet = myLog.SetBackUpLogFile("True");
//Sets the number of bytes the log file should grow to before it is truncated
var maxSize = myLog.SetMaxSize(10485760);
//Adds timestamps to the entries
var wantTimeStamp = myLog.SetWantTimeStamp("True");
//Returns the current logging level
myLog.Message(1, "Log reporting level: " + myLog.GetReportingLevel());
//Sets the log reporting level to Minimal
reportLevel = myLog.SetReportingLevel(LogLevelConstants.MINIMAL);
myLog.Message(myLog.NONE(), "Message level NONE" );
myLog.Message(2,"Message level MINIMAL" );
myLog.Message(LogLevelConstants.VERBOSE(), "Message level VERBOSE" );
//Logs the message with frmt (format string)
myLog.Message(3, "Testing the {0} {1} to check that '{0}' {1}s to {0}. {2}, {3}, {4}",
"STRING", "FORMAT", 2, 3, 4);
//Closes the Log Object
myLog.Close();
Copyright © 2007–2017 Serena Software, Inc. All rights reserved.