Skip to content

Commit

Permalink
fix logging in ga & log-on-stack-trace
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-atr committed Nov 16, 2022
1 parent 4d2cb8f commit 3ae7455
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/helpers/log-utils.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* Logs message to console.
* Used when logging is a part of a scriptlet's functionality.
* @param {string} message
* @param {...string} message
*/
export const logMessage = (message) => {
export const logMessage = (...args) => {
// eslint-disable-next-line no-console
console.log(message);
console.log(...args);
};

/**
Expand Down
18 changes: 11 additions & 7 deletions src/redirects/google-analytics-ga.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/* eslint-disable no-underscore-dangle */
import { hit, noopFunc } from '../helpers/index';
import {
hit,
noopFunc,
logVerbose,
} from '../helpers/index';

/**
* @redirect google-analytics-ga
Expand Down Expand Up @@ -93,11 +97,7 @@ export function GoogleAnalyticsGa(source) {
try {
window.location.assign(url);
} catch (e) {
// log the error only while debugging
if (source.verbose) {
// eslint-disable-next-line no-console
console.log(e);
}
logVerbose(e, source.verbose);
}
};

Expand Down Expand Up @@ -128,4 +128,8 @@ GoogleAnalyticsGa.names = [
'google-analytics_ga.js',
];

GoogleAnalyticsGa.injections = [hit, noopFunc];
GoogleAnalyticsGa.injections = [
hit,
noopFunc,
logVerbose,
];
6 changes: 4 additions & 2 deletions src/scriptlets/log-on-stack-trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
getPropertyInChain,
setPropertyAccess,
hit,
logMessage,
// following helpers should be imported and injected
// because they are used by helpers above
isEmptyObject,
Expand Down Expand Up @@ -83,13 +84,13 @@ export function logOnStacktrace(source, property) {
setPropertyAccess(base, prop, {
get() {
hit(source);
console.log(`%cGet %c${prop}`, 'color:red;', 'color:green;');
logMessage(`%cGet %c${prop}`, 'color:red;', 'color:green;');
console.table(refineStackTrace(new Error().stack));
return value;
},
set(newValue) {
hit(source);
console.log(`%cSet %c${prop}`, 'color:red;', 'color:green;');
logMessage(`%cSet %c${prop}`, 'color:red;', 'color:green;');
console.table(refineStackTrace(new Error().stack));
value = newValue;
},
Expand All @@ -107,5 +108,6 @@ logOnStacktrace.injections = [
getPropertyInChain,
setPropertyAccess,
hit,
logMessage,
isEmptyObject,
];

0 comments on commit 3ae7455

Please sign in to comment.