Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: #184 Cleanup debug/log messages and styles #194

Merged
merged 10 commits into from
May 8, 2024
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"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes raygun debug messages show up in the Express sample app.

},
"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 @@ -16,11 +18,13 @@ var appDomain = require("domain").create();
// crashes
appDomain.on("error", function (err) {
try {
console.log(`Domain error caught: ${err}`);
console.log(`[Raygun4Node-Domains-Sample] Domain error caught: ${err}`);
// Try send data to Raygun
raygunClient.send(err, {}, function () {
// 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 (e) {
Expand All @@ -35,7 +39,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 @@ -56,7 +56,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 @@ -123,7 +123,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 @@ -137,11 +137,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 @@ -153,7 +153,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 @@ -47,7 +47,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 @@ -62,23 +62,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 @@ -95,14 +97,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 @@ -26,7 +26,7 @@ export function send(options: SendOptionsWithoutCB) {
syncRequest(options);
} catch (e) {
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 @@ -54,7 +54,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 @@ -67,7 +67,7 @@ export function send(options: SendOptions, path = DEFAULT_ENDPOINT) {
request.end();
} catch (e) {
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 @@ -204,7 +204,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 @@ -234,7 +234,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 @@ -293,7 +293,7 @@ class Raygun {

stop() {
if (this._batchTransport) {
debug("batch transport stopped");
debug(`[raygun.ts] Batch transport stopped`);
this._batchTransport.stopProcessing();
}
}
Expand Down Expand Up @@ -365,9 +365,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