un-cli 0.0.72 → 0.0.73

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.mjs +86 -85
  2. package/logger.mjs +16 -2
  3. package/package.json +1 -1
package/index.mjs CHANGED
@@ -7,7 +7,7 @@ import { AdminLog } from "./adminlog.mjs"
7
7
  import logger from "./logger.mjs"
8
8
  import fetch from "node-fetch"
9
9
  //update version
10
- let version = "0.0.72";
10
+ let version = "0.0.73";
11
11
  const GENERATE_TOKEN_TIME_MIN = 30;
12
12
 
13
13
  let rl = null;
@@ -53,10 +53,10 @@ function parseInput(){
53
53
 
54
54
  if (Object.values(params).includes(null))
55
55
  {
56
- console.log ("HELP: uncli --portal https://unportal.domain.com/portal --service servicename --user username --password password [--gdbversion* user.version --server https://federatedserver.domain.com/server --file commandfile* --verify true|false]")
57
- console.log("--file commandfile is optional and you can pass a path to a file with a list of command to execute. ")
58
- console.log("--gdbversion is optional and allows the UN to be opened in that version. When not specified sde.DEFAULT is used.")
59
- console.log("--server is optional except when there are more than one federated server sites to the portal. If the portal only has one server it will be selected.")
56
+ logger.info ("HELP: uncli --portal https://unportal.domain.com/portal --service servicename --user username --password password [--gdbversion* user.version --server https://federatedserver.domain.com/server --file commandfile* --verify true|false]")
57
+ logger.info("--file commandfile is optional and you can pass a path to a file with a list of command to execute. ")
58
+ logger.info("--gdbversion is optional and allows the UN to be opened in that version. When not specified sde.DEFAULT is used.")
59
+ logger.info("--server is optional except when there are more than one federated server sites to the portal. If the portal only has one server it will be selected.")
60
60
  process.exit();
61
61
  }
62
62
 
@@ -73,7 +73,7 @@ async function getToken(parameters) {
73
73
  }
74
74
 
75
75
  async function regenerateToken(parameters) {
76
- console.log("Regenerating token.")
76
+ logger.info("Regenerating token.")
77
77
  const token = await getToken(parameters);
78
78
  un.token = token;
79
79
  executeInput("clear");
@@ -193,7 +193,7 @@ const inputs = {
193
193
  },
194
194
  "^whoami$": async () => {
195
195
 
196
- console.log(`${parameters.user}@${parameters.service}@${parameters.gdbversion}`)
196
+ logger.info(`${parameters.user}@${parameters.service}@${parameters.gdbversion}`)
197
197
 
198
198
  },
199
199
  "^def --layers$|^layers$": async () => {
@@ -231,20 +231,20 @@ const inputs = {
231
231
 
232
232
  const subnetworks = await un.getSubnetworks();
233
233
  if (subnetworks.features.length === 0) {
234
- console.log("No dirty subnetworks found.")
234
+ logger.info("No dirty subnetworks found.")
235
235
  return;
236
236
  }
237
237
  const subs = subnetworks.features.map(a => a.attributes)
238
238
  console.table(subs)
239
239
  const rowCount = subs.length;
240
- console.log (`${numberWithCommas(rowCount)} rows returned.`)
240
+ logger.info (`${numberWithCommas(rowCount)} rows returned.`)
241
241
  },
242
242
  "^topology$": async () => {
243
243
  const moments = ["initialEnableTopology","fullValidateTopology","partialValidateTopology","enableTopology","disableTopology","definitionModification","updateIsConnected"]
244
244
  const networkMoments = await un.queryMoment(moments)
245
245
  // networkMoments.forEach (m => momentsText += `\n${m.moment} : ${m.time === 0 ? "N/A": new Date(m.time*1000)} ${m.duration === 0 ? "" : ` Duration: ${Math.round(m.duration/1000)}s `} `)
246
246
  // networkMoments.forEach (m => momentsText += `\n${m.moment} : ${m.time === 0 ? "N/A": new Date(m.time*1000)} ${m.duration === 0 ? "" : ` Duration: ${Math.round(m.duration/1000)}s `} `)
247
- // console.log('\x1b[36m%s\x1b[0m', 'I am cyan'); //cyan
247
+ // logger.info('\x1b[36m%s\x1b[0m', 'I am cyan'); //cyan
248
248
  const topoMoments = networkMoments.networkMoments.map(m => {
249
249
  const t = m.time === 0 ? "N/A": new Date(m.time*1000)
250
250
  const d = m.duration === 0 ? "N/A" : numberWithCommas(Math.round(m.duration)) + " ms"
@@ -260,7 +260,7 @@ const inputs = {
260
260
  console.table(topoMoments)
261
261
  },
262
262
  "^topology --enable$": async () => {
263
- console.log("Enabling topology ...");
263
+ logger.info("Enabling topology ...");
264
264
  const fromDate = new Date();
265
265
  const result = await un.enableTopology()
266
266
  const toDate = new Date();
@@ -270,7 +270,7 @@ const inputs = {
270
270
  },
271
271
  "^topology --disable$": async () => {
272
272
  const fromDate = new Date();
273
- console.log("Disabling topology ...");
273
+ logger.info("Disabling topology ...");
274
274
  const result = await un.disableTopology()
275
275
  const toDate = new Date();
276
276
  const timeEnable = toDate.getTime() - fromDate.getTime();
@@ -279,25 +279,25 @@ const inputs = {
279
279
  },
280
280
  "^evaluate$": async () => {
281
281
  const fromDate = new Date();
282
- console.log("Building Evaluation Blocks ...");
282
+ logger.info("Building Evaluation Blocks ...");
283
283
  //return evaluation blocks for layer 5
284
284
  const blocks = await buildEvaluationBlocks(5);
285
285
 
286
- console.log("Evaluating Attribute Rules ...");
286
+ logger.info("Evaluating Attribute Rules ...");
287
287
  //blocks.forEach(b => un.evaluate (null, b, ["validationRules", "calculationRules"], async = false, gdbVersion = "sde.DEFAULT"))
288
- //Object.keys(blocks).forEach(k => console.log(blocks[k]))
288
+ //Object.keys(blocks).forEach(k => logger.info(blocks[k]))
289
289
  const promises = []
290
290
  Object.keys(blocks).forEach(k => promises.push(un.evaluate (null, blocks[k], ["validationRules", "calculationRules"] )))
291
291
 
292
- console.log("done sending all requests.. now waiting for response ")
292
+ logger.info("done sending all requests.. now waiting for response ")
293
293
 
294
- Promise.all(promises).then(a=>console.log("done")).catch(a=>console.log("failed" + JSON.stringify(a)))
294
+ Promise.all(promises).then(a=>logger.info("done")).catch(a=>logger.info("failed" + JSON.stringify(a)))
295
295
 
296
296
  const result = {}
297
297
  const toDate = new Date();
298
298
  const timeEnable = toDate.getTime() - fromDate.getTime();
299
299
  result.duration = numberWithCommas(Math.round(timeEnable)) + " ms"
300
- console.log(result)
300
+ logger.info(result)
301
301
  },
302
302
 
303
303
  //partition so that we can run and commit incrementally..
@@ -305,7 +305,7 @@ const inputs = {
305
305
  //timeouts
306
306
  //in case failure you don't lose everything
307
307
  "^topology --validate -fn$": async () => {
308
- console.log("Validating Network topology ...");
308
+ logger.info("Validating Network topology ...");
309
309
 
310
310
  const fullExtent = un.featureServiceJson.fullExtent;
311
311
  /*
@@ -343,7 +343,7 @@ const inputs = {
343
343
  const timeEnable = toDate.getTime() - fromDate.getTime();
344
344
  const duration = numberWithCommas(Math.round(timeEnable)) + " ms"
345
345
  console.clear()
346
- console.log("Validating extent " + e.xmin)
346
+ logger.info("Validating extent " + e.xmin)
347
347
  console.table({duration})
348
348
 
349
349
  })
@@ -352,7 +352,7 @@ const inputs = {
352
352
  },
353
353
 
354
354
  "^topology --validate$": async () => {
355
- console.log("Validating Network topology ...");
355
+ logger.info("Validating Network topology ...");
356
356
  const fromDate = new Date();
357
357
  const result = await un.validateNetworkTopology()
358
358
  const toDate = new Date();
@@ -363,35 +363,35 @@ const inputs = {
363
363
  "^subnetworks --dirty$": async () => {
364
364
  const subnetworks = await un.getSubnetworks("isdirty=1");
365
365
  if (subnetworks.features.length === 0) {
366
- console.log("No dirty subnetworks found.")
366
+ logger.info("No dirty subnetworks found.")
367
367
  return;
368
368
  }
369
369
 
370
370
  const subs = subnetworks.features.map(a => a.attributes)
371
371
  console.table(subs)
372
372
  const rowCount = subs.length;
373
- console.log (`${numberWithCommas(rowCount)} rows returned.`)
373
+ logger.info (`${numberWithCommas(rowCount)} rows returned.`)
374
374
  },
375
375
  "^subnetworks --deleted$": async () => {
376
376
  const subnetworks = await un.getSubnetworks("isdirty=1 and isdeleted=1");
377
377
  if (subnetworks.features.length === 0) {
378
- console.log("No dirty and deleted subnetworks found.")
378
+ logger.info("No dirty and deleted subnetworks found.")
379
379
  return;
380
380
  }
381
381
 
382
382
  const subs = subnetworks.features.map(a => a.attributes)
383
383
  console.table(subs)
384
384
  const rowCount = subs.length;
385
- console.log (`${numberWithCommas(rowCount)} rows returned.`)
385
+ logger.info (`${numberWithCommas(rowCount)} rows returned.`)
386
386
  },
387
387
 
388
388
  "^update subnetworks --deleted$" : async () => {
389
- console.log("Querying all subnetworks that are dirty and deleted.");
389
+ logger.info("Querying all subnetworks that are dirty and deleted.");
390
390
  let subnetworks = await un.queryDistinct(500002, "domainnetworkname,tiername,subnetworkname", "isdirty=1 and isdeleted=1","domainnetworkname,tiername,subnetworkname");
391
- console.log(`Discovered ${subnetworks.features.length} dirty deleted subnetworks.`);
391
+ logger.info(`Discovered ${subnetworks.features.length} dirty deleted subnetworks.`);
392
392
  for (let i = 0; i < subnetworks.features.length; i++) {
393
393
  const f = subnetworks.features[i]
394
- console.log("Updating Subnetwork " + v(f.attributes,"subnetworkName"));
394
+ logger.info("Updating Subnetwork " + v(f.attributes,"subnetworkName"));
395
395
 
396
396
  const fromDate = new Date();
397
397
 
@@ -404,7 +404,7 @@ const inputs = {
404
404
  subnetworkResult.duration = numberWithCommas(Math.round(timeEnable)) + " ms"
405
405
 
406
406
 
407
- console.log(`Result ${JSON.stringify(subnetworkResult)}`)
407
+ logger.info(`Result ${JSON.stringify(subnetworkResult)}`)
408
408
  }
409
409
  },
410
410
 
@@ -422,27 +422,28 @@ const inputs = {
422
422
  if (failedSubnetworks.length > 0 )
423
423
  failedSubWhereClause = " AND SUBNETWORKNAME NOT IN (" + failedSubnetworks.join(",") + ")"
424
424
 
425
- console.log("Querying all subnetworks that are dirty.");
425
+ logger.info("Querying all subnetworks that are dirty.");
426
426
  subnetworks = await un.queryDistinct(500002, "domainnetworkname,tiername,subnetworkname", "isdirty=1 " + failedSubWhereClause, `domainnetworkname ${sort},tiername ${sort},subnetworkname ${sort}`);
427
- console.log(`Discovered ${subnetworks.features.length} dirty subnetworks.`);
427
+ logger.info(`Discovered ${subnetworks.features.length} dirty subnetworks.`);
428
428
 
429
429
  for (let i = 0; i < subnetworks.features.length; i++) {
430
430
  const f = subnetworks.features[i]
431
431
  const subnetworkName = v(f.attributes,"subnetworkName")
432
- console.log("Updating Subnetwork " + subnetworkName);
432
+ logger.info("Updating Subnetwork " + subnetworkName);
433
433
 
434
434
  const fromDate = new Date();
435
435
 
436
436
  const subnetworkResult = await un.updateSubnetworks(v(f.attributes,"domainNetworkName"), v(f.attributes,"tierName"), v(f.attributes,"subnetworkName"),false);
437
437
  //check if we have processed this subnetwork (maybe be an error)
438
- if (subnetworkResult.success == false)
438
+ const tier = un.getTier(v(f.attributes,"domainNetworkName"), v(f.attributes,"tierName"))
439
+ if (subnetworkResult.success == false || tier.manageSubnetwork?.propertySetItems?.includes("IsDirty"))
439
440
  failedSubnetworks.push("'" + subnetworkName + "'")
440
441
 
441
442
  const toDate = new Date();
442
443
  const timeEnable = toDate.getTime() - fromDate.getTime();
443
444
  subnetworkResult.duration = numberWithCommas(Math.round(timeEnable)) + " ms"
444
445
 
445
- console.log(`Result ${JSON.stringify(subnetworkResult)}`)
446
+ logger.info(`Result ${JSON.stringify(subnetworkResult)}`)
446
447
  }
447
448
 
448
449
  }
@@ -450,14 +451,14 @@ const inputs = {
450
451
 
451
452
  },
452
453
  "^update subnetworks --all --async$" : async () => {
453
- console.log("Querying all subnetworks that are dirty.");
454
+ logger.info("Querying all subnetworks that are dirty.");
454
455
  let subnetworks = await un.queryDistinct(500002, "domainnetworkname,tiername,subnetworkname", "isdirty=1", "domainnetworkname,tiername,subnetworkname");
455
- console.log(`Discovered ${subnetworks.features.length} dirty subnetworks.`);
456
+ logger.info(`Discovered ${subnetworks.features.length} dirty subnetworks.`);
456
457
  for (let i = 0; i < subnetworks.features.length; i++) {
457
458
  const f = subnetworks.features[i]
458
- console.log("Sending job for " + v(f.attributes,"subnetworkName"));
459
+ logger.info("Sending job for " + v(f.attributes,"subnetworkName"));
459
460
  const subnetworkResult = await un.updateSubnetworks(v(f.attributes,"domainNetworkName"), v(f.attributes,"tierName"), v(f.attributes,"subnetworkName"),true);
460
- console.log(`Result from submitting job ${JSON.stringify(subnetworkResult)}`)
461
+ logger.info(`Result from submitting job ${JSON.stringify(subnetworkResult)}`)
461
462
  }
462
463
  },
463
464
  "^export subnetworks --all --folder .*$|^export subnetworks --all$" : async input => {
@@ -473,13 +474,13 @@ const inputs = {
473
474
 
474
475
  do {
475
476
 
476
- console.log("Querying all subnetworks that are clean.");
477
+ logger.info("Querying all subnetworks that are clean.");
477
478
  subnetworks = await un.queryDistinct(500002, "domainnetworkname,tiername,subnetworkname", "isdirty=0","domainnetworkname,tiername,subnetworkname");
478
- console.log(`Discovered ${subnetworks.features.length} subnetworks that can be exported.`);
479
+ logger.info(`Discovered ${subnetworks.features.length} subnetworks that can be exported.`);
479
480
  for (let i = 0; i < subnetworks.features.length; i++) {
480
481
  const f = subnetworks.features[i]
481
482
  const subnetworkName = v(f.attributes,"subnetworkName")
482
- console.log("Exporting subnetworks " + v(f.attributes,"subnetworkName"));
483
+ logger.info("Exporting subnetworks " + v(f.attributes,"subnetworkName"));
483
484
 
484
485
  const fromDate = new Date();
485
486
 
@@ -494,7 +495,7 @@ const inputs = {
494
495
  //if undefined exit
495
496
  if (!subnetworkResult.url)
496
497
  {
497
- console.log("Export subnetwork failed " + JSON.stringify(subnetworkResult))
498
+ logger.info("Export subnetwork failed " + JSON.stringify(subnetworkResult))
498
499
  continue;
499
500
  }
500
501
 
@@ -507,7 +508,7 @@ const inputs = {
507
508
  fs.writeFileSync(`${inputDir}/${subnetworkName}.json`, jsonExport)
508
509
 
509
510
 
510
- console.log(`Result ${JSON.stringify(subnetworkResult)} written to file ${process.cwd()}/${inputDir}/${subnetworkName}.json`)
511
+ logger.info(`Result ${JSON.stringify(subnetworkResult)} written to file ${process.cwd()}/${inputDir}/${subnetworkName}.json`)
511
512
 
512
513
  }
513
514
  }
@@ -527,20 +528,20 @@ const inputs = {
527
528
  if (!fs.existsSync(inputDir)) fs.mkdirSync(inputDir)
528
529
 
529
530
 
530
- console.log("Querying all subnetworks that are clean and not exported.");
531
+ logger.info("Querying all subnetworks that are clean and not exported.");
531
532
  let subnetworks = await un.queryDistinct(500002, "domainnetworkname,tiername,subnetworkname", "isdirty = 0 and (LASTACKEXPORTSUBNETWORK is null or LASTACKEXPORTSUBNETWORK < LASTUPDATESUBNETWORK)","domainnetworkname,tiername,subnetworkname");
532
- console.log(`Discovered ${subnetworks.features.length} subnetworks that can be exported.`);
533
+ logger.info(`Discovered ${subnetworks.features.length} subnetworks that can be exported.`);
533
534
  for (let i = 0; i < subnetworks.features.length; i++) {
534
535
  const f = subnetworks.features[i]
535
536
  const subnetworkName = v(f.attributes,"subnetworkName")
536
- console.log(`Exporting subnetwork ${subnetworkName}` );
537
+ logger.info(`Exporting subnetwork ${subnetworkName}` );
537
538
  const subnetworkResult = await un.exportSubnetworks(v(f.attributes,"domainNetworkName"), v(f.attributes,"tierName"), v(f.attributes,"subnetworkName"),false);
538
539
  //fetch the json and write it to disk
539
540
  const subContent = await fetch(subnetworkResult.url);
540
541
  const jsonExport = await subContent.text();
541
542
  fs.writeFileSync(`${inputDir}/${subnetworkName}.json`, JSON.stringify(jsonExport))
542
543
 
543
- console.log(`Result ${JSON.stringify(subnetworkResult)} written to file ${process.cwd()}/${inputDir}/${subnetworkName}.json`)
544
+ logger.info(`Result ${JSON.stringify(subnetworkResult)} written to file ${process.cwd()}/${inputDir}/${subnetworkName}.json`)
544
545
  }
545
546
 
546
547
 
@@ -550,7 +551,7 @@ const inputs = {
550
551
  "^ia$": async input => {
551
552
 
552
553
  const result = await un.returnInvalidAssociations();
553
- console.log("Invalid Associations " + JSON.stringify(result))
554
+ logger.info("Invalid Associations " + JSON.stringify(result))
554
555
  },
555
556
  "^connect --service": async input =>{
556
557
 
@@ -573,10 +574,10 @@ const inputs = {
573
574
  if (inputParam != null && inputParam.length > 0)
574
575
  subnetworkName = inputParam[0].replace("--subnetwork ", "")
575
576
 
576
- console.log(`Tracing subnetwork ${subnetworkName}`);
577
+ logger.info(`Tracing subnetwork ${subnetworkName}`);
577
578
  const result = await un.subnetworkTraceSimple(subnetworkName)
578
579
  if (result == null) {
579
- console.log(`Subnetwork ${subnetworkName} doesn't exist`);
580
+ logger.info(`Subnetwork ${subnetworkName} doesn't exist`);
580
581
  return null;
581
582
  }
582
583
  const toDate = new Date();
@@ -598,19 +599,19 @@ const inputs = {
598
599
  if (!fs.existsSync(inputDir)) fs.mkdirSync(inputDir)
599
600
 
600
601
 
601
- console.log("Querying all subnetworks that are clean and deleted.");
602
+ logger.info("Querying all subnetworks that are clean and deleted.");
602
603
  let subnetworks = await un.queryDistinct(500002, "domainnetworkname,tiername,subnetworkname", "isdirty = 0 and isdeleted=1");
603
- console.log(`Discovered ${subnetworks.features.length} subnetworks that can be exported.`);
604
+ logger.info(`Discovered ${subnetworks.features.length} subnetworks that can be exported.`);
604
605
  for (let i = 0; i < subnetworks.features.length; i++) {
605
606
  const f = subnetworks.features[i]
606
607
  const subnetworkName = v(f.attributes,"subnetworkName")
607
- console.log(`Exporting subnetwork ${subnetworkName}` );
608
+ logger.info(`Exporting subnetwork ${subnetworkName}` );
608
609
  const subnetworkResult = await un.exportSubnetworks(v(f.attributes,"domainNetworkName"), v(f.attributes,"tierName"), v(f.attributes,"subnetworkName"),false);
609
610
 
610
611
  //if undefined exit
611
612
  if (!subnetworkResult.url)
612
613
  {
613
- console.log("Export subnetwork failed " + JSON.stringify(subnetworkResult))
614
+ logger.info("Export subnetwork failed " + JSON.stringify(subnetworkResult))
614
615
  continue;
615
616
  }
616
617
 
@@ -619,7 +620,7 @@ const inputs = {
619
620
  const jsonExport = await subContent.text();
620
621
  fs.writeFileSync(`${inputDir}/${subnetworkName}.json`, JSON.stringify(jsonExport))
621
622
 
622
- console.log(`Result ${JSON.stringify(subnetworkResult)} written to file ${process.cwd()}/${inputDir}/${subnetworkName}.json`)
623
+ logger.info(`Result ${JSON.stringify(subnetworkResult)} written to file ${process.cwd()}/${inputDir}/${subnetworkName}.json`)
623
624
  }
624
625
 
625
626
 
@@ -628,7 +629,7 @@ const inputs = {
628
629
  "^cwd$" : async input => {
629
630
 
630
631
 
631
- console.log(process.cwd())
632
+ logger.info(process.cwd())
632
633
 
633
634
  },
634
635
 
@@ -640,14 +641,14 @@ const inputs = {
640
641
  //create directory if doesn't exists
641
642
  if (!fs.existsSync(inputDir)) fs.mkdirSync(inputDir)
642
643
  fs.writeFileSync(`${inputDir}/${Math.random()}`, Math.random())
643
- console.log(inputDir)
644
+ logger.info(inputDir)
644
645
 
645
646
 
646
647
  },
647
648
 
648
649
 
649
650
  "^count$": async () => {
650
- console.log("Querying all layers....")
651
+ logger.info("Querying all layers....")
651
652
  const layerProperties = [
652
653
  "id",
653
654
  "name",
@@ -681,12 +682,12 @@ const inputs = {
681
682
 
682
683
 
683
684
  console.table(layerCount)
684
- console.log(`Total number of rows in all layers : ${numberWithCommas(totalRows)} .`)
685
+ logger.info(`Total number of rows in all layers : ${numberWithCommas(totalRows)} .`)
685
686
  },
686
687
 
687
688
 
688
689
  "^count --system$": async () => {
689
- console.log("Querying all system layers....")
690
+ logger.info("Querying all system layers....")
690
691
 
691
692
  const systemLayers = un.getSystemLayers();
692
693
  let totalRows = 0;
@@ -709,7 +710,7 @@ const inputs = {
709
710
  }
710
711
 
711
712
  console.table(layerCount)
712
- console.log(`Total number of rows in all system layers : ${numberWithCommas(totalRows)} .`)
713
+ logger.info(`Total number of rows in all system layers : ${numberWithCommas(totalRows)} .`)
713
714
 
714
715
  },
715
716
 
@@ -724,7 +725,7 @@ const inputs = {
724
725
  mins = inputParam[0].replace("--age ", "")
725
726
 
726
727
 
727
- console.log(`Querying attribute rules logs for ${parameters.service} for the last ${mins} minutes ...`)
728
+ logger.info(`Querying attribute rules logs for ${parameters.service} for the last ${mins} minutes ...`)
728
729
 
729
730
  const startTime = Date.now() - mins*60*1000
730
731
  const endTime = Date.now();
@@ -774,7 +775,7 @@ const inputs = {
774
775
  if (inputParam != null && inputParam.length > 0)
775
776
  mins = inputParam[0].replace("--age ", "")
776
777
 
777
- console.log(`Querying trace logs for ${parameters.service} for the last ${mins} minutes ...`)
778
+ logger.info(`Querying trace logs for ${parameters.service} for the last ${mins} minutes ...`)
778
779
  const startTime = Date.now() - mins*60*1000
779
780
  const endTime = Date.now();
780
781
  let result= await adminLog.query([102002], [parameters.service+ ".MapServer"], topLogCount, startTime ,endTime , "VERBOSE")
@@ -815,7 +816,7 @@ const inputs = {
815
816
  delete newMessage.message
816
817
 
817
818
  console.table([newMessage])
818
- console.log(m.message)
819
+ logger.info(m.message)
819
820
  })
820
821
 
821
822
  },
@@ -833,7 +834,7 @@ const inputs = {
833
834
  mins = inputParam[0].replace("--age ", "")
834
835
 
835
836
 
836
- console.log(`Querying validate logs for ${parameters.service} for the last ${mins} minutes ...`)
837
+ logger.info(`Querying validate logs for ${parameters.service} for the last ${mins} minutes ...`)
837
838
  const startTime = Date.now() - mins*60*1000
838
839
  const endTime = Date.now();
839
840
  let result= await adminLog.query([102003], [parameters.service+ ".MapServer"], topLogCount, startTime ,endTime , "VERBOSE")
@@ -898,7 +899,7 @@ const inputs = {
898
899
  delete newMessage.message
899
900
 
900
901
  console.table([newMessage])
901
- console.log(m.message)
902
+ logger.info(m.message)
902
903
  })
903
904
 
904
905
 
@@ -917,7 +918,7 @@ const inputs = {
917
918
  if (inputParam != null && inputParam.length > 0)
918
919
  mins = inputParam[0].replace("--age ", "")
919
920
 
920
- console.log(`Querying subnetwork logs for ${parameters.service} for the last ${mins} minutes ...`)
921
+ logger.info(`Querying subnetwork logs for ${parameters.service} for the last ${mins} minutes ...`)
921
922
  const startTime = Date.now() - mins*60*1000
922
923
  const endTime = Date.now();
923
924
  let result= await adminLog.query([102003], [parameters.service+ ".MapServer"], topLogCount, startTime ,endTime , "VERBOSE")
@@ -982,7 +983,7 @@ const inputs = {
982
983
  delete newMessage.message
983
984
 
984
985
  console.table([newMessage])
985
- console.log(m.message)
986
+ logger.info(m.message)
986
987
  })
987
988
 
988
989
 
@@ -999,7 +1000,7 @@ const inputs = {
999
1000
  if (inputParam != null && inputParam.length > 0)
1000
1001
  mins = inputParam[0].replace("--age ", "")
1001
1002
 
1002
- console.log(`Querying cursor sql logs for ${parameters.service} for the last ${mins} minutes ...`)
1003
+ logger.info(`Querying cursor sql logs for ${parameters.service} for the last ${mins} minutes ...`)
1003
1004
  const startTime = Date.now() - mins*60*1000
1004
1005
  const endTime = Date.now();
1005
1006
  let result= await adminLog.query([102023], [parameters.service+ ".MapServer"], topLogCount, startTime ,endTime , "DEBUG")
@@ -1015,7 +1016,7 @@ const inputs = {
1015
1016
 
1016
1017
  allMessages = allMessages.concat(jsonRes.logMessages.filter(m => m.message.indexOf("EndCursor;") > -1))
1017
1018
  }
1018
- console.log ("Filtering messages...")
1019
+ logger.info ("Filtering messages...")
1019
1020
 
1020
1021
  allMessages = allMessages
1021
1022
  .map( m=> {
@@ -1029,21 +1030,21 @@ const inputs = {
1029
1030
  .slice(0, 10) ;//first 10
1030
1031
 
1031
1032
 
1032
- console.log("-----Top 10 SQL----")
1033
+ logger.info("-----Top 10 SQL----")
1033
1034
  let i =0;
1034
1035
  allMessages= allMessages.forEach(m =>
1035
1036
  {
1036
1037
 
1037
1038
  const x = m.message.split(";")
1038
1039
  x.shift()
1039
- console.log(`id: ${i++}`)
1040
- console.log(`\tAt: ${new Date(m.time)} (${m.time})`)
1041
- console.log(`\tUser: ${m.user}`)
1042
- console.log(`\tTotal Time: ${numberWithCommas(Math.round(m.elapsed*1000))} ms (Total time the cursor was opened)`)
1043
- console.log(`\tQuery Time: ${numberWithCommas(m.totalExecutionElapsed)} ms (includes search + data access nextRow)`)
1044
- console.log(`\tQuery:`)
1045
- x.forEach(a => console.log(`\t${a}`))
1046
- console.log(`\n`)
1040
+ logger.info(`id: ${i++}`)
1041
+ logger.info(`\tAt: ${new Date(m.time)} (${m.time})`)
1042
+ logger.info(`\tUser: ${m.user}`)
1043
+ logger.info(`\tTotal Time: ${numberWithCommas(Math.round(m.elapsed*1000))} ms (Total time the cursor was opened)`)
1044
+ logger.info(`\tQuery Time: ${numberWithCommas(m.totalExecutionElapsed)} ms (includes search + data access nextRow)`)
1045
+ logger.info(`\tQuery:`)
1046
+ x.forEach(a => logger.info(`\t${a}`))
1047
+ logger.info(`\n`)
1047
1048
 
1048
1049
  })
1049
1050
 
@@ -1155,11 +1156,11 @@ const inputs = {
1155
1156
  console.table(rules)
1156
1157
 
1157
1158
  const totalARExecution = rules.reduce( (prev, cur) => prev + cur["Total Cost (ms)"], 0)
1158
- console.log(`Total time spend executing attribute rules (${Math.round(totalARExecution)} ms) (${Math.round(totalARExecution/1000)} s) (${Math.round(totalARExecution/(1000*60))} m)`)
1159
+ logger.info(`Total time spend executing attribute rules (${Math.round(totalARExecution)} ms) (${Math.round(totalARExecution/1000)} s) (${Math.round(totalARExecution/(1000*60))} m)`)
1159
1160
 
1160
1161
  },
1161
1162
 
1162
- "^version$": () => console.log(version),
1163
+ "^version$": () => logger.info(version),
1163
1164
  "^clear$|^cls$": () => console.clear(),
1164
1165
  "^quit$": () => {
1165
1166
  if (rl) rl.close();
@@ -1184,7 +1185,7 @@ const inputs = {
1184
1185
 
1185
1186
  while(true) {
1186
1187
  const result = await un.query(layerId, `1=1`, undefined, undefined, ["globalId"], "sde.DEFAULT", offset, recordCount)
1187
- console.log(`Processing ${recordCount} rows`)
1188
+ logger.info(`Processing ${recordCount} rows`)
1188
1189
  //for each assocaition check if its valid
1189
1190
  for (let i = 0 ; i < result.features.length; i++){
1190
1191
  const row = result.features[i]
@@ -1299,7 +1300,7 @@ function numberWithCommas(x) {
1299
1300
  /*
1300
1301
  rl.question("What is your name ? ", function(name) {
1301
1302
  rl.question("Where do you live ? ", function(country) {
1302
- console.log(`${name}, is a citizen of ${country}`);
1303
+ logger.info(`${name}, is a citizen of ${country}`);
1303
1304
  rl.close();
1304
1305
  });
1305
1306
  });
@@ -1312,7 +1313,7 @@ function setupReadLine() {
1312
1313
  });
1313
1314
 
1314
1315
  rl.on("close", function() {
1315
- console.log("\nbye");
1316
+ logger.info("\nbye");
1316
1317
  process.exit(0);
1317
1318
  });
1318
1319
 
@@ -1334,7 +1335,7 @@ export async function run (){
1334
1335
  console.error(`Minimum required node js is ${minVer} your version is ${process.version}`)
1335
1336
  process.exit(0);
1336
1337
  }
1337
- console.log(`uncli ${version} is experimental command line utility for basic utility network services. Use as is.`)
1338
+ logger.info(`uncli ${version} is experimental command line utility for basic utility network services. Use as is.`)
1338
1339
  parameters = await parseInput( )
1339
1340
  //set certificate verification
1340
1341
  const verifyCert = parameters["verify"] === 'true' ? 1 : 0;
package/logger.mjs CHANGED
@@ -1,9 +1,23 @@
1
1
  const logger = {}
2
- logger.info = console.log
3
- logger.error = console.error
2
+ logger.info = m => console.log (`${shortDate()}: ${m}`)
3
+ logger.error =m => console.error (`${shortDate()}: ${m}`)
4
4
 
5
5
  export default logger;
6
6
 
7
+ function shortDate()
8
+ {
9
+
10
+ const t = new Date();
11
+ const date = ('0' + t.getDate()).slice(-2);
12
+ const month = ('0' + (t.getMonth() + 1)).slice(-2);
13
+ const year = t.getFullYear();
14
+ const hours = ('0' + t.getHours()).slice(-2);
15
+ const minutes = ('0' + t.getMinutes()).slice(-2);
16
+ const seconds = ('0' + t.getSeconds()).slice(-2);
17
+ const time = `${month}/${date}/${year}:${hours}:${minutes}:${seconds}`;
18
+ return time;
19
+ }
20
+
7
21
  /*
8
22
  import winston from "winston"
9
23
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "un-cli",
3
- "version": "0.0.72",
3
+ "version": "0.0.73",
4
4
  "description": "Command line interface for working with ArcGIS Utility Network Extension",
5
5
  "main": "index.mjs",
6
6
  "bin": {