This is an automated email from the ASF dual-hosted git repository.

unclegedd pushed a commit to branch test
in repository https://gitbox.apache.org/repos/asf/flagon-useralejs.git

commit 18b8d0a0cd6a217658188a850776817e8c897c97
Author: Jason Young <[email protected]>
AuthorDate: Tue Apr 25 15:23:17 2023 -0700

    Temporarily reintroduce deprecated functions
---
 src/packageLogs.js       | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 test/packageLogs_spec.js | 30 ++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+)

diff --git a/src/packageLogs.js b/src/packageLogs.js
index 4a3f282..db287d1 100644
--- a/src/packageLogs.js
+++ b/src/packageLogs.js
@@ -29,8 +29,30 @@ let intervalTimer;
 let intervalCounter;
 let intervalLog;
 
+export let filterHandler = null;
+export let mapHandler = null;
 export let cbHandlers = {};
 
+/**
+ * Assigns a handler to filter logs out of the queue.
+ * @deprecated Use addCallbacks and removeCallbacks instead
+ * @param  {Function} callback The handler to invoke when logging.
+ */
+export function setLogFilter(callback) {
+  console.warn("setLogFilter() is deprecated and will be removed in a futre 
release");
+  filterHandler = callback;
+}
+
+/**
+ * Assigns a handler to transform logs from their default structure.
+ * @deprecated Use addCallbacks and removeCallbacks instead
+ * @param  {Function} callback The handler to invoke when logging.
+ */
+export function setLogMapper(callback) {
+  console.warn("setLogMapper() is deprecated and will be removed in a futre 
release");
+  mapHandler = callback;
+}
+
 /**
  * Adds named callbacks to be executed when logging.
  * @param  {Object } newCallbacks An object containing named callback 
functions.
@@ -124,6 +146,14 @@ export function packageLog(e, detailFcn) {
     'sessionID': config.sessionID,
   };
 
+  if ((typeof filterHandler === 'function') && !filterHandler(log)) {
+    return false;
+  }
+
+  if (typeof mapHandler === 'function') {
+    log = mapHandler(log, e);
+  }
+
   for (const func of Object.values(cbHandlers)) {
     if (typeof func === 'function') {
       log = func(log, e);
@@ -173,6 +203,14 @@ export function packageCustomLog(customLog, detailFcn, 
userAction) {
 
     let log = Object.assign(metaData, customLog);
 
+    if ((typeof filterHandler === 'function') && !filterHandler(log)) {
+        return false;
+    }
+
+    if (typeof mapHandler === 'function') {
+        log = mapHandler(log);
+    }
+
     for (const func of Object.values(cbHandlers)) {
       if (typeof func === 'function') {
         log = func(log, null);
@@ -247,6 +285,14 @@ export function packageIntervalLog(e) {
             'sessionID': config.sessionID
         };
 
+        if (typeof filterHandler === 'function' && 
!filterHandler(intervalLog)) {
+          return false;
+        }
+
+        if (typeof mapHandler === 'function') {
+          intervalLog = mapHandler(intervalLog, e);
+        }
+
         for (const func of Object.values(cbHandlers)) {
           if (typeof func === 'function') {
             intervalLog = func(intervalLog, null);
diff --git a/test/packageLogs_spec.js b/test/packageLogs_spec.js
index def256b..32c443d 100644
--- a/test/packageLogs_spec.js
+++ b/test/packageLogs_spec.js
@@ -22,16 +22,46 @@ import {
     buildPath,
     cbHandlers,
     extractTimeFields,
+    filterHandler,
     getLocation,
     getSelector,
     initPackager,
     logs,
+    mapHandler,
     packageLog,
     removeCallbacks,
     selectorizePath,
+    setLogFilter,
+    setLogMapper,
 } from '../src/packageLogs';
 
 describe('packageLogs', () => {
+    describe('setLogFilter', () => {
+        it('assigns the handler to the provided value', () => {
+            const func = x => true;
+            setLogFilter(func);
+            expect(filterHandler).to.equal(func);
+        });
+        it('allows the handler to be nulled', () => {
+            setLogFilter(x => true);
+            setLogFilter(null);
+            expect(filterHandler).to.equal(null);
+        });
+    });
+
+    describe('setLogMapper', () => {
+        it('assigns the handler to the provided value', () => {
+            const func = x => true;
+            setLogMapper(func);
+            expect(mapHandler).to.equal(func);
+        });
+        it('allows the handler to be nulled', () => {
+            setLogMapper(x => true);
+            setLogMapper(null);
+            expect(mapHandler).to.equal(null);
+        });
+    });
+    
     describe('addCallbacks', () => {
         it('adds a single callback', () => {
             initPackager([], {on: false});

Reply via email to