You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flagon.apache.org by po...@apache.org on 2019/04/20 04:12:17 UTC
[incubator-flagon] branch FLAGON-344 updated: [FLAGON-381] added
WIP stub for dataschema docs
This is an automated email from the ASF dual-hosted git repository.
poorejc pushed a commit to branch FLAGON-344
in repository https://gitbox.apache.org/repos/asf/incubator-flagon.git
The following commit(s) were added to refs/heads/FLAGON-344 by this push:
new a868775 [FLAGON-381] added WIP stub for dataschema docs
a868775 is described below
commit a8687755065412b7c0a157b520755ee93d902f19
Author: poorejc <po...@apache.org>
AuthorDate: Sat Apr 20 00:12:06 2019 -0400
[FLAGON-381] added WIP stub for dataschema docs
---
site/_docs/useralejs/dataschema.md | 81 ++++++++++++++++++++++++++++++++++++++
1 file changed, 81 insertions(+)
diff --git a/site/_docs/useralejs/dataschema.md b/site/_docs/useralejs/dataschema.md
new file mode 100644
index 0000000..1414f47
--- /dev/null
+++ b/site/_docs/useralejs/dataschema.md
@@ -0,0 +1,81 @@
+---
+title: API
+component: useralejs
+permalink: /docs/useralejs/API
+priority: 11
+---
+
+### The UserALE.js API
+
+For some applications, it may be desirable to filter logs based on some runtime parameters or to enhance the logs with information available to the app. To support this use-case, [Apache UserALE.js](https://github.com/apache/incubator-flagon-useralejs) is equipped with an API exposed against the global UserALE.js object.
+
+The two functions exposed are the `setLogFilter` and `setLogMapper` functions. These allow dynamic modifications to the logs at runtime, but before they are shipped to the server.
+
+`setLogFilter` helps you sculpt your log stream, removing data you don't want.
+`setLogMapper` helps you modify the content of your log stream, such as by adding fields to logs, or modifying what is written to existing fields.
+
+**Sample Uses**
+
+Here is an example of a filter that only keeps every second log (odd-even):
+```html
+<html>
+ <head>
+ <script src="/path/to/userale-1.0.0.min.js" data-url="http://yourLoggingUrl"></script>
+
+ <script type="text/javascript">
+ var logCounter = 0;
+ window.userale.filter(function (log) {
+ return (logCounter++ % 2);
+ });
+ </script>
+ </head>
+ <body>
+ <div id="app">
+ <!-- application goes here -->
+ </div>
+ </body>
+</html>
+```
+
+Here is an example of a mapping function that adds runtime information about the current "score":
+```html
+<html>
+ <head>
+ <script src="/path/to/userale-1.0.0.min.js" data-url="http://yourLoggingUrl"></script>
+ </head>
+ <body>
+ <div id="app">
+ <button id="increment">+</button>
+ <button id="decrement">-</button>
+ <div id="scoreboard"></div>
+ </div>
+
+ <script type="text/javascript">
+ var score = 0;
+ var scoreBoard = document.getElementById('scoreboard');
+ scoreBoard.innerText = '0';
+
+ function setScore(nextScore) {
+ score = nextScore;
+ scoreBoard.innerText = String(score);
+ }
+
+ document.getElementById('increment').addEventListener('click', function () {
+ setScore(score + 1);
+ });
+
+ document.getElementById('decrement').addEventListener('click', function () {
+ if (score) {
+ setScore(score - 1);
+ }
+ });
+
+ window.userale.map(function (log) {
+ return Object.assign({}, log, { score: score }); // Add the "score" property to the log
+ });
+ </script>
+ </body>
+</html>
+```
+
+Even with this small API, it is possible to compose very powerful logging capabilities and progressively append additionally app-specific logic to your logs.