Skip to content

Commit

Permalink
feat(1.2.0): adding config option to set up only some cases of log
Browse files Browse the repository at this point in the history
  • Loading branch information
schirrel committed Jul 27, 2023
1 parent 1c54c2a commit f3fc4eb
Show file tree
Hide file tree
Showing 6 changed files with 462 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ firestore.indexes.json
**/firebase.json
**/firestore.rules
**/firestore.indexes.json

**/.firebase
node_modules
33 changes: 23 additions & 10 deletions lib/remote-logger.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
function DebugRemoteLogger(loggerId) {
function DebugRemoteLogger(loggerId, options = {}) {
var optionsDefined = options.only && options.only.length;

function postData(data = {}) {
var body = JSON.stringify(data);

Expand Down Expand Up @@ -29,6 +31,26 @@ function DebugRemoteLogger(loggerId) {
postData(data);
};

var consoleKeys = Object.keys(console);

if (optionsDefined) {
consoleKeys = consoleKeys.filter((key) =>
options.only.some((only) => only == key)
);
}

consoleKeys.forEach((logType) => {
var sourceLog = console[logType];

console[logType] = function () {
communicate({ arguments, type: logType, date: new Date() });
sourceLog.apply(console, arguments);
};
});

if (optionsDefined && !options.only.some((option) => option == "error"))
return;

addEventListener("error", (evt) => {
communicate({
arguments: {
Expand All @@ -41,15 +63,6 @@ function DebugRemoteLogger(loggerId) {
date: new Date(),
});
});

Object.keys(console).forEach(logType => {
var sourceLog = console[logType]

console[logType] = function () {
communicate({ arguments, type: logType, date: new Date() });
sourceLog.apply(console, arguments);
};
})
}

window.DebugRemoteLogger = DebugRemoteLogger;
2 changes: 1 addition & 1 deletion lib/remote-logger.min.js

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

Loading

0 comments on commit f3fc4eb

Please sign in to comment.