Skip to content

Commit 909ed51

Browse files
authored
Merge pull request #32 from Bit-Quill/achild/logging
Increased logging to console and introduced file logging
2 parents e0656ae + ee6578b commit 909ed51

15 files changed

+507
-612
lines changed

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@
6464
"graphql": "^16.8.1",
6565
"graphql-tag": "2.12.6",
6666
"ora": "7.0.1",
67-
"semver": "7.5.4"
67+
"semver": "7.5.4",
68+
"pino": "9.4.0",
69+
"pino-pretty": "11.2.2"
6870
},
6971
"devDependencies": {
7072
"@jest/test-sequencer": "^29.7.0",

samples/todo.schema.graphql

-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,4 @@ type Todo {
1010

1111
type Comment {
1212
content: String
13-
}
14-
15-
input Options {
16-
limit: Int
1713
}

src/CDKPipelineApp.js

+14-17
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { readFile, writeFile } from 'fs/promises';
1616
import fs from 'fs';
1717
import archiver from 'archiver';
1818
import ora from 'ora';
19+
import { loggerDebug, loggerError, loggerInfo, yellow } from "./logger.js";
1920

2021
let NAME = '';
2122
let REGION = '';
@@ -34,11 +35,6 @@ let APPSYNC_ATTACH_MUTATION = [];
3435
let SCHEMA_MODEL = null;
3536
let thisOutputFolderPath = './output';
3637

37-
38-
function yellow(text) {
39-
return '\x1b[33m' + text + '\x1b[0m';
40-
}
41-
4238
async function getSchemaFields(typeName) {
4339
/* To be updated as:
4440
SCHEMA_MODEL.definitions
@@ -69,7 +65,7 @@ async function createDeploymentFile(folderPath, zipFilePath) {
6965
archive.file('./output/output.resolver.graphql.js', { name: 'output.resolver.graphql.js' })
7066
await archive.finalize();
7167
} catch (err) {
72-
console.error('Creating deployment zip file: ' + err);
68+
loggerError('Error creating deployment zip file', err);
7369
}
7470
}
7571

@@ -107,32 +103,32 @@ async function createAWSpipelineCDK({
107103

108104
if (neptuneType === 'neptune-db') {
109105
try {
110-
if (!quiet) console.log('Get Neptune Cluster Info');
106+
loggerInfo('Getting Neptune Cluster Info');
111107
if (!quiet) spinner = ora('Getting ...').start();
112108
neptuneClusterInfo = await getNeptuneClusterDbInfoBy(NEPTUNE_DB_NAME, REGION);
113109
if (!quiet) spinner.succeed('Got Neptune Cluster Info');
114110
if (isNeptuneIAMAuth) {
115111
if (!neptuneClusterInfo.isIAMauth) {
116-
console.error("The Neptune database authentication is set to VPC.");
117-
console.error("Remove the --output-aws-pipeline-cdk-neptune-IAM option.");
112+
loggerError("The Neptune database authentication is set to VPC.");
113+
loggerError("Remove the --output-aws-pipeline-cdk-neptune-IAM option.");
118114
process.exit(1);
119115
}
120116
} else {
121117
if (neptuneClusterInfo.isIAMauth) {
122-
console.error("The Neptune database authentication is set to IAM.");
123-
console.error("Add the --output-aws-pipeline-cdk-neptune-IAM option.");
118+
loggerError("The Neptune database authentication is set to IAM.");
119+
loggerError("Add the --output-aws-pipeline-cdk-neptune-IAM option.");
124120
process.exit(1);
125121
} else {
126-
if (!quiet) console.log(`Subnet Group: ` + yellow(neptuneClusterInfo.dbSubnetGroup));
122+
loggerDebug(`Subnet Group: ` + neptuneClusterInfo.dbSubnetGroup, {toConsole: true});
127123
}
128124
}
129125

130126
if (neptuneClusterInfo.version != '') {
131127
const v = neptuneClusterInfo.version;
132128
if (lambdaFilesPath.includes('SDK') == true && //semver.satisfies(v, '>=1.2.1.0') ) {
133-
(v == '1.2.1.0' || v == '1.2.0.2' || v == '1.2.0.1' || v == '1.2.0.0' || v == '1.1.1.0' || v == '1.1.0.0')) {
134-
console.error("Neptune SDK query is supported starting with Neptune versions 1.2.1.0.R5");
135-
console.error("Switch to Neptune HTTPS query with option --output-resolver-query-https");
129+
(v == '1.2.1.0' || v == '1.2.0.2' || v == '1.2.0.1' || v == '1.2.0.0' || v == '1.1.1.0' || v == '1.1.0.0')) {
130+
loggerError("Neptune SDK query is supported starting with Neptune versions 1.2.1.0.R5");
131+
loggerError("Switch to Neptune HTTPS query with option --output-resolver-query-https");
136132
process.exit(1);
137133
}
138134
}
@@ -143,13 +139,14 @@ async function createAWSpipelineCDK({
143139
NEPTUNE_IAM_POLICY_RESOURCE = neptuneClusterInfo.iamPolicyResource;
144140

145141
} catch (error) {
142+
loggerError('Error getting Neptune Cluster Info', error);
146143
if (!quiet) spinner.fail("Error getting Neptune Cluster Info.");
147144
if (!isNeptuneIAMAuth) {
148145
spinner.clear();
149-
console.error("VPC data is not available to proceed.");
146+
loggerError("VPC data is not available to proceed.");
150147
process.exit(1);
151148
} else {
152-
if (!quiet) console.log("Proceeding without getting Neptune Cluster info.");
149+
loggerInfo("Proceeding without getting Neptune Cluster info.", {toConsole: true});
153150
}
154151
}
155152
}

0 commit comments

Comments
 (0)