diff --git a/README.md b/README.md index 2f9b517..327128b 100644 --- a/README.md +++ b/README.md @@ -58,3 +58,23 @@ If you need to lint just one file, you can run: ```sh npx eslint file1.js ``` + +## Logging +When logging do not use `console` but instead use `window.lana.log`, these logs will then be visible in Splunk. +Use tags to help filter logs. Tags should have the severity, see below, and the module/block name. +Tags should provide context, categorization, or help in filtering, etc. + +Severity: +``` +info = network issues or extra details to identify important information. +warn = authoring related mis-configurations or similar - this could lead to generating tickets. +error = actual error ( ex. cannot read Y of undefined ) - this could lead to generating tickets / CSOs depending on context. +``` +Work with OPS to generate automatic tickets / CSOs, for example if an error causes the page or block not to render. + +Example Logging: +```js +window.lana.log('message', 'info, block-name'); +``` + +More info: https://wiki.corp.adobe.com/display/WCMSOps/Best+Practices diff --git a/blocks/faas-decode/faas-decode.js b/blocks/faas-decode/faas-decode.js index b197cfa..70c3fac 100644 --- a/blocks/faas-decode/faas-decode.js +++ b/blocks/faas-decode/faas-decode.js @@ -6,8 +6,7 @@ export default async function init(el) { const resp = await fetch(url); if (!resp?.ok) { - // eslint-disable-next-line no-console - console.log(`Error fetching data from url: ${url}`); + window.lana?.log(`Error fetching data from url: ${url}`, { tags: 'info, faas-decode' }); return; } diff --git a/blocks/tree-view/tree-view.js b/blocks/tree-view/tree-view.js index 26aba1e..3e044a5 100644 --- a/blocks/tree-view/tree-view.js +++ b/blocks/tree-view/tree-view.js @@ -11,8 +11,7 @@ export const isCurrentPage = (link) => { if (isBacomHost && url.pathname.replace('.html', '') === currentPath) return true; } catch (e) { - // eslint-disable-next-line no-console - console.log('Tree View error:', e); + window.lana?.log(`Tree View error:${e.message}`, { tags: 'info, tree-view' }); } return false; diff --git a/scripts/scripts.js b/scripts/scripts.js index 5bd5f20..d57758d 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -189,6 +189,6 @@ const miloLibs = setLibs(LIBS); } } setConfig({ ...CONFIG, miloLibs }); - loadLana({ clientId: 'bacom' }); + loadLana({ clientId: 'bacom', tags: 'info' }); await loadArea(); }()); diff --git a/test/blocks/faas-decode/faas-decode.test.js b/test/blocks/faas-decode/faas-decode.test.js index c79a143..e643aff 100644 --- a/test/blocks/faas-decode/faas-decode.test.js +++ b/test/blocks/faas-decode/faas-decode.test.js @@ -4,9 +4,11 @@ import init from '../../../blocks/faas-decode/faas-decode.js'; import { setLibs } from '../../../scripts/utils.js'; import waitForElement from '../../helpers/waitForElement.js'; +window.lana = { log: () => {} }; + describe('FaaS Decode', () => { before(() => { - sinon.spy(console, 'log'); + sinon.stub(window.lana, 'log'); setLibs('/libs'); }); @@ -18,7 +20,7 @@ describe('FaaS Decode', () => { document.body.innerHTML = '
'; const el = document.querySelector('.faas-decode'); await init(el); - expect(console.log.args[0][0]).to.include('Error fetching data from url:'); + expect(window.lana.log.args[0][0]).to.include('Error fetching data from url:'); }); it('creates a table', async () => { diff --git a/test/blocks/tree-view/tree-view.test.js b/test/blocks/tree-view/tree-view.test.js index 1f68981..428284a 100644 --- a/test/blocks/tree-view/tree-view.test.js +++ b/test/blocks/tree-view/tree-view.test.js @@ -5,6 +5,7 @@ import { setLibs } from '../../../scripts/utils.js'; const { default: init, isCurrentPage } = await import('../../../blocks/tree-view/tree-view.js'); +window.lana = { log: () => {} }; setLibs('libs'); describe('Tree View', () => { @@ -38,10 +39,10 @@ describe('Tree View', () => { }); it('isCurrentPage catches error', () => { - sinon.spy(console, 'log'); + sinon.stub(window.lana, 'log'); isCurrentPage('/relative-link'); - expect(console.log.args[0][0]).to.equal('Tree View error:'); - console.log.restore(); + expect(window.lana.log.args[0][0]).to.contain('Tree View error:'); + window.lana.log.restore(); }); describe('accordion', () => {