EndFileLog.ds

Review the EndFileLog.ds referenced script files when scheduling inventory imports.

Note: This code is provided as a sample. It isn't a supported part of the SiteGenesis application.
/***********************************************************  
 * Name: EndFileLog.ds
 *
 * Description:
 *  Resets FileLogger to stop writing all logging events to file.
 *  This replaces the FileLogger with a normal logger in the pdict.
 *
 * @input sampleLogger   : Object
 * @output sampleLogger  : Object
 * @output sampleError   : Object
 *
 ***********************************************************/
importScript("bc_sample:library/common/libContext.ds");
importScript("bc_sample:library/utility/exception/libsampleException.ds");
importScript("bc_sample:library/utility/logging/libLog.ds");



function execute(pdict: PipelineDictionary): Number {



    var _context: Context = new Context("EndFileLog.ds");
    var _logger: Log = pdict.sampleLogger;

    try {

        if (empty(_logger)) {

            throw new sampleException(_context,
                "No Log instance found. " +
                "Make sure the corresponding 'BeginFileLog' pipelet was set on this pipeline.");
        }

        _logger.debug(_context, "Now stopped logging to file.");

        if (FileLog.prototype.isPrototypeOf(_logger)) {

            // resets logger to the original instance  
            pdict.sampleLogger = _logger.getBaseLogger();
        } else {

            // resets logwriter on logger
            _logger.setLogWriter(null);
            pdict.sampleLogger = _logger;
        }
    } catch (e) {

        // Call into error handler
        _logger.error(_context, "Error occurred processing pipelet: " + e.message);

        // wrap error into custom exception
        var exception: sampleException = new sampleException(_context, "Error occured in pipelet", e);
        pdict.sampleError = exception;

        return PIPELET_ERROR;
    }

    return PIPELET_NEXT;
}