# @whi/weblogger

> A minimal logger implementation designed to work in web browsers

Latest version **0.4.0** (published 2024-04-11) · ISC license · 0 weekly downloads

## Install

```sh
npm install @whi/weblogger
pnpm add @whi/weblogger
yarn add @whi/weblogger
bun add @whi/weblogger
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2024-04-11 |
| First published | 2021-08-19 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 41.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Matthew Brisebois |
| Maintainers | brisebom |

## Links

- npm: https://www.npmjs.com/package/@whi/weblogger
- Repository: https://github.com/mjbrisebois/js-weblogger
- Homepage: https://github.com/mjbrisebois/js-weblogger#readme
- Issues: https://github.com/mjbrisebois/js-weblogger/issues
- npm.io page: https://npm.io/package/@whi/weblogger

## Recent versions

- 0.4.0 (latest) — 2024-04-11
- 0.3.0 — 2024-03-01
- 0.2.1 — 2023-10-09
- 0.2.0 — 2023-09-21
- 0.1.6 — 2023-03-21
- 0.1.5 — 2022-09-27
- 0.1.4 — 2021-09-24
- 0.1.3 — 2021-09-24
- 0.1.2 — 2021-08-19
- 0.1.1 — 2021-08-19
- 0.1.0 — 2021-08-19

## README

[![](https://img.shields.io/npm/v/@whi/weblogger/latest?style=flat-square)](http://npmjs.com/package/@whi/weblogger)

# `new Logger( context, level )`
This micro-package provides a minimalist logging class for web browsers.

[![](https://img.shields.io/github/issues-raw/mjbrisebois/js-weblogger?style=flat-square)](https://github.com/mjbrisebois/js-weblogger/issues)
[![](https://img.shields.io/github/issues-closed-raw/mjbrisebois/js-weblogger?style=flat-square)](https://github.com/mjbrisebois/js-weblogger/issues?q=is%3Aissue+is%3Aclosed)
[![](https://img.shields.io/github/issues-pr-raw/mjbrisebois/js-weblogger?style=flat-square)](https://github.com/mjbrisebois/js-weblogger/pulls)


## Overview

> Bundled size is less than 2KB

## Install

```bash
npm i @whi/weblogger
```

## Usage

#### Browser
```html
<script src="weblogger.bundled.js"></script>

<script type="text/javascript">
    const { Logger } = WebLogger;
    const log = new Logger( "main" );

    log.fatal("Testing");
    log.error("Testing");
    log.warn("Testing");
    log.normal("Testing"); // default level
    log.info("Testing");
    log.debug("Testing");
    log.trace("Testing");
</script>
```

#### Node
```javascript
const { Logger } = require('@whi/weblogger');

const log = new Logger( "main", "debug" );

log.fatal("Testing");
log.error("Testing");
log.warn("Testing");
log.normal("Testing");
log.info("Testing");
log.debug("Testing");
log.trace("Testing"); // would not log
```

#### Set defaults using `localStorage`

```javascript
window.localStorage.setItem("LOG_COLOR", "false"); // turn off coloring
window.localStorage.setItem("LOG_LEVEL", "debug"); // set default level to "debug"
```

#### Avoiding expensive arg computations

Short-circuit using logical operators
```javascript
log.level.debug && log.debug("Expensive arg computation: %s", value.map(...).join(", ") );
```

Or, a callback function that only evaluates when a message will be logged.
```javascript
log.debug("Expensive arg computation: %s", () => [ value.map(...).join(", ") ]);
```

### API Reference

#### `new Logger( context, level, colors )`
Change this Logger's verbosity level.

- `context` - *(required)* an identifier used in the log format
- `level` - *(optional)* the starting log level
  - defaults to level 3 (normal)
- `colors` - *(optional)* a boolean for log coloring
  - defaults to `true`


#### `<Logger>.setLevel( level )`
Change this Logger's verbosity level.

- `level` - *(required)* the new log level

Returns the integer value of the new level.


### Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md)

---
_Source: https://npm.io/package/@whi/weblogger · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
