setLogLevel

The setLogLevel method sets the log level for error and message reporting.

Method Synopsis

setLogLevel($loglevel)

Parameters

$loglevel
Specifies the log level to set. The following are the valid options described in ascending order:
  • debug — Specifies a log level in which all messages are logged.
  • info — Specifies a log level in which informational, warning, and critical messages are logged.
  • warn — Specifies a log level in which warning and critical messages are logged.
  • critical — Specifies a log level in which only critical messages are logged.

Description

The setLogLevel method sets the log level to the option specified in the $loglevel parameter. The default is debug level. If set to a higher level, only messages with an equal or higher level will be logged. For example, at level warn, messages of level info and level debug will not be logged.

By default, the NCP::Domain module methods log messages to STDOUT. If you specify a log handle to the setLogHandle method, the NCP::Domain module methods log messages to the opened file associated with this log handle.

The setLogLevel method logs an appropriate message (either to STDOUT or to an opened file) if you specify an invalid log level.

Example Usage

The example that illustrates a call to the setLogLevel method is divided into the following sections:

  • Create a new NCP::Domain object
  • Call setLogHandle to log messages to a specified open file
  • Call setLogLevel to set the log level

Create a new NCP::Domain object

The following code shows a call to the NCP::Domain constructor, which returns a new NCP::Domain object to the $domain variable. The name of the domain is specified in $domainName in the call to the NCP::Domain constructor:

.
.
.
my $domain = new NCP::Domain($domainName, %$ncimArgs);
.
.
.

Call setLogHandle to log messages to a specified open file

The following code shows an invocation of the setLogHandle method on the NCP::Domain object ($domain->). The call to the setLogHandle method ensures that any messages get logged to an open file (stored in the $logFile local variable) rather than to STDOUT:

.
.
.
my $logName = "$logdir/checkDomain.$domainName.log";

    my $logFile = new IO::File;
    $logFile->open(">$logName") or die "Could not open log file $logName\n";
    $domain->setLogHandle($logFile);
.
.
.

Call setLogLevel to set the log level

The following code shows that the setLogLevel method is invoked on the NCP::Domain object ($domain->). The call to setLogLevel specifies the logging of messages at the warn and critical levels.

.
.
.
$domain->setLogLevel("warn");
.
.
.

Returns

Upon completion, the setLogLevel method returns no data.

See Also