Skip to content
Snippets Groups Projects
Commit 22fbe664 authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

Disable debug logging by default

appending "#debug" to the URL enables it again. Not sure if this
the best mechanism, but better than spaming the console for now.
parent dd66ee0e
No related branches found
No related tags found
No related merge requests found
...@@ -11,4 +11,5 @@ export {getIconSVGURL, getIconCSS, Icon}; ...@@ -11,4 +11,5 @@ export {getIconSVGURL, getIconCSS, Icon};
export {MiniSpinner}; export {MiniSpinner};
export {Button, LoadingButton}; export {Button, LoadingButton};
export {Spinner}; export {Spinner};
export {InlineNotification}; export {InlineNotification};
\ No newline at end of file export * from './src/logger.js';
\ No newline at end of file
class LoggerType {
get debug() {
if (window.location.hash.includes("debug")) {
return console.debug;
} else {
return () => {};
}
}
}
export const Logger = new LoggerType();
\ No newline at end of file
import {LitElement} from "lit-element"; import {LitElement} from "lit-element";
import {Logger} from "@dbp-toolkit/common";
export class AdapterLitElement extends LitElement { export class AdapterLitElement extends LitElement {
constructor() { constructor() {
...@@ -23,7 +24,7 @@ export class AdapterLitElement extends LitElement { ...@@ -23,7 +24,7 @@ export class AdapterLitElement extends LitElement {
// We need to store our own "last values" because we cannot be sure what the MutationObserver detects // We need to store our own "last values" because we cannot be sure what the MutationObserver detects
this.lastProperties = {}; this.lastProperties = {};
console.debug('AdapterLitElement(' + this.tagName + ') constructor()'); Logger.debug('AdapterLitElement(' + this.tagName + ') constructor()');
} }
getProperty(name) { getProperty(name) {
...@@ -41,7 +42,7 @@ export class AdapterLitElement extends LitElement { ...@@ -41,7 +42,7 @@ export class AdapterLitElement extends LitElement {
setProperty(name, value) { setProperty(name, value) {
// TODO: check if lit attribute really present? // TODO: check if lit attribute really present?
if (typeof value === 'object' && value !== null) { if (typeof value === 'object' && value !== null) {
// console.debug("value is object", value); // Logger.debug("value is object", value);
this.setPropertyByAttributeName(name, value); this.setPropertyByAttributeName(name, value);
} else { } else {
this.attributeChangedCallback(name, this.getPropertyByAttributeName(name), value); this.attributeChangedCallback(name, this.getPropertyByAttributeName(name), value);
...@@ -83,7 +84,7 @@ export class AdapterLitElement extends LitElement { ...@@ -83,7 +84,7 @@ export class AdapterLitElement extends LitElement {
this.addEventListener('dbp-subscribe', function (e) { this.addEventListener('dbp-subscribe', function (e) {
const name = e.detail.name; const name = e.detail.name;
if (that.hasProperty(name) || that.root) { if (that.hasProperty(name) || that.root) {
console.debug('AdapterLitElementProvider(' + that.tagName + ') eventListener("dbp-subscribe",..) name "' + name + '" found.'); Logger.debug('AdapterLitElementProvider(' + that.tagName + ') eventListener("dbp-subscribe",..) name "' + name + '" found.');
that.callbackStore.push({name: name, callback: e.detail.callback, sender: e.detail.sender}); that.callbackStore.push({name: name, callback: e.detail.callback, sender: e.detail.sender});
e.detail.callback(that.getProperty(name)); e.detail.callback(that.getProperty(name));
...@@ -95,12 +96,12 @@ export class AdapterLitElement extends LitElement { ...@@ -95,12 +96,12 @@ export class AdapterLitElement extends LitElement {
const name = e.detail.name; const name = e.detail.name;
const sender = e.detail.sender; const sender = e.detail.sender;
if (that.hasProperty(name) || that.root) { if (that.hasProperty(name) || that.root) {
console.debug('AdapterLitElementProvider(' + that.tagName + ') eventListener("dbp-unsubscribe",..) name "' + name + '" found.'); Logger.debug('AdapterLitElementProvider(' + that.tagName + ') eventListener("dbp-unsubscribe",..) name "' + name + '" found.');
that.callbackStore.forEach(item => { that.callbackStore.forEach(item => {
if (item.sender === sender && item.name === name) { if (item.sender === sender && item.name === name) {
const index = that.callbackStore.indexOf(item); const index = that.callbackStore.indexOf(item);
that.callbackStore.splice(index, 1); that.callbackStore.splice(index, 1);
console.debug('AdapterLitElementProvider(' + that.tagName + ') eventListener for name "' + name + '" removed.'); Logger.debug('AdapterLitElementProvider(' + that.tagName + ') eventListener for name "' + name + '" removed.');
} }
}); });
...@@ -114,7 +115,7 @@ export class AdapterLitElement extends LitElement { ...@@ -114,7 +115,7 @@ export class AdapterLitElement extends LitElement {
const value = e.detail.value; const value = e.detail.value;
if (that.hasProperty(name) || that.root) { if (that.hasProperty(name) || that.root) {
console.debug('AdapterLitElementProvider(' + that.tagName + ') eventListener("dbp-set-property",..) name "' + name + '" found.'); Logger.debug('AdapterLitElementProvider(' + that.tagName + ') eventListener("dbp-set-property",..) name "' + name + '" found.');
that.setProperty(name, value); that.setProperty(name, value);
that.callbackStore.forEach(item => { that.callbackStore.forEach(item => {
...@@ -139,7 +140,7 @@ export class AdapterLitElement extends LitElement { ...@@ -139,7 +140,7 @@ export class AdapterLitElement extends LitElement {
const value = that.getAttribute(name); const value = that.getAttribute(name);
if (that.hasPropertyChanged(name, value)) { if (that.hasPropertyChanged(name, value)) {
console.debug('AdapterLitElementProvider (' + that.tagName + ') observed attribute "' + name + '" changed'); Logger.debug('AdapterLitElementProvider (' + that.tagName + ') observed attribute "' + name + '" changed');
that.setProperty(name, value); that.setProperty(name, value);
that.callbackStore.forEach(item => { that.callbackStore.forEach(item => {
...@@ -167,7 +168,7 @@ export class AdapterLitElement extends LitElement { ...@@ -167,7 +168,7 @@ export class AdapterLitElement extends LitElement {
} }
this.setProperty(attrs[i].name, attrs[i].value); this.setProperty(attrs[i].name, attrs[i].value);
console.debug('AdapterLitElementProvider (' + that.tagName + ') found attribute "' + attrs[i].name + '" = "' + attrs[i].value + '"'); Logger.debug('AdapterLitElementProvider (' + that.tagName + ') found attribute "' + attrs[i].name + '" = "' + attrs[i].value + '"');
} }
} }
} }
...@@ -180,7 +181,7 @@ export class AdapterLitElement extends LitElement { ...@@ -180,7 +181,7 @@ export class AdapterLitElement extends LitElement {
} }
subscribeProviderFor(element) { subscribeProviderFor(element) {
console.debug('AdapterLitElement(' + this.tagName + ') subscribeProviderFor( ' + element + ' )'); Logger.debug('AdapterLitElement(' + this.tagName + ') subscribeProviderFor( ' + element + ' )');
const pair = element.trim().split(':'); const pair = element.trim().split(':');
const local = pair[0]; const local = pair[0];
const global = pair[1] || local; const global = pair[1] || local;
...@@ -192,14 +193,14 @@ export class AdapterLitElement extends LitElement { ...@@ -192,14 +193,14 @@ export class AdapterLitElement extends LitElement {
detail: { detail: {
name: global, name: global,
callback: (value) => { callback: (value) => {
console.debug('AdapterLitElement(' + that.tagName + ') sub/Callback ' + global + ' -> ' + local + ' = ' + value); Logger.debug('AdapterLitElement(' + that.tagName + ') sub/Callback ' + global + ' -> ' + local + ' = ' + value);
// If value is an object set it directly as property // If value is an object set it directly as property
if (typeof value === 'object' && value !== null) { if (typeof value === 'object' && value !== null) {
// console.debug("value is object", value); // Logger.debug("value is object", value);
that.setPropertyByAttributeName(local, value); that.setPropertyByAttributeName(local, value);
} else { } else {
// console.debug("local, that.getPropertyByAttributeName(local), value", local, that.getPropertyByAttributeName(local), value); // Logger.debug("local, that.getPropertyByAttributeName(local), value", local, that.getPropertyByAttributeName(local), value);
that.attributeChangedCallback(local, that.getPropertyByAttributeName(local), value); that.attributeChangedCallback(local, that.getPropertyByAttributeName(local), value);
// check if an attribute also exists in the tag // check if an attribute also exists in the tag
...@@ -221,7 +222,7 @@ export class AdapterLitElement extends LitElement { ...@@ -221,7 +222,7 @@ export class AdapterLitElement extends LitElement {
} }
unSubscribeProviderFor(element) { unSubscribeProviderFor(element) {
console.debug('AdapterLitElement(' + this.tagName + ') unSubscribeProviderFor( ' + element + ' )'); Logger.debug('AdapterLitElement(' + this.tagName + ') unSubscribeProviderFor( ' + element + ' )');
const pair = element.trim().split(':'); const pair = element.trim().split(':');
const global = pair[1] || pair[0]; const global = pair[1] || pair[0];
const event = new CustomEvent('dbp-unsubscribe', const event = new CustomEvent('dbp-unsubscribe',
...@@ -246,10 +247,10 @@ export class AdapterLitElement extends LitElement { ...@@ -246,10 +247,10 @@ export class AdapterLitElement extends LitElement {
findPropertyName(attributeName) { findPropertyName(attributeName) {
let resultName = attributeName; let resultName = attributeName;
const properties = this.constructor.properties; const properties = this.constructor.properties;
// console.debug("properties", properties); // Logger.debug("properties", properties);
for (const propertyName in properties) { for (const propertyName in properties) {
// console.debug("findPropertyName", `${propertyName}: ${properties[propertyName]}`); // Logger.debug("findPropertyName", `${propertyName}: ${properties[propertyName]}`);
const attribute = properties[propertyName].attribute; const attribute = properties[propertyName].attribute;
if (attribute === attributeName) { if (attribute === attributeName) {
resultName = propertyName; resultName = propertyName;
...@@ -263,7 +264,7 @@ export class AdapterLitElement extends LitElement { ...@@ -263,7 +264,7 @@ export class AdapterLitElement extends LitElement {
attributeChangedCallback(name, oldValue, newValue) { attributeChangedCallback(name, oldValue, newValue) {
switch(name) { switch(name) {
case 'subscribe': case 'subscribe':
console.debug('AdapterLitElement() attributeChangesCallback( ' + name + ', ' + oldValue + ', ' + newValue + ')'); Logger.debug('AdapterLitElement() attributeChangesCallback( ' + name + ', ' + oldValue + ', ' + newValue + ')');
if (this.subscribe && this.subscribe.length > 0) { if (this.subscribe && this.subscribe.length > 0) {
if (this.connected) { if (this.connected) {
...@@ -290,14 +291,14 @@ export class AdapterLitElement extends LitElement { ...@@ -290,14 +291,14 @@ export class AdapterLitElement extends LitElement {
// or if newValue is empty but name and oldValue are set // or if newValue is empty but name and oldValue are set
// This should prevent 'Uncaught SyntaxError: JSON.parse unexpected end of data at line 1 column 1 of the JSON data' // This should prevent 'Uncaught SyntaxError: JSON.parse unexpected end of data at line 1 column 1 of the JSON data'
if ((typeof oldValue === 'object' && !oldValue && !newValue) || (!newValue && oldValue && name)) { if ((typeof oldValue === 'object' && !oldValue && !newValue) || (!newValue && oldValue && name)) {
// console.debug("attributeChangedCallback ignored", name, oldValue, newValue); // Logger.debug("attributeChangedCallback ignored", name, oldValue, newValue);
break; break;
} }
super.attributeChangedCallback(name, oldValue, newValue); super.attributeChangedCallback(name, oldValue, newValue);
} }
// console.debug("this.lang", this.tagName, name, this.lang); // Logger.debug("this.lang", this.tagName, name, this.lang);
// console.debug("this.entryPointUrl", this.tagName, name, this.entryPointUrl); // Logger.debug("this.entryPointUrl", this.tagName, name, this.entryPointUrl);
// console.trace(); // console.trace();
} }
...@@ -309,7 +310,7 @@ export class AdapterLitElement extends LitElement { ...@@ -309,7 +310,7 @@ export class AdapterLitElement extends LitElement {
* @returns {boolean} * @returns {boolean}
*/ */
sendSetPropertyEvent(name, value) { sendSetPropertyEvent(name, value) {
// console.debug("dbp-set-property", name, value); // Logger.debug("dbp-set-property", name, value);
const event = new CustomEvent('dbp-set-property', { const event = new CustomEvent('dbp-set-property', {
bubbles: true, bubbles: true,
......
import {Logger} from "@dbp-toolkit/common";
export class Provider extends HTMLElement { export class Provider extends HTMLElement {
constructor() { constructor() {
super(); super();
...@@ -12,7 +14,7 @@ export class Provider extends HTMLElement { ...@@ -12,7 +14,7 @@ export class Provider extends HTMLElement {
// We need to store our own "last values" because we cannot be sure what the MutationObserver detects // We need to store our own "last values" because we cannot be sure what the MutationObserver detects
this.lastProperties = {}; this.lastProperties = {};
console.debug('Provider constructor()'); Logger.debug('Provider constructor()');
} }
getProperty(name) { getProperty(name) {
...@@ -33,14 +35,14 @@ export class Provider extends HTMLElement { ...@@ -33,14 +35,14 @@ export class Provider extends HTMLElement {
} }
connectedCallback() { connectedCallback() {
console.debug('Provider(' + this.id + ') connectedCallback()'); Logger.debug('Provider(' + this.id + ') connectedCallback()');
const that = this; const that = this;
this.addEventListener('dbp-subscribe', function (e) { this.addEventListener('dbp-subscribe', function (e) {
const name = e.detail.name; const name = e.detail.name;
if (that.hasProperty(name) || that.root) { if (that.hasProperty(name) || that.root) {
console.debug('Provider(' + that.id + ') eventListener("dbp-subscribe",..) name "' + name + '" found.'); Logger.debug('Provider(' + that.id + ') eventListener("dbp-subscribe",..) name "' + name + '" found.');
that.callbackStore.push({name: name, callback: e.detail.callback, sender: e.detail.sender}); that.callbackStore.push({name: name, callback: e.detail.callback, sender: e.detail.sender});
e.detail.callback(that.getProperty(name)); e.detail.callback(that.getProperty(name));
...@@ -52,12 +54,12 @@ export class Provider extends HTMLElement { ...@@ -52,12 +54,12 @@ export class Provider extends HTMLElement {
const name = e.detail.name; const name = e.detail.name;
const sender = e.detail.sender; const sender = e.detail.sender;
if (that.hasProperty(name) || that.root) { if (that.hasProperty(name) || that.root) {
console.debug('Provider(' + that.id + ') eventListener("dbp-unsubscribe",..) name "' + name + '" found.'); Logger.debug('Provider(' + that.id + ') eventListener("dbp-unsubscribe",..) name "' + name + '" found.');
that.callbackStore.forEach(item => { that.callbackStore.forEach(item => {
if (item.sender === sender && item.name === name) { if (item.sender === sender && item.name === name) {
const index = that.callbackStore.indexOf(item); const index = that.callbackStore.indexOf(item);
that.callbackStore.splice(index, 1); that.callbackStore.splice(index, 1);
console.debug('Provider(' + that.id + ') eventListener for name "' + name + '" removed.'); Logger.debug('Provider(' + that.id + ') eventListener for name "' + name + '" removed.');
} }
}); });
...@@ -71,7 +73,7 @@ export class Provider extends HTMLElement { ...@@ -71,7 +73,7 @@ export class Provider extends HTMLElement {
const value = e.detail.value; const value = e.detail.value;
if (that.hasProperty(name) || that.root) { if (that.hasProperty(name) || that.root) {
console.debug('Provider(' + that.id + ') eventListener("dbp-set-property",..) name "' + name + '" found.'); Logger.debug('Provider(' + that.id + ') eventListener("dbp-set-property",..) name "' + name + '" found.');
that.setProperty(name, value); that.setProperty(name, value);
that.callbackStore.forEach(item => { that.callbackStore.forEach(item => {
...@@ -96,7 +98,7 @@ export class Provider extends HTMLElement { ...@@ -96,7 +98,7 @@ export class Provider extends HTMLElement {
const value = that.getAttribute(name); const value = that.getAttribute(name);
if (that.hasPropertyChanged(name, value)) { if (that.hasPropertyChanged(name, value)) {
console.debug('Provider (' + that.id + ') observed attribute "' + name + '" changed'); Logger.debug('Provider (' + that.id + ') observed attribute "' + name + '" changed');
that.setProperty(name, value); that.setProperty(name, value);
that.callbackStore.forEach(item => { that.callbackStore.forEach(item => {
...@@ -124,7 +126,7 @@ export class Provider extends HTMLElement { ...@@ -124,7 +126,7 @@ export class Provider extends HTMLElement {
} }
this.setProperty(attrs[i].name, attrs[i].value); this.setProperty(attrs[i].name, attrs[i].value);
console.debug('Provider (' + that.id + ') found attribute "' + attrs[i].name + '" = "' + attrs[i].value + '"'); Logger.debug('Provider (' + that.id + ') found attribute "' + attrs[i].name + '" = "' + attrs[i].value + '"');
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment