1/**************************************************
2 * Name: BeginFileLog.ds
3 *
4 * Description:
5 * Create new FileLogger to write all logging events to file.
6 * This FileLogger will replace the normal logger in the pdict for
7 * the length of the operation, then its contents are appended
8 * to the original logger (to avoid writing everything else to file).
9 * If the filename is specified, the logger will write to this file
10 * in the TEMP directory. Otherwise, the default logs are used.
11 *
12 * @input CUSTLogger : Object
13 * @input LogFileName : Object
14 * @output custLogger : Object
15 * @output custError : Object
16 *
17 *****************************************************/
18importScript("bc_cust:library/common/libContext.ds");
19importScript("bc_cust:library/utility/exception/libcustException.ds");
20importScript("bc_cust:library/utility/logging/libLog.ds");
21
22
23
24function execute(pdict: PipelineDictionary): Number {
25
26
27
28 var _context: Context = new Context("BeginFileLog.ds");
29 var _logger: Log = Log.getLogger(pdict);
30
31 try {
32
33 // retrieve filename
34 var LogFileName: String = pdict.LogFileName;
35 if (!empty(LogFileName) && LogFileName.length > 0) {
36
37 _logger = Log.getFileLogger(LogFileName, _logger);
38 _logger.debug(_context, "Now logging to file: " + LogFileName);
39 } else {
40
41 _logger.warn(_context, "No filename specified, using default DemandWare logs");
42 _logger.setLogWriter(Log.DemandWareLogWriter);
43 _logger.debug(_context, "Now logging to default log file");
44 }
45
46 pdict.custLogger = _logger;
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: custException = new custException(_context, "Error occured in pipelet", e);
54 pdict.custError = exception;
55
56 return PIPELET_ERROR;
57 }
58
59 return PIPELET_NEXT;
60}