Skip to content

Commit

Permalink
Fixes for file logging related errors in windows environments: (#40)
Browse files Browse the repository at this point in the history
-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
  • Loading branch information
andreachild authored Nov 20, 2024
1 parent 0c17d87 commit b365db4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
36 changes: 20 additions & 16 deletions src/logger.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { pino } from "pino";
import pretty from "pino-pretty";
import path from "path";

let fileLogger;
Expand All @@ -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(){};
Expand Down
3 changes: 2 additions & 1 deletion src/pipelineResources.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down

0 comments on commit b365db4

Please sign in to comment.