github.com/hernad/nomad@v1.6.112/ui/app/utils/classes/abstract-logger.js (about)

     1  /**
     2   * Copyright (c) HashiCorp, Inc.
     3   * SPDX-License-Identifier: MPL-2.0
     4   */
     5  
     6  import { assert } from '@ember/debug';
     7  import Mixin from '@ember/object/mixin';
     8  import { computed } from '@ember/object';
     9  import { computed as overridable } from 'ember-overridable-computed';
    10  import { assign } from '@ember/polyfills';
    11  import queryString from 'query-string';
    12  
    13  const MAX_OUTPUT_LENGTH = 50000;
    14  
    15  // eslint-disable-next-line ember/no-new-mixins
    16  export default Mixin.create({
    17    url: '',
    18    params: overridable(() => ({})),
    19    logFetch() {
    20      assert(
    21        'Loggers need a logFetch method, which should have an interface like window.fetch'
    22      );
    23    },
    24  
    25    endOffset: null,
    26  
    27    offsetParams: computed('endOffset', function () {
    28      const endOffset = this.endOffset;
    29      return endOffset
    30        ? { origin: 'start', offset: endOffset }
    31        : { origin: 'end', offset: MAX_OUTPUT_LENGTH };
    32    }),
    33  
    34    additionalParams: overridable(() => ({})),
    35  
    36    fullUrl: computed(
    37      'url',
    38      'params',
    39      'offsetParams',
    40      'additionalParams',
    41      function () {
    42        const queryParams = queryString.stringify(
    43          assign({}, this.params, this.offsetParams, this.additionalParams)
    44        );
    45        return `${this.url}?${queryParams}`;
    46      }
    47    ),
    48  });