From b9456eef6ed5997fe98da79b4e6ca891814d3b4f Mon Sep 17 00:00:00 2001 From: Peter Hedenskog Date: Tue, 7 Jan 2025 08:53:48 +0100 Subject: [PATCH] Replace intel with sitespeed.io/log (#4381) * Replace intel with sitespeed.io/log --- .../sitespeed.io/plugins/index.md | 2 +- lib/cli/cli.js | 6 - lib/core/logging.js | 104 +----------------- lib/core/queueHandler.js | 4 +- lib/core/resultsStorage/pathToFolder.js | 4 +- lib/core/resultsStorage/storageManager.js | 4 +- lib/plugins/axe/index.js | 4 +- lib/plugins/browsertime/analyzer.js | 4 +- lib/plugins/browsertime/filmstrip.js | 4 +- lib/plugins/browsertime/index.js | 4 +- lib/plugins/budget/deprecatedVerify.js | 4 +- lib/plugins/budget/index.js | 4 +- lib/plugins/budget/json.js | 4 +- lib/plugins/budget/junit.js | 4 +- lib/plugins/budget/tap.js | 4 +- lib/plugins/budget/verify.js | 4 +- lib/plugins/coach/index.js | 4 +- lib/plugins/compare/helper.js | 4 +- lib/plugins/compare/index.js | 4 +- lib/plugins/crawler/index.js | 4 +- lib/plugins/crux/index.js | 4 +- lib/plugins/crux/send.js | 4 +- lib/plugins/domains/aggregator.js | 4 +- lib/plugins/gcs/index.js | 4 +- lib/plugins/grafana/send-annotation.js | 4 +- lib/plugins/graphite/index.js | 4 +- lib/plugins/graphite/send-annotation.js | 4 +- lib/plugins/graphite/sender.js | 4 +- lib/plugins/html/htmlBuilder.js | 4 +- lib/plugins/html/renderer.js | 4 +- lib/plugins/html/setup/summaryBoxes.js | 4 +- lib/plugins/influxdb/index.js | 4 +- lib/plugins/influxdb/send-annotation.js | 4 +- lib/plugins/influxdb/send-annotationV2.js | 4 +- lib/plugins/matrix/index.js | 4 +- lib/plugins/matrix/send.js | 4 +- lib/plugins/messagelogger/index.js | 4 +- lib/plugins/pagexray/index.js | 4 +- lib/plugins/remove/index.js | 4 +- lib/plugins/s3/index.js | 4 +- lib/plugins/scp/index.js | 4 +- lib/plugins/slack/index.js | 4 +- lib/plugins/sustainable/index.js | 4 +- lib/sitespeed.js | 17 +-- lib/support/flattenMessage.js | 4 +- npm-shrinkwrap.json | 20 +++- package.json | 6 +- test/cliUtilTests.js | 4 +- test/graphiteTests.js | 4 +- test/slackTests.js | 4 +- 50 files changed, 119 insertions(+), 212 deletions(-) diff --git a/docs/documentation/sitespeed.io/plugins/index.md b/docs/documentation/sitespeed.io/plugins/index.md index 27d34e1b4..91b938ae2 100644 --- a/docs/documentation/sitespeed.io/plugins/index.md +++ b/docs/documentation/sitespeed.io/plugins/index.md @@ -283,7 +283,7 @@ In the [open](#opencontext-options) function you can add something like this: ~~~javascript // Register a logger for this plugin, a unique name so we can filter the log // And save the log for later -this.log = context.intel.getLogger('sitespeedio.plugin.PLUGIN_NAME'); +this.log = context.getLogger('sitespeedio.plugin.PLUGIN_NAME'); this.log.info('Plugin PLUGIN_NAME started'); ~~~ diff --git a/lib/cli/cli.js b/lib/cli/cli.js index 8b00543a5..62dae6036 100644 --- a/lib/cli/cli.js +++ b/lib/cli/cli.js @@ -2040,12 +2040,6 @@ export async function parseCommandLine() { default: false, type: 'boolean' }) - .option('logToFile', { - describe: - 'Store the log for your run into a file in logs/sitespeed.io.log', - default: false, - type: 'boolean' - }) .option('useHash', { describe: 'If your site uses # for URLs and # give you unique URLs you need to turn on useHash. By default is it turned off, meaning URLs with hash and without hash are treated as the same URL', diff --git a/lib/core/logging.js b/lib/core/logging.js index 51a284534..e536eb01c 100644 --- a/lib/core/logging.js +++ b/lib/core/logging.js @@ -1,100 +1,8 @@ -import intel from 'intel'; -import { createWriteStream } from 'node:fs'; -import { inherits } from 'node:util'; -const { - INFO, - DEBUG, - VERBOSE, - TRACE, - NONE, - basicConfig, - Logger, - Handler, - Formatter -} = intel; +import { configureLog } from '@sitespeed.io/log'; -// FileHandler isn't exposed in Intel when we moved to ESM. -// To fix that for now we just use the same code as Intel. - -function StreamHandler(options) { - options = options || {}; - if (!options.stream) { - options = { stream: options }; - } - Handler.call(this, options); - this._stream = options.stream; -} - -inherits(StreamHandler, Handler); - -StreamHandler.prototype.emit = function streamEmit(record) { - this._stream.write(this.format(record) + '\n'); -}; - -function FileHandler(options) { - if (typeof options === 'string') { - options = { file: options }; - } - this._file = options.file; - - options.stream = this._open(); - StreamHandler.call(this, options); -} -inherits(FileHandler, StreamHandler); - -FileHandler.prototype._open = function open() { - return createWriteStream(this._file, { flags: 'a' }); -}; - -export function configure(options, logDir) { - options = options || {}; - - let level = INFO; - - switch (options.verbose) { - case 1: { - level = DEBUG; - break; - } - case 2: { - level = VERBOSE; - break; - } - case 3: { - level = TRACE; - break; - } - default: { - break; - } - } - - if (options.silent) { - level = NONE; - } - - if (level === INFO) { - basicConfig({ - format: '[%(date)s] %(levelname)s: %(message)s', - level: level - }); - } else { - basicConfig({ - format: '[%(date)s] %(levelname)s: [%(name)s] %(message)s', - level: level - }); - } - - if (options.logToFile) { - let logger = new Logger(); - logger.addHandler( - new FileHandler({ - file: logDir + '/sitespeed.io.log', - formatter: new Formatter({ - format: '[%(date)s] %(levelname)s: [%(name)s] %(message)s', - level: level - }) - }) - ); - } +export function configure(options = {}) { + configureLog({ + verbose: options.verbose ?? 0, + silent: options.silent ?? false + }); } diff --git a/lib/core/queueHandler.js b/lib/core/queueHandler.js index b5d5d6041..73d15fd75 100644 --- a/lib/core/queueHandler.js +++ b/lib/core/queueHandler.js @@ -1,7 +1,7 @@ /* eslint no-console:0 */ import cq from 'concurrent-queue'; -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; import { messageMaker } from '../support/messageMaker.js'; import { @@ -11,7 +11,7 @@ import { } from './queueStatistics.js'; const make = messageMaker('queueHandler').make; -const log = intel.getLogger('sitespeedio.queuehandler'); +const log = getLogger('sitespeedio.queuehandler'); function shortenData(key, value) { if (key === 'data') { diff --git a/lib/core/resultsStorage/pathToFolder.js b/lib/core/resultsStorage/pathToFolder.js index 2f798b2c1..16cb7b955 100644 --- a/lib/core/resultsStorage/pathToFolder.js +++ b/lib/core/resultsStorage/pathToFolder.js @@ -2,9 +2,9 @@ import { parse } from 'node:url'; import { createHash } from 'node:crypto'; import isEmpty from 'lodash.isempty'; -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; -const log = intel.getLogger('sitespeedio.file'); +const log = getLogger('sitespeedio.file'); function toSafeKey(key) { // U+2013 : EN DASH – as used on https://en.wikipedia.org/wiki/2019–20_coronavirus_pandemic diff --git a/lib/core/resultsStorage/storageManager.js b/lib/core/resultsStorage/storageManager.js index efe923666..e1767d79e 100644 --- a/lib/core/resultsStorage/storageManager.js +++ b/lib/core/resultsStorage/storageManager.js @@ -10,11 +10,11 @@ import { } from 'node:fs'; import { cp } from 'node:fs/promises'; -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; import { pathToFolder } from './pathToFolder.js'; -const log = intel.getLogger('sitespeedio.storageManager'); +const log = getLogger('sitespeedio.storageManager'); const mkdir = promisify(_mkdir); const readdir = promisify(_readdir); const lstat = promisify(_lstat); diff --git a/lib/plugins/axe/index.js b/lib/plugins/axe/index.js index 04463acf1..153a1ae75 100644 --- a/lib/plugins/axe/index.js +++ b/lib/plugins/axe/index.js @@ -1,11 +1,11 @@ import path from 'node:path'; import { readFileSync } from 'node:fs'; import { fileURLToPath } from 'node:url'; -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; import axe from 'axe-core'; const { version: axeVersion } = axe; import { SitespeedioPlugin } from '@sitespeed.io/plugin'; -const log = intel.getLogger('sitespeedio.plugin.axe'); +const log = getLogger('sitespeedio.plugin.axe'); const __dirname = fileURLToPath(new URL('.', import.meta.url)); export default class AxePlugin extends SitespeedioPlugin { diff --git a/lib/plugins/browsertime/analyzer.js b/lib/plugins/browsertime/analyzer.js index 044f500ee..22b053d90 100644 --- a/lib/plugins/browsertime/analyzer.js +++ b/lib/plugins/browsertime/analyzer.js @@ -5,8 +5,8 @@ import get from 'lodash.get'; import coach from 'coach-core'; import { BrowsertimeEngine, browserScripts } from 'browsertime'; const { getDomAdvice } = coach; -import intel from 'intel'; -const log = intel.getLogger('plugin.browsertime'); +import { getLogger } from '@sitespeed.io/log'; +const log = getLogger('plugin.browsertime'); const defaultBrowsertimeOptions = { statistics: true diff --git a/lib/plugins/browsertime/filmstrip.js b/lib/plugins/browsertime/filmstrip.js index 173726fcf..88590318c 100644 --- a/lib/plugins/browsertime/filmstrip.js +++ b/lib/plugins/browsertime/filmstrip.js @@ -2,8 +2,8 @@ import { readdir as _readdir } from 'node:fs'; import { promisify } from 'node:util'; import path from 'node:path'; const readdir = promisify(_readdir); -import intel from 'intel'; -const log = intel.getLogger('sitespeedio.plugin.browsertime'); +import { getLogger } from '@sitespeed.io/log'; +const log = getLogger('sitespeedio.plugin.browsertime'); function findFrame(videoFrames, time) { let frame = videoFrames[0]; diff --git a/lib/plugins/browsertime/index.js b/lib/plugins/browsertime/index.js index 59987c164..59f2627db 100644 --- a/lib/plugins/browsertime/index.js +++ b/lib/plugins/browsertime/index.js @@ -2,8 +2,8 @@ import { parse } from 'node:url'; import { default as _merge } from 'lodash.merge'; -import intel from 'intel'; -const log = intel.getLogger('plugin.browsertime'); +import { getLogger } from '@sitespeed.io/log'; +const log = getLogger('plugin.browsertime'); import dayjs from 'dayjs'; import isEmpty from 'lodash.isempty'; diff --git a/lib/plugins/budget/deprecatedVerify.js b/lib/plugins/budget/deprecatedVerify.js index 392604851..d98d4caed 100644 --- a/lib/plugins/budget/deprecatedVerify.js +++ b/lib/plugins/budget/deprecatedVerify.js @@ -3,8 +3,8 @@ */ import get from 'lodash.get'; import { noop, size } from '../../support/helpers/index.js'; -import intel from 'intel'; -const log = intel.getLogger('sitespeedio.plugin.budget'); +import { getLogger } from '@sitespeed.io/log'; +const log = getLogger('sitespeedio.plugin.budget'); function getItem(url, type, metric, value, limit, limitType) { return { diff --git a/lib/plugins/budget/index.js b/lib/plugins/budget/index.js index 16a79d832..8e7cdd2d3 100644 --- a/lib/plugins/budget/index.js +++ b/lib/plugins/budget/index.js @@ -1,4 +1,4 @@ -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; import { SitespeedioPlugin } from '@sitespeed.io/plugin'; import { verify as deprecatedVerify } from './deprecatedVerify.js'; import { verify } from './verify.js'; @@ -6,7 +6,7 @@ import { writeTap } from './tap.js'; import { writeJunit } from './junit.js'; import { writeJson } from './json.js'; -const log = intel.getLogger('sitespeedio.plugin.budget'); +const log = getLogger('sitespeedio.plugin.budget'); export default class BudgetPlugin extends SitespeedioPlugin { constructor(options, context, queue) { diff --git a/lib/plugins/budget/json.js b/lib/plugins/budget/json.js index 51fa689ac..62d8bd46b 100644 --- a/lib/plugins/budget/json.js +++ b/lib/plugins/budget/json.js @@ -1,8 +1,8 @@ import { writeFileSync } from 'node:fs'; import path from 'node:path'; -import intel from 'intel'; -const log = intel.getLogger('sitespeedio.plugin.budget'); +import { getLogger } from '@sitespeed.io/log'; +const log = getLogger('sitespeedio.plugin.budget'); export function writeJson(results, dir) { const file = path.join(dir, 'budgetResult.json'); diff --git a/lib/plugins/budget/junit.js b/lib/plugins/budget/junit.js index acd6c638c..4c300a904 100644 --- a/lib/plugins/budget/junit.js +++ b/lib/plugins/budget/junit.js @@ -3,8 +3,8 @@ import { parse } from 'node:url'; import jrp from 'junit-report-builder'; -import intel from 'intel'; -const log = intel.getLogger('sitespeedio.plugin.budget'); +import { getLogger } from '@sitespeed.io/log'; +const log = getLogger('sitespeedio.plugin.budget'); import merge from 'lodash.merge'; diff --git a/lib/plugins/budget/tap.js b/lib/plugins/budget/tap.js index 1b45dac78..895754c99 100644 --- a/lib/plugins/budget/tap.js +++ b/lib/plugins/budget/tap.js @@ -2,8 +2,8 @@ import path from 'node:path'; import fs from 'node:fs'; import { EOL } from 'node:os'; import tap from 'tape'; -import intel from 'intel'; -const log = intel.getLogger('sitespeedio.plugin.budget'); +import { getLogger } from '@sitespeed.io/log'; +const log = getLogger('sitespeedio.plugin.budget'); export function writeTap(results, dir) { const file = path.join(dir, 'budget.tap'); diff --git a/lib/plugins/budget/verify.js b/lib/plugins/budget/verify.js index b1048f777..cc335f502 100644 --- a/lib/plugins/budget/verify.js +++ b/lib/plugins/budget/verify.js @@ -3,8 +3,8 @@ */ import get from 'lodash.get'; import merge from 'lodash.merge'; -import intel from 'intel'; -const log = intel.getLogger('sitespeedio.plugin.budget'); +import { getLogger } from '@sitespeed.io/log'; +const log = getLogger('sitespeedio.plugin.budget'); import friendlyNames from '../../support/friendlynames.js'; import { time } from '../../support/helpers/time.js'; diff --git a/lib/plugins/coach/index.js b/lib/plugins/coach/index.js index 8b9a8c827..0658775ab 100644 --- a/lib/plugins/coach/index.js +++ b/lib/plugins/coach/index.js @@ -1,7 +1,7 @@ import { SitespeedioPlugin } from '@sitespeed.io/plugin'; import { CoachAggregator } from './aggregator.js'; -import intel from 'intel'; -const log = intel.getLogger('plugin.coach'); +import { getLogger } from '@sitespeed.io/log'; +const log = getLogger('plugin.coach'); const DEFAULT_METRICS_RUN = []; diff --git a/lib/plugins/compare/helper.js b/lib/plugins/compare/helper.js index 6d41181f9..709fbd493 100644 --- a/lib/plugins/compare/helper.js +++ b/lib/plugins/compare/helper.js @@ -3,9 +3,9 @@ import path from 'node:path'; import { execa } from 'execa'; import { Stats } from 'fast-stats'; -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; import { decimals } from '../../support/helpers/index.js'; -const log = intel.getLogger('sitespeedio.plugin.compare'); +const log = getLogger('sitespeedio.plugin.compare'); const __dirname = path.dirname(fileURLToPath(import.meta.url)); diff --git a/lib/plugins/compare/index.js b/lib/plugins/compare/index.js index 68eaacc8c..8b1101283 100644 --- a/lib/plugins/compare/index.js +++ b/lib/plugins/compare/index.js @@ -3,7 +3,7 @@ import { readFileSync } from 'node:fs'; import path from 'node:path'; import { SitespeedioPlugin } from '@sitespeed.io/plugin'; -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; import merge from 'lodash.merge'; import get from 'lodash.get'; import dayjs from 'dayjs'; @@ -19,7 +19,7 @@ import { getBaseline, saveBaseline } from './baseline.js'; const __dirname = fileURLToPath(new URL('.', import.meta.url)); -const log = intel.getLogger('sitespeedio.plugin.compare'); +const log = getLogger('sitespeedio.plugin.compare'); const defaultConfig = {}; function urlToId(url, options) { diff --git a/lib/plugins/crawler/index.js b/lib/plugins/crawler/index.js index a812bc92a..b75c9ff68 100644 --- a/lib/plugins/crawler/index.js +++ b/lib/plugins/crawler/index.js @@ -1,9 +1,9 @@ import path from 'node:path'; import merge from 'lodash.merge'; -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; import { SitespeedioPlugin } from '@sitespeed.io/plugin'; -const log = intel.getLogger('sitespeedio.plugin.crawler'); +const log = getLogger('sitespeedio.plugin.crawler'); import Crawler from 'simplecrawler'; import { throwIfMissing } from '../../support/util.js'; import { toArray } from '../../support/util.js'; diff --git a/lib/plugins/crux/index.js b/lib/plugins/crux/index.js index 483ef5a53..9d2a2a112 100644 --- a/lib/plugins/crux/index.js +++ b/lib/plugins/crux/index.js @@ -2,7 +2,7 @@ import { readFileSync } from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; import merge from 'lodash.merge'; import { SitespeedioPlugin } from '@sitespeed.io/plugin'; @@ -11,7 +11,7 @@ import { throwIfMissing } from '../../support/util.js'; import { repackage } from './repackage.js'; import { send } from './send.js'; const __dirname = fileURLToPath(new URL('.', import.meta.url)); -const log = intel.getLogger('plugin.crux'); +const log = getLogger('plugin.crux'); const defaultConfig = {}; diff --git a/lib/plugins/crux/send.js b/lib/plugins/crux/send.js index fb5b0c928..ef9725ed5 100644 --- a/lib/plugins/crux/send.js +++ b/lib/plugins/crux/send.js @@ -1,6 +1,6 @@ import { request as _request } from 'node:https'; -import intel from 'intel'; -const log = intel.getLogger('plugin.crux'); +import { getLogger } from '@sitespeed.io/log'; +const log = getLogger('plugin.crux'); export async function send(url, key, formFactor, shouldWeTestTheURL) { let data = shouldWeTestTheURL ? { url } : { origin: url }; diff --git a/lib/plugins/domains/aggregator.js b/lib/plugins/domains/aggregator.js index 635041f0f..01fd53058 100644 --- a/lib/plugins/domains/aggregator.js +++ b/lib/plugins/domains/aggregator.js @@ -1,13 +1,13 @@ import { parse } from 'node:url'; import { Stats } from 'fast-stats'; -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; import isEmpty from 'lodash.isempty'; import reduce from 'lodash.reduce'; import { summarizeStats } from '../../support/statsHelpers.js'; -const log = intel.getLogger('sitespeedio.plugin.domains'); +const log = getLogger('sitespeedio.plugin.domains'); const timingNames = [ 'blocked', diff --git a/lib/plugins/gcs/index.js b/lib/plugins/gcs/index.js index d7a3de4d9..56080d4ff 100644 --- a/lib/plugins/gcs/index.js +++ b/lib/plugins/gcs/index.js @@ -5,11 +5,11 @@ import { SitespeedioPlugin } from '@sitespeed.io/plugin'; // Documentation of @google-cloud/storage: https://cloud.google.com/nodejs/docs/reference/storage/2.3.x/Bucket#upload import { Storage } from '@google-cloud/storage'; -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; import { throwIfMissing } from '../../support/util.js'; import { recursiveReaddir } from '../../support/fileUtil.js'; -const log = intel.getLogger('sitespeedio.plugin.gcs'); +const log = getLogger('sitespeedio.plugin.gcs'); async function uploadLatestFiles(dir, gcsOptions, prefix) { const config = { diff --git a/lib/plugins/grafana/send-annotation.js b/lib/plugins/grafana/send-annotation.js index 7ce30658d..71278407d 100644 --- a/lib/plugins/grafana/send-annotation.js +++ b/lib/plugins/grafana/send-annotation.js @@ -2,7 +2,7 @@ import http from 'node:http'; import https from 'node:https'; import { createRequire } from 'node:module'; -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; import { getConnectivity, getURLAndGroup } from '../../support/tsdbUtil.js'; import { @@ -13,7 +13,7 @@ import { toArray } from '../../support/util.js'; const require = createRequire(import.meta.url); const version = require('../../../package.json').version; -const log = intel.getLogger('sitespeedio.plugin.grafana'); +const log = getLogger('sitespeedio.plugin.grafana'); export function send( url, diff --git a/lib/plugins/graphite/index.js b/lib/plugins/graphite/index.js index f430cf640..eac79623e 100644 --- a/lib/plugins/graphite/index.js +++ b/lib/plugins/graphite/index.js @@ -2,7 +2,7 @@ import isEmpty from 'lodash.isempty'; import merge from 'lodash.merge'; import get from 'lodash.get'; import dayjs from 'dayjs'; -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; import { SitespeedioPlugin } from '@sitespeed.io/plugin'; import { send } from './send-annotation.js'; @@ -13,7 +13,7 @@ import { toArray } from '../../support/util.js'; import { GraphiteSender } from './graphite-sender.js'; import { StatsDSender } from './statsd-sender.js'; -const log = intel.getLogger('sitespeedio.plugin.graphite'); +const log = getLogger('sitespeedio.plugin.graphite'); export default class GraphitePlugin extends SitespeedioPlugin { constructor(options, context, queue) { diff --git a/lib/plugins/graphite/send-annotation.js b/lib/plugins/graphite/send-annotation.js index f8f43c46a..696bc2371 100644 --- a/lib/plugins/graphite/send-annotation.js +++ b/lib/plugins/graphite/send-annotation.js @@ -1,7 +1,7 @@ import http from 'node:http'; import https from 'node:https'; import { createRequire } from 'node:module'; -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; import { getConnectivity, getURLAndGroup } from '../../support/tsdbUtil.js'; import { @@ -13,7 +13,7 @@ import { toArray } from '../../support/util.js'; const require = createRequire(import.meta.url); const version = require('../../../package.json').version; -const log = intel.getLogger('sitespeedio.plugin.graphite'); +const log = getLogger('sitespeedio.plugin.graphite'); export function send( url, diff --git a/lib/plugins/graphite/sender.js b/lib/plugins/graphite/sender.js index 8c5b73c23..7e42c41b2 100644 --- a/lib/plugins/graphite/sender.js +++ b/lib/plugins/graphite/sender.js @@ -1,5 +1,5 @@ -import intel from 'intel'; -const log = intel.getLogger('sitespeedio.plugin.graphite'); +import { getLogger } from '@sitespeed.io/log'; +const log = getLogger('sitespeedio.plugin.graphite'); export class Sender { constructor(host, port, bulkSize) { diff --git a/lib/plugins/html/htmlBuilder.js b/lib/plugins/html/htmlBuilder.js index ac985e214..4ce9500f2 100644 --- a/lib/plugins/html/htmlBuilder.js +++ b/lib/plugins/html/htmlBuilder.js @@ -7,14 +7,14 @@ import { fileURLToPath } from 'node:url'; import dayjs from 'dayjs'; import getos from 'getos'; -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; import { markdown } from 'markdown'; import merge from 'lodash.merge'; import get from 'lodash.get'; import isEmpty from 'lodash.isempty'; const getOS = promisify(getos); -const log = intel.getLogger('sitespeedio.plugin.html'); +const log = getLogger('sitespeedio.plugin.html'); const require = createRequire(import.meta.url); const { dependencies, version } = require('../../../package.json'); import { renderTemplate } from './renderer.js'; diff --git a/lib/plugins/html/renderer.js b/lib/plugins/html/renderer.js index e91503cb6..88dca149b 100644 --- a/lib/plugins/html/renderer.js +++ b/lib/plugins/html/renderer.js @@ -2,9 +2,9 @@ import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { compileFile, compile } from 'pug'; -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; -const log = intel.getLogger('sitespeedio.plugin.html'); +const log = getLogger('sitespeedio.plugin.html'); const __dirname = fileURLToPath(new URL('.', import.meta.url)); const basePath = path.resolve(__dirname, 'templates'); diff --git a/lib/plugins/html/setup/summaryBoxes.js b/lib/plugins/html/setup/summaryBoxes.js index 85f79840d..4ff33c6df 100644 --- a/lib/plugins/html/setup/summaryBoxes.js +++ b/lib/plugins/html/setup/summaryBoxes.js @@ -1,5 +1,5 @@ -import intel from 'intel'; -const log = intel.getLogger('sitespeedio.plugin.html'); +import { getLogger } from '@sitespeed.io/log'; +const log = getLogger('sitespeedio.plugin.html'); import { toArray } from '../../../support/util.js'; import friendlyNames from '../../../support/friendlynames.js'; import get from 'lodash.get'; diff --git a/lib/plugins/influxdb/index.js b/lib/plugins/influxdb/index.js index 45a940981..e8db9aa6f 100644 --- a/lib/plugins/influxdb/index.js +++ b/lib/plugins/influxdb/index.js @@ -1,5 +1,5 @@ import isEmpty from 'lodash.isempty'; -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; import dayjs from 'dayjs'; import { SitespeedioPlugin } from '@sitespeed.io/plugin'; @@ -10,7 +10,7 @@ import { sendV2 } from './send-annotationV2.js'; import { InfluxDBDataGenerator as DataGenerator } from './data-generator.js'; import { throwIfMissing } from '../../support/util.js'; -const log = intel.getLogger('sitespeedio.plugin.influxdb'); +const log = getLogger('sitespeedio.plugin.influxdb'); export default class InfluxDBPlugin extends SitespeedioPlugin { constructor(options, context, queue) { super({ name: 'influxdb', options, context, queue }); diff --git a/lib/plugins/influxdb/send-annotation.js b/lib/plugins/influxdb/send-annotation.js index 72dd112f3..0bc9c7635 100644 --- a/lib/plugins/influxdb/send-annotation.js +++ b/lib/plugins/influxdb/send-annotation.js @@ -2,7 +2,7 @@ import http from 'node:http'; import https from 'node:https'; import { stringify } from 'node:querystring'; -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; import dayjs from 'dayjs'; import { getConnectivity, getURLAndGroup } from '../../support/tsdbUtil.js'; @@ -11,7 +11,7 @@ import { getTagsAsString } from '../../support/annotationsHelper.js'; -const log = intel.getLogger('sitespeedio.plugin.influxdb'); +const log = getLogger('sitespeedio.plugin.influxdb'); export function sendV1( url, diff --git a/lib/plugins/influxdb/send-annotationV2.js b/lib/plugins/influxdb/send-annotationV2.js index 3f0adcc62..d20c6800a 100644 --- a/lib/plugins/influxdb/send-annotationV2.js +++ b/lib/plugins/influxdb/send-annotationV2.js @@ -1,7 +1,7 @@ import http from 'node:http'; import https from 'node:https'; -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; import dayjs from 'dayjs'; import { getConnectivity, getURLAndGroup } from '../../support/tsdbUtil.js'; @@ -10,7 +10,7 @@ import { getTagsAsString } from '../../support/annotationsHelper.js'; -const log = intel.getLogger('sitespeedio.plugin.influxdb'); +const log = getLogger('sitespeedio.plugin.influxdb'); export function sendV2( url, diff --git a/lib/plugins/matrix/index.js b/lib/plugins/matrix/index.js index bc12901ba..06309340f 100644 --- a/lib/plugins/matrix/index.js +++ b/lib/plugins/matrix/index.js @@ -1,11 +1,11 @@ -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; import get from 'lodash.get'; import { SitespeedioPlugin } from '@sitespeed.io/plugin'; import send from './send.js'; import { throwIfMissing } from '../../support/util.js'; -const log = intel.getLogger('sitespeedio.plugin.matrix'); +const log = getLogger('sitespeedio.plugin.matrix'); function getBrowserData(data) { return data && data.browser diff --git a/lib/plugins/matrix/send.js b/lib/plugins/matrix/send.js index 63812dd93..ac2df5ebd 100644 --- a/lib/plugins/matrix/send.js +++ b/lib/plugins/matrix/send.js @@ -1,6 +1,6 @@ import { request as _request } from 'node:https'; -import intel from 'intel'; -const log = intel.getLogger('sitespeedio.plugin.matrix'); +import { getLogger } from '@sitespeed.io/log'; +const log = getLogger('sitespeedio.plugin.matrix'); function send( host, diff --git a/lib/plugins/messagelogger/index.js b/lib/plugins/messagelogger/index.js index f7a755faa..c82a4553b 100644 --- a/lib/plugins/messagelogger/index.js +++ b/lib/plugins/messagelogger/index.js @@ -1,10 +1,10 @@ /* eslint no-console:0 */ -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; import isEmpty from 'lodash.isempty'; import { SitespeedioPlugin } from '@sitespeed.io/plugin'; -const log = intel.getLogger('sitespeedio.plugin.messagelogger'); +const log = getLogger('sitespeedio.plugin.messagelogger'); function shortenData(key, value) { if (key === 'data' && !isEmpty(value)) { diff --git a/lib/plugins/pagexray/index.js b/lib/plugins/pagexray/index.js index b82d40998..8f19ce11c 100644 --- a/lib/plugins/pagexray/index.js +++ b/lib/plugins/pagexray/index.js @@ -1,5 +1,5 @@ import { parse } from 'node:url'; -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; import coach from 'coach-core'; import { SitespeedioPlugin } from '@sitespeed.io/plugin'; @@ -8,7 +8,7 @@ import { short } from '../../support/helpers/index.js'; const { getPageXray } = coach; const pagexray = getPageXray(); -const log = intel.getLogger('plugin.pagexray'); +const log = getLogger('plugin.pagexray'); const DEFAULT_PAGEXRAY_PAGESUMMARY_METRICS = [ 'contentTypes', diff --git a/lib/plugins/remove/index.js b/lib/plugins/remove/index.js index 38192d4c6..abe67e738 100644 --- a/lib/plugins/remove/index.js +++ b/lib/plugins/remove/index.js @@ -1,7 +1,7 @@ -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; import { SitespeedioPlugin } from '@sitespeed.io/plugin'; -const log = intel.getLogger('sitespeedio.plugin.remove'); +const log = getLogger('sitespeedio.plugin.remove'); export default class RemovePlugin extends SitespeedioPlugin { constructor(options, context, queue) { diff --git a/lib/plugins/s3/index.js b/lib/plugins/s3/index.js index a72357fc6..ca0fbdb69 100644 --- a/lib/plugins/s3/index.js +++ b/lib/plugins/s3/index.js @@ -2,7 +2,7 @@ import path from 'node:path'; import { promises as fsPromises } from 'node:fs'; import pLimit from 'p-limit'; -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3'; import { SitespeedioPlugin } from '@sitespeed.io/plugin'; @@ -10,7 +10,7 @@ import { throwIfMissing } from '../../support/util.js'; import { recursiveReaddir } from '../../support/fileUtil.js'; import { getContentType } from './contentType.js'; -const log = intel.getLogger('sitespeedio.plugin.s3'); +const log = getLogger('sitespeedio.plugin.s3'); async function uploadFile(file, s3Client, s3Options, prefix, baseDir) { const stream = await fsPromises.readFile(file); diff --git a/lib/plugins/scp/index.js b/lib/plugins/scp/index.js index bc7fc79ab..e8b6510a9 100644 --- a/lib/plugins/scp/index.js +++ b/lib/plugins/scp/index.js @@ -3,11 +3,11 @@ import fs from 'node:fs'; import { SitespeedioPlugin } from '@sitespeed.io/plugin'; import { Client } from 'node-scp'; -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; import { throwIfMissing } from '../../support/util.js'; import { recursiveReaddir } from '../../support/fileUtil.js'; -const log = intel.getLogger('sitespeedio.plugin.scp'); +const log = getLogger('sitespeedio.plugin.scp'); async function getClient(scpOptions) { const options = { diff --git a/lib/plugins/slack/index.js b/lib/plugins/slack/index.js index f1291f76d..a83b9bd80 100644 --- a/lib/plugins/slack/index.js +++ b/lib/plugins/slack/index.js @@ -1,4 +1,4 @@ -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; import { IncomingWebhook } from '@slack/webhook'; import merge from 'lodash.merge'; import set from 'lodash.set'; @@ -9,7 +9,7 @@ import { getAttachements } from './attachements.js'; import { getSummary } from './summary.js'; import { throwIfMissing } from '../../support/util.js'; -const log = intel.getLogger('sitespeedio.plugin.slack'); +const log = getLogger('sitespeedio.plugin.slack'); const defaultConfig = { userName: 'Sitespeed.io', diff --git a/lib/plugins/sustainable/index.js b/lib/plugins/sustainable/index.js index 0180cf33d..9907331ae 100644 --- a/lib/plugins/sustainable/index.js +++ b/lib/plugins/sustainable/index.js @@ -4,7 +4,7 @@ import fs from 'node:fs'; import zlib from 'node:zlib'; import { promisify } from 'node:util'; -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; import { co2, hosting } from '@tgwf/co2'; import { SitespeedioPlugin } from '@sitespeed.io/plugin'; import { Aggregator } from './aggregator.js'; @@ -27,7 +27,7 @@ const packageJson = JSON.parse( const co2Version = packageJson.dependencies['@tgwf/co2']; const gunzip = promisify(zlib.gunzip); -const log = intel.getLogger('sitespeedio.plugin.sustainable'); +const log = getLogger('sitespeedio.plugin.sustainable'); const DEFAULT_METRICS_PAGE_SUMMARY = [ 'co2PerPageView', diff --git a/lib/sitespeed.js b/lib/sitespeed.js index 8b4e20103..87aa810ea 100644 --- a/lib/sitespeed.js +++ b/lib/sitespeed.js @@ -6,7 +6,7 @@ import fs from 'node:fs/promises'; import dayjs from 'dayjs'; import utc from 'dayjs/plugin/utc.js'; -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; import pullAll from 'lodash.pullall'; import union from 'lodash.union'; @@ -26,7 +26,7 @@ const packageJson = JSON.parse( await fs.readFile(path.resolve(path.join(__dirname, '..', 'package.json'))) ); -const log = intel.getLogger('sitespeedio'); +const log = getLogger('sitespeedio'); dayjs.extend(utc); const budgetResult = { @@ -61,9 +61,6 @@ export async function run(options) { options ); - // Setup logging - const logDir = await storageManager.createDirectory('logs'); - if ( options.browsertime && options.browsertime.tcpdump && @@ -74,7 +71,7 @@ export async function run(options) { 'SSLKEYLOGFILE.txt' ); } - configure(options, logDir); + configure(options); // Tell the world what we are using log.info( @@ -85,9 +82,8 @@ export async function run(options) { packageJson.dependencies.browsertime, packageJson.dependencies['coach-core'] ); - if (log.isEnabledFor(log.DEBUG)) { - log.debug('Running with options: %:2j', options); - } + + log.debug('Running with options: %:2j', options); let pluginNames = await parsePluginNames(options); @@ -122,12 +118,11 @@ export async function run(options) { budget: budgetResult, name: url, log, - intel, + getLogger, messageMaker, statsHelpers, filterRegistry }; - const queueHandler = new QueueHandler(options); const runningPlugins = await loadPlugins( pluginNames, diff --git a/lib/support/flattenMessage.js b/lib/support/flattenMessage.js index f2934fc31..9a4facc20 100644 --- a/lib/support/flattenMessage.js +++ b/lib/support/flattenMessage.js @@ -1,6 +1,6 @@ import { parse } from 'node:url'; -import intel from 'intel'; -const log = intel.getLogger('sitespeedio'); +import { getLogger } from '@sitespeed.io/log'; +const log = getLogger('sitespeedio'); function joinNonEmpty(strings, delimeter) { return strings.filter(Boolean).join(delimeter); diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index b78e7fac2..5576c3f71 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -13,7 +13,8 @@ "@aws-sdk/client-s3": "3.717.0", "@google-cloud/storage": "7.14.0", "@influxdata/influxdb-client": "1.33.2", - "@sitespeed.io/plugin": "0.0.6", + "@sitespeed.io/log": "0.2.2", + "@sitespeed.io/plugin": "1.0.0", "@slack/webhook": "7.0.4", "@tgwf/co2": "0.16.4", "axe-core": "4.10.2", @@ -27,7 +28,6 @@ "getos": "3.2.1", "import-global": "1.1.1", "influx": "5.9.3", - "intel": "1.2.0", "jstransformer-markdown-it": "3.0.0", "junit-report-builder": "3.2.1", "lodash.clonedeep": "4.5.0", @@ -2239,10 +2239,20 @@ "node": ">=14.18" } }, + "node_modules/@sitespeed.io/log": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/@sitespeed.io/log/-/log-0.2.2.tgz", + "integrity": "sha512-Acvu61hHtbGz07b4TXuUVtRvO5YnNNcoreUFdiGlQkK4jE9ADRjCgrsw3ogQWuC0140ymuCVE/CZAOSQ+alA6g==", + "license": "Apache-2.0", + "engines": { + "node": ">=20.0.0" + } + }, "node_modules/@sitespeed.io/plugin": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/@sitespeed.io/plugin/-/plugin-0.0.6.tgz", - "integrity": "sha512-LlH46uCTpW+M86JYdUzH5hD9yDj5dVMEi83MTBG/PfnxLAkWmOKqp9mh0zr1wfuyvAuOWxjwmqFKvivd1lRKLg==" + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@sitespeed.io/plugin/-/plugin-1.0.0.tgz", + "integrity": "sha512-IvwXe17ZlF2UK2Asl8KkfhrNnmDS/3aL/mZg1xPhNbLiGhvYu4Uh7bsbz3YkV8cnOxGK7HdR5khbjm/BjZ0wQg==", + "license": "MIT" }, "node_modules/@sitespeed.io/throttle": { "version": "5.0.1", diff --git a/package.json b/package.json index f7eb7aad2..1352052d6 100644 --- a/package.json +++ b/package.json @@ -81,10 +81,12 @@ }, "exports": "./lib/sitespeed.js", "dependencies": { + "@aws-sdk/client-s3": "3.717.0", "@google-cloud/storage": "7.14.0", "@influxdata/influxdb-client": "1.33.2", + "@sitespeed.io/log": "0.2.2", + "@sitespeed.io/plugin": "1.0.0", "@tgwf/co2": "0.16.4", - "@aws-sdk/client-s3": "3.717.0", "@slack/webhook": "7.0.4", "axe-core": "4.10.2", "browsertime": "23.5.0", @@ -97,7 +99,6 @@ "getos": "3.2.1", "import-global": "1.1.1", "influx": "5.9.3", - "intel": "1.2.0", "jstransformer-markdown-it": "3.0.0", "junit-report-builder": "3.2.1", "lodash.clonedeep": "4.5.0", @@ -116,7 +117,6 @@ "p-limit": "6.1.0", "pug": "3.0.3", "simplecrawler": "1.1.9", - "@sitespeed.io/plugin": "0.0.6", "tape": "5.8.1", "yargs": "17.7.2" }, diff --git a/test/cliUtilTests.js b/test/cliUtilTests.js index 67f7d3393..57ebe1b82 100644 --- a/test/cliUtilTests.js +++ b/test/cliUtilTests.js @@ -4,7 +4,7 @@ import { pluginDefaults, registerPluginOptions } from '../lib/cli/util.js'; -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; import { SitespeedioPlugin } from '@sitespeed.io/plugin'; import { messageMaker } from '../lib/support/messageMaker.js'; @@ -81,7 +81,7 @@ test(`registerPluginOptions should not setup options with invalid values`, t => super({ name: 'test', options, context, queue }); } } - const plugin = new TestPlugin({}, { messageMaker, intel }); + const plugin = new TestPlugin({}, { messageMaker, getLogger }); const codeUnderTest = () => registerPluginOptions(mockYargs(), plugin); diff --git a/test/graphiteTests.js b/test/graphiteTests.js index 8b4f329f8..ef4501561 100644 --- a/test/graphiteTests.js +++ b/test/graphiteTests.js @@ -1,6 +1,6 @@ import test from 'ava'; import dayjs from 'dayjs'; -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; import { default as GraphitePlugin } from '../lib/plugins/graphite/index.js'; import { GraphiteDataGenerator as DataGenerator } from '../lib/plugins/graphite/data-generator.js'; @@ -92,7 +92,7 @@ test(`Use graphite interface by default`, async t => { const { messageMaker } = await import('../lib/support/messageMaker.js'); const filterRegistry = await import('../lib/support/filterRegistry.js'); const statsHelpers = await import('../lib/support/statsHelpers.js'); - const context = { messageMaker, filterRegistry, intel, statsHelpers }; + const context = { messageMaker, filterRegistry, getLogger, statsHelpers }; const plugin = new GraphitePlugin(options, context); plugin.open(context, options); t.is(plugin.sender.facility, 'Graphite'); diff --git a/test/slackTests.js b/test/slackTests.js index d523f21a6..a07bd7fc0 100644 --- a/test/slackTests.js +++ b/test/slackTests.js @@ -2,7 +2,7 @@ import path from 'node:path'; import { readFileSync } from 'node:fs'; import test from 'ava'; -import intel from 'intel'; +import { getLogger } from '@sitespeed.io/log'; import { resultUrls } from '../lib/core/resultsStorage/resultUrls.js'; import { messageMaker } from '../lib/support/messageMaker.js'; @@ -23,7 +23,7 @@ const defaultContextFactory = (context = {}) => { { messageMaker, filterRegistry, - intel, + getLogger, statsHelpers, resultUrls: resultUrls('', {}) },