<commit_before>const AssetCollection = require('../domain/asset-collection')
const AssetServer = require('./asset-server')
const AssetBuilder = require('./asset-builder')
const chalk = require('chalk')

const DEFAULT_DEST = 'build' // The default destination
const DEFAULT_PORT = 7100 // The default port number
const DEFAULT_DEBUG_PAGE_TITLE = 'Welcome to <i>Bulbo</i> asset path debug page!'
const DEFAULT_DEBUG_PAGE_PATH = '__bulbo__'

/**
 * AssetService manages, builds and serves the collection of assets.
 */
class AssetService {
  constructor () {
    this.assets = new AssetCollection()

    this.reset()

    this.assets.on('error', (err, asset) => {
      this.logger.log(chalk.red('Error: ' + asset.toString()))
      this.logger.log(chalk.red(err.stack))
    })
  }

  setLogger (logger) {
    this.logger = logger
  }

  /**
   * Adds the asset
   * @private
   * @param {Asset} asset The asset
   */
  addAsset (asset) {
    this.assets.add(asset)
  }

  /**
   * Serves the assets.
   * @return {Promise} Resolves when the server started
   */
  serve () {
    const server = new AssetServer(this.assets, this.port, this.logger, this.debugPageTitle, this.debugPagePath)

    server.on('reading', asset => this.logger.log(chalk.yellow('Reading:'), chalk.magenta(asset.toString())))
    server.on('changed', asset => this.logger.log(chalk.yellow('Changed:'), chalk.magenta(asset.toString())))
    server.on('ready', asset => this.logger.log(chalk.green('Ready:'), chalk.magenta(asset.toString())))

    this.watcher = server
<commit_msg>feat(asset-service): improve error logging<commit_after>const AssetCollection = require('../domain/asset-collection')
const AssetServer = require('./asset-server')
const AssetBuilder = require('./asset-builder')
const chalk = require('chalk')

const DEFAULT_DEST = 'build' // The default destination
const DEFAULT_PORT = 7100 // The default port number
const DEFAULT_DEBUG_PAGE_TITLE = 'Welcome to <i>Bulbo</i> asset path debug page!'
const DEFAULT_DEBUG_PAGE_PATH = '__bulbo__'

/**
 * AssetService manages, builds and serves the collection of assets.
 */
class AssetService {
  constructor () {
    this.assets = new AssetCollection()

    this.reset()

    this.assets.on('error', (err, asset) => {
      this.logger.log(chalk.red('Error: ' + asset.toString()))

      if (err.stack != null) {
        // log stack if available
        this.logger.log(chalk.red(err.stack))
      } else {
        // log error itself if stack is null
        this.logger.log(chalk.red(err))
      }
    })
  }

  setLogger (logger) {
    this.logger = logger
  }

  /**
   * Adds the asset
   * @private
   * @param {Asset} asset The asset
   */
  addAsset (asset) {
    this.assets.add(asset)
  }

  /**
   * Serves the assets.
   * @return {Promise} Resolves when the server started
   */
  serve () {
    const server = new AssetServer(this.assets, this.port, this.logger, this.debugPageTitle, this.debugPagePath)

    server.on('reading', asset => this.logger.log(chalk.yellow('Reading:'), chalk.magenta(asset.toString())))
    server.on('changed', asset => this.logger.log(chalk.yellow('Changed:'), chalk.magenta(asset.toString())))
    server.on('ready', asset => this.logger.log(chalk.green('Ready:'), chalk.magenta(asset.toString())))

    this.watcher = server

{'fraction_non_alphanumeric': 0.15179921378893257, 'fraction_numerical': 0.002419110976716057, 'mean_word_length': 3.575380359612725, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '482408', 'n_tokens_mistral': 1065, 'n_tokens_neox': 1013, 'n_words': 235}