github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/app/utils/classes/abstract-logger.js (about) 1 import { assert } from '@ember/debug'; 2 import Mixin from '@ember/object/mixin'; 3 import { computed } from '@ember/object'; 4 import { computed as overridable } from 'ember-overridable-computed'; 5 import { assign } from '@ember/polyfills'; 6 import queryString from 'query-string'; 7 8 const MAX_OUTPUT_LENGTH = 50000; 9 10 // eslint-disable-next-line ember/no-new-mixins 11 export default Mixin.create({ 12 url: '', 13 params: overridable(() => ({})), 14 logFetch() { 15 assert( 16 'Loggers need a logFetch method, which should have an interface like window.fetch' 17 ); 18 }, 19 20 endOffset: null, 21 22 offsetParams: computed('endOffset', function () { 23 const endOffset = this.endOffset; 24 return endOffset 25 ? { origin: 'start', offset: endOffset } 26 : { origin: 'end', offset: MAX_OUTPUT_LENGTH }; 27 }), 28 29 additionalParams: overridable(() => ({})), 30 31 fullUrl: computed( 32 'url', 33 'params', 34 'offsetParams', 35 'additionalParams', 36 function () { 37 const queryParams = queryString.stringify( 38 assign({}, this.params, this.offsetParams, this.additionalParams) 39 ); 40 return `${this.url}?${queryParams}`; 41 } 42 ), 43 });