---
schema_version: "1"
id: 5bb526b7ce32975279440ec9ff3cb92a675ce191bf68e51d13ac5493bdab3180
title: BeginFileLog.ds
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/commerce-cloud/b2c-commerce/guides/inventory/b2c-begin-file-log-ds.md
canonical_url: https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/b2c-begin-file-log-ds.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: e3c2d5abb9a30826c8d24d8100429ed736fa6b0f7a643be76e577f0bfb980bb4
products:
  - Composable Storefront
  - Salesforce APIs
---
# BeginFileLog.ds

Review the BeginFileLog.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. You can use this code to write all logging events to a file.

```
/**************************************************
 * Name: BeginFileLog.ds
 *
 * Description:
 * Create new FileLogger to write all logging events to file.
 * This FileLogger will replace the normal logger in the pdict for
 * the length of the operation, then its contents are appended
 * to the original logger (to avoid writing everything else to file).
 * If the filename is specified, the logger will write to this file
 * in the TEMP directory. Otherwise, the default logs are used.
 *
 * @input CUSTLogger   		: Object
 * @input LogFileName 		: Object
 * @output custLogger     	: Object
 * @output custError     	: Object
 *
 *****************************************************/
importScript("bc_cust:library/common/libContext.ds");
importScript("bc_cust:library/utility/exception/libcustException.ds");
importScript("bc_cust:library/utility/logging/libLog.ds");



function execute(pdict: PipelineDictionary): Number {



    var _context: Context = new Context("BeginFileLog.ds");
    var _logger: Log = Log.getLogger(pdict);

    try {

        // retrieve filename
        var LogFileName: String = pdict.LogFileName;
        if (!empty(LogFileName) && LogFileName.length > 0) {

            _logger = Log.getFileLogger(LogFileName, _logger);
            _logger.debug(_context, "Now logging to file: " + LogFileName);
        } else {

            _logger.warn(_context, "No filename specified, using default DemandWare logs");
            _logger.setLogWriter(Log.DemandWareLogWriter);
            _logger.debug(_context, "Now logging to default log file");
        }

        pdict.custLogger = _logger;
    } catch (e) {

        // Call into error handler
        _logger.error(_context, "Error occurred processing pipelet: " + e.message);

        // wrap error into custom exception
        var exception: custException = new custException(_context, "Error occured in pipelet", e);
        pdict.custError = exception;

        return PIPELET_ERROR;
    }

    return PIPELET_NEXT;
}
```
