From b365db4650d6ca30872d9221319fa0cf85fb0238 Mon Sep 17 00:00:00 2001 From: andreachild Date: Wed, 20 Nov 2024 09:25:52 -0800 Subject: [PATCH] Fixes for file logging related errors in windows environments: (#40) -replaced : and . characters in log file name with - as windows does not allow these characters in file names -replaced usage of pino.transport with pino.multistream which resolved issue of log file being created with no content --- src/logger.js | 36 ++++++++++++++++++++---------------- src/pipelineResources.js | 3 ++- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/logger.js b/src/logger.js index ed4e1d1..775eaeb 100644 --- a/src/logger.js +++ b/src/logger.js @@ -1,4 +1,5 @@ import { pino } from "pino"; +import pretty from "pino-pretty"; import path from "path"; let fileLogger; @@ -11,22 +12,25 @@ let logFileDestination; * @param logLevel the file log level */ function loggerInit(directory, quiet = false, logLevel = 'info') { - logFileDestination = path.join(directory, 'log_' + (new Date()).toISOString() + '.txt'); - fileLogger = pino(pino.transport({ - targets: [ - { - target: 'pino-pretty', - options: { - destination: logFileDestination, - mkdir: true, - colorize: false, - translateTime: 'yyyy-mm-dd HH:MM:ss', - ignore: 'pid,hostname' - }, - } - ] - })); - fileLogger.level = logLevel; + // replaces characters that windows does not allow in filenames + logFileDestination = path.join(directory, 'log_' + new Date().toISOString().replaceAll(/[.:]/g, '-') + '.txt'); + const streams = [ + { + level: logLevel, + stream: pretty({ + destination: logFileDestination, + mkdir: true, + colorize: false, + translateTime: 'yyyy-mm-dd HH:MM:ss', + ignore: 'pid,hostname' + }) + }, + ] + + // using pino.multistream seems to resolve some issues with file logging in windows environments that occurred when pino.transport was used instead + fileLogger = pino({ + level: logLevel + }, pino.multistream(streams)); if (quiet) { console.log = function(){}; console.info = function(){}; diff --git a/src/pipelineResources.js b/src/pipelineResources.js index ebaa8df..1c70b0c 100644 --- a/src/pipelineResources.js +++ b/src/pipelineResources.js @@ -169,7 +169,8 @@ async function checkPipeline() { startSpinner('Checking for API...'); const notFound = 'API not found'; try { - const command = new ListGraphqlApisCommand({apiType: "GRAPHQL"}); + // set maxResults to max allowed value as workaround until https://github.com/aws/amazon-neptune-for-graphql/issues/39 is addressed + const command = new ListGraphqlApisCommand({apiType: "GRAPHQL", maxResults: 25}); const response = await appSyncClient.send(command); response.graphqlApis.forEach(element => { if (element.name == NAME + 'API') {