Skip to content

Commit

Permalink
refactor: #184 Cleanup debug/log messages and styles (#194)
Browse files Browse the repository at this point in the history
* Showing RG4N and Express sample app debug messages.

* Unifying debug calls re prefix tag and using string templates where not before.

* Unifying console.log calls re prefix tag and using string templates where not before.

* Unifying other console.<something> calls re prefix tag and using string templates where not before.

* Unifying console.<something> calls re prefix tag and using string templates where not before in both example apps

* Prettier

* Updated package-lock

* Update examples/express-sample/bin/www

Co-authored-by: Miguel Beltran <[email protected]>

* Update examples/express-sample/bin/www

Co-authored-by: Miguel Beltran <[email protected]>

---------

Co-authored-by: Sumitra Manga <[email protected]>
Co-authored-by: Miguel Beltran <[email protected]>
  • Loading branch information
3 people authored May 8, 2024
1 parent f55da01 commit ad719b4
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 32 deletions.
4 changes: 3 additions & 1 deletion examples/express-sample/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
var config = require("config");

if (config.Raygun.Key === "YOUR_API_KEY") {
console.error("You need to set your Raygun API key in the config file");
console.error(
`[Raygun4Node-Express-Sample] You need to set your Raygun API key in the config file`,
);
process.exit(1);
}

Expand Down
4 changes: 2 additions & 2 deletions examples/express-sample/bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ function onError(error) {
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
console.error(`[Raygun4Node-Express-Sample] ` + bind + ` requires elevated privileges`);
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
console.error(`[Raygun4Node-Express-Sample] ` + bind + ` is already in use`);
process.exit(1);
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion examples/express-sample/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/express-sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"private": true,
"scripts": {
"start": "DEBUG=express-sample:server node ./bin/www"
"start": "DEBUG=raygun,express-sample:server node ./bin/www"
},
"dependencies": {
"body-parser": "^1.20.2",
Expand Down
12 changes: 8 additions & 4 deletions examples/using-domains/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
var config = require("config");

if (config.Raygun.Key === "YOUR_API_KEY") {
console.error("You need to set your Raygun API key in the config file");
console.error(
`[Raygun4Node-Domains-Sample] You need to set your Raygun API key in the config file`,
);
process.exit(1);
}

Expand All @@ -15,13 +17,15 @@ var appDomain = require("domain").create();
// Add the error handler so we can pass errors to Raygun when the domain
// crashes
appDomain.on("error", function (err) {
console.log(`Domain error caught: ${err}`);
console.log(`[Raygun4Node-Domains-Sample] Domain error caught: ${err}`);
// Try send data to Raygun
raygunClient
.send(err)
.then((message) => {
// Exit the process once the error has been sent
console.log("Error sent to Raygun, exiting process");
console.log(
`[Raygun4Node-Domains-Sample] Error sent to Raygun, exiting process`,
);
process.exit(1);
})
.catch((error) => {
Expand All @@ -36,7 +40,7 @@ appDomain.on("error", function (err) {
appDomain.run(function () {
var fs = require("fs");

console.log("Running example app");
console.log(`[Raygun4Node-Domains-Sample] Running example app`);

// Try and read a file that doesn't exist
fs.readFile("badfile.json", "utf8", function (err, file) {
Expand Down
10 changes: 5 additions & 5 deletions lib/raygun.batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class RaygunBatchTransport {

stopProcessing() {
if (this.timerId) {
debug("batch transport - stopping");
debug(`[raygun.batch.ts] Batch transport - stopping`);
clearInterval(this.timerId);

this.timerId = null;
Expand Down Expand Up @@ -128,7 +128,7 @@ export class RaygunBatchTransport {
const { payload, messageCount, callbacks } = batch;

debug(
`batch transport - processing ( ${messageCount} message(s) in batch)`,
`[raygun.batch.ts] Batch transport - processing (${messageCount} message(s) in batch)`,
);

const batchId = this.batchId;
Expand All @@ -142,11 +142,11 @@ export class RaygunBatchTransport {
const durationInMs = stopTimer();
if (err) {
debug(
`batch transport - error sending batch (id=${batchId}, duration=${durationInMs}ms): ${err}`,
`[raygun.batch.ts] Batch transport - error sending batch (id=${batchId}, duration=${durationInMs}ms): ${err}`,
);
} else {
debug(
`batch transport - successfully sent batch (id=${batchId}, duration=${durationInMs}ms)`,
`[raygun.batch.ts] Batch transport - successfully sent batch (id=${batchId}, duration=${durationInMs}ms)`,
);
}

Expand All @@ -159,7 +159,7 @@ export class RaygunBatchTransport {
};

debug(
`batch transport - sending batch (id=${batchId}) (${messageCount} messages, ${payload.length} bytes)`,
`[raygun.batch.ts] Batch transport - sending batch (id=${batchId}, ${messageCount} messages, ${payload.length} bytes)`,
);

const stopTimer = startTimer();
Expand Down
16 changes: 9 additions & 7 deletions lib/raygun.offline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class OfflineStorage implements IOfflineStorage {
this.cacheLimit = offlineStorageOptions.cacheLimit || 100;

debug(
`offline storage - initialized (cachePath=${this.cachePath}, cacheLimit=${this.cacheLimit}`,
`[raygun.offline.ts] Offline storage - initialized (cachePath=${this.cachePath}, cacheLimit=${this.cacheLimit})`,
);

if (!fs.existsSync(this.cachePath)) {
Expand All @@ -63,23 +63,25 @@ export class OfflineStorage implements IOfflineStorage {

fs.readdir(this.cachePath, (err, files) => {
if (err) {
console.log("[Raygun] Error reading cache folder");
console.log(`[Raygun4Node] Error reading cache folder`);
console.log(err);
return callback(err);
}

if (files.length > this.cacheLimit) {
console.log("[Raygun] Error cache reached limit");
console.log(`[Raygun4Node] Error cache reached limit`);
return callback(null);
}

fs.writeFile(filename, transportItem, "utf8", function (err) {
if (!err) {
debug(`offline storage - wrote message to ${filename}`);
debug(
`[raygun.offline.ts] Offline storage - wrote message to ${filename}`,
);
return callback(null);
}

console.log("[Raygun] Error writing to cache folder");
console.log(`[Raygun4Node] Error writing to cache folder`);
console.log(err);

return callback(err);
Expand All @@ -96,14 +98,14 @@ export class OfflineStorage implements IOfflineStorage {
send(callback: (error: Error | null, items?: string[]) => void) {
this.retrieve((err, items) => {
if (err) {
console.log("[Raygun] Error reading cache folder");
console.log(`[Raygun4Node] Error reading cache folder`);
console.log(err);
return callback(err);
}

if (items.length > 0) {
debug(
"offline storage - transporting ${items.length} message(s) from cache",
`[raygun.offline.ts] Offline storage - transporting ${items.length} message(s) from cache`,
);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/raygun.sync.transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function send(options: SendOptionsWithoutCB) {
} catch (e) {
// TODO: Is there a reason we ignore errors here?
console.log(
`Raygun: error ${e} occurred while attempting to send error with message: ${options.message}`,
`[Raygun4Node] Error ${e} occurred while attempting to send error with message: ${options.message}`,
);
}
}
4 changes: 2 additions & 2 deletions lib/raygun.sync.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ transport.send(sendOptions);

function callback(error: Error | null, result: IncomingMessage | null) {
if (error) {
console.log("Error sending with sync transport", error);
console.log(`[Raygun4Node] Error sending with sync transport`, error);
} else {
console.log(
"[raygun-apm] Successfully reported uncaught exception to Raygun",
`[Raygun4Node] Successfully reported uncaught exception to Raygun`,
);
}
}
4 changes: 2 additions & 2 deletions lib/raygun.transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function send(options: SendOptions, path = DEFAULT_ENDPOINT) {

request.on("error", function (e) {
console.log(
`Raygun: error ${e.message} occurred while attempting to send error with message: ${options.message}`,
`[Raygun4Node] Error ${e.message} occurred while attempting to send error with message: ${options.message}`,
);

// If the callback has two parameters, it should expect an `error` value.
Expand All @@ -74,7 +74,7 @@ export function send(options: SendOptions, path = DEFAULT_ENDPOINT) {
} catch (e) {
// TODO: Non-HTTP errors are being ignored, should be better pass them up?
console.log(
`Raygun: error ${e} occurred while attempting to send error with message: ${options.message}`,
`[Raygun4Node] Error ${e} occurred while attempting to send error with message: ${options.message}`,
);
}
}
16 changes: 10 additions & 6 deletions lib/raygun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class Raygun {
this._reportColumnNumbers = options.reportColumnNumbers;
this._innerErrorFieldName = options.innerErrorFieldName || "cause"; // VError function to retrieve inner error;

debug(`client initialized`);
debug(`[raygun.ts] Client initialized`);

if (options.reportUncaughtExceptions) {
this.reportUncaughtExceptions();
Expand Down Expand Up @@ -240,7 +240,7 @@ class Raygun {

if (!sendOptionsResult.valid) {
console.error(
`Encountered an error sending an error to Raygun. No API key is configured, please ensure .init is called with api key. See docs for more info.`,
`[Raygun4Node] Encountered an error sending an error to Raygun. No API key is configured, please ensure .init() is called with api key. See docs for more info.`,
);
return sendOptionsResult.message;
}
Expand Down Expand Up @@ -273,7 +273,7 @@ class Raygun {
(major === 13 && minor < 7)
) {
console.log(
"[Raygun] Warning: reportUncaughtExceptions requires at least Node v12.17.0 or v13.7.0. Uncaught exceptions will not be automatically reported.",
`[Raygun4Node] Warning: reportUncaughtExceptions requires at least Node v12.17.0 or v13.7.0. Uncaught exceptions will not be automatically reported.`,
);

return;
Expand Down Expand Up @@ -328,7 +328,7 @@ class Raygun {

stop() {
if (this._batchTransport) {
debug("batch transport stopped");
debug(`[raygun.ts] Batch transport stopped`);
this._batchTransport.stopProcessing();
}
}
Expand Down Expand Up @@ -400,9 +400,13 @@ class Raygun {
) {
const durationInMs = stopTimer();
if (error) {
debug(`error sending message (duration=${durationInMs}ms): ${error}`);
debug(
`[raygun.ts] Error sending message (duration=${durationInMs}ms): ${error}`,
);
} else {
debug(`successfully sent message (duration=${durationInMs}ms)`);
debug(
`[raygun.ts] Successfully sent message (duration=${durationInMs}ms)`,
);
}
if (!callback) {
return;
Expand Down

0 comments on commit ad719b4

Please sign in to comment.