Skip to content

Commit

Permalink
Merge branch 'main' into sukamat-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
sukamat authored Dec 11, 2023
2 parents c5a8b78 + 9cdcf00 commit 79cb20a
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions blocks/faas-decode/faas-decode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 1 addition & 2 deletions blocks/tree-view/tree-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,6 @@ const miloLibs = setLibs(LIBS);
}
}
setConfig({ ...CONFIG, miloLibs });
loadLana({ clientId: 'bacom' });
loadLana({ clientId: 'bacom', tags: 'info' });
await loadArea();
}());
6 changes: 4 additions & 2 deletions test/blocks/faas-decode/faas-decode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

Expand All @@ -18,7 +20,7 @@ describe('FaaS Decode', () => {
document.body.innerHTML = '<div class="faas-decode"><div><div><a href="/404"></a></div></div></div>';
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 () => {
Expand Down
7 changes: 4 additions & 3 deletions test/blocks/tree-view/tree-view.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit 79cb20a

Please sign in to comment.