1.2.0 • Published 4 months ago

@weyvern/dom-logger v1.2.0

Weekly downloads
-
License
ISC
Repository
github
Last release
4 months ago

DOM Logger

A simple JavaScript utility to log to a DOM element instead of the console

Install

npm i @weyvern/dom-logger

Usage

import DOMLogger from '@weyvern/dom-logger';

// a valid HTML element that allows InnerHTML
const element = document.getElementById('output');
/* 
instantiate the class passing the HTML element and a second optional boolean 
parameter, if this  this parameter is set to true, the messages will be logged 
to the native console as well, it defaults to false.
*/
const logger = new DOMLogger(element, true);

logger.log('Hello World!');
logger.info('Hello World!');
logger.warn('Hello World!');
logger.error('Hello World!');

You can also use the CDN directly within a JS Module

<!--index.html-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>001-Intro-to-JS</title>
  </head>
  <body>
    <main>
      <div id="output"></div>
    </main>
    <script type="module" src="index.js"></script>
  </body>
</html>
import DOMLogger from 'https://unpkg.com/@weyvern/dom-logger@1.0.3/index.js';

// a valid HTML element that allows IinnerHTML
const element = document.getElementById('output');

const logger = new DOMLogger(element);

logger.log('Hello World!');
logger.info('Hello World!');
logger.warn('Hello World!');
logger.error('Hello World!');

You can additionally style the message CSS, e.g:

.info {
  background-color: #1da4cd;
}

.warn {
  background-color: #f0d16b;
  color: #251919;
}

.error {
  background-color: #f8485e;
}

Example within a div element

Screenshot 2024-01-30 at 18 07 52

1.2.0

4 months ago

1.1.1

4 months ago

1.1.0

4 months ago

1.0.3

4 months ago

1.0.2

4 months ago

1.0.1

4 months ago

1.0.0

4 months ago