EndFileLog.ds

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

This code is provided as a sample. It isn’t a supported part of the SiteGenesis application.

Note

1/***********************************************************
2 * Name: EndFileLog.ds
3 *
4 * Description:
5 *  Resets FileLogger to stop writing all logging events to file.
6 *  This replaces the FileLogger with a normal logger in the pdict.
7 *
8 * @input sampleLogger   : Object
9 * @output sampleLogger  : Object
10 * @output sampleError   : Object
11 *
12 ***********************************************************/
13importScript("bc_sample:library/common/libContext.ds");
14importScript("bc_sample:library/utility/exception/libsampleException.ds");
15importScript("bc_sample:library/utility/logging/libLog.ds");
16
17
18
19function execute(pdict: PipelineDictionary): Number {
20
21
22
23    var _context: Context = new Context("EndFileLog.ds");
24    var _logger: Log = pdict.sampleLogger;
25
26    try {
27
28        if (empty(_logger)) {
29
30            throw new sampleException(_context,
31                "No Log instance found. " +
32                "Make sure the corresponding 'BeginFileLog' pipelet was set on this pipeline.");
33        }
34
35        _logger.debug(_context, "Now stopped logging to file.");
36
37        if (FileLog.prototype.isPrototypeOf(_logger)) {
38
39            // resets logger to the original instance
40            pdict.sampleLogger = _logger.getBaseLogger();
41        } else {
42
43            // resets logwriter on logger
44            _logger.setLogWriter(null);
45            pdict.sampleLogger = _logger;
46        }
47    } catch (e) {
48
49        // Call into error handler
50        _logger.error(_context, "Error occurred processing pipelet: " + e.message);
51
52        // wrap error into custom exception
53        var exception: sampleException = new sampleException(_context, "Error occured in pipelet", e);
54        pdict.sampleError = exception;
55
56        return PIPELET_ERROR;
57    }
58
59    return PIPELET_NEXT;
60}