# MTLog

This interface allows plug-ins a facility to write to the system log.

## Program ID

MetraPipeline.MTLog.1

## MTLog Methods

Init | The Init method initializes the Logger with the logging.xml file in the specified relative configuration path and the application tag.
OKToLog | Asks if a message would be logged at this level.
LogString | Logs the specified message to the MetraTech log file if the log level is set to the appropriate level.

## Example

It may be useful to determine the log level the system is configured to run before logging a message. This is especially useful if the string to be logged requires significant processing. If the specified log level is configured on the system, the OKToLog method returns a Boolean result. A sample use of OKToLog follows:

if(mLogger->OKToLog(MTPipelineLib::PLUGIN_LOG_DEBUG))
{
char buffer[1024];
//perform complicated string processing
mLogger->LogString(PLUGIN_LOG_DEBUG,buffer);
}

To pass the log level and string, use the following LogString() function:

mLogger->LogString(MTPipelineLib::PLUGIN_LOG_DEBUG, "log string")

The Pipeline server reads the log level to determine whether to log the information. For example, if the log level is set to 3 [WARNING], information with a level of 4 [INFO] and 5 [DEBUG] is not logged.

# Method Detail

## Init

The Init method initializes the Logger with the logging.xml file in the specified relative configuration path and the application tag.

If a logging.xml file is not present in the relative configuration path, the default logging.xml file (in Logging) is used. The application tag is the tag that is written at the beginning of the log messages in the MetraTech Log.

### Visual Basic Syntax

Sub Init(apConfigPath As String, apAppTag As String)

### C++ Syntax

HRESULT Init([in] BSTR apConfigPath, [in] BSTR apAppTag);

### Arguments

apConfigPath

The relative configuration path to the logging.xml file.

apAppTag

The tag that precedes logged error messages.

## OKToLog

Asks if a message would be logged at this level. Returns true if a message logged at the given level would be entered into the log. That is, this method compares the current system logging level with the passed in parameter, and determines if a message of this level will be logged.

### Visual Basic Syntax

Sub OKToLog(aLogLevel as PlugInLogLevel, wouldLog as Boolean)

### C++ Syntax

HRESULT OKToLog([in] PlugInLogLevel aLogLevel, [out,retval] VARIANT_BOOL * wouldLog);

### Arguments

aLogLevel

The logging level to compare against.

wouldLog

A boolean value; True if a message at this level would be logged, False otherwise.

## LogString

The LogString method logs the specified message to the MetraTech log file, if the log level is set to the appropriate level.

### Visual Basic Syntax

Sub LogString(aLogLevel As PlugInLogLevel, apData As String)

### C++ Syntax

HRESULT LogString([in] PlugInLogLevel aLogLevel, [in] BSTR apData);

### Arguments

aLogLevel

The log level at which the messages will be logged.

apData

The message to be logged.

# Enumerated Types Detail

## PlugInLogLevel

Listed from highest to lowest level: The system logs all messages that are at or above the current level.

PLUGIN_LOG_OFF = 0
PLUGIN_LOG_FATAL = 1
PLUGIN_LOG_ERROR = 2
PLUGIN_LOG_WARNING = 3
PLUGIN_LOG_INFO = 4
PLUGIN_LOG_DEBUG = 5