# @simplyappdevs/logging-helper

> Logging helper for Javascript/Typescript

Latest version **1.1.0** (published 2021-09-04) · GPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install @simplyappdevs/logging-helper
pnpm add @simplyappdevs/logging-helper
yarn add @simplyappdevs/logging-helper
bun add @simplyappdevs/logging-helper
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2021-09-04 |
| First published | 2021-05-03 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 117.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | SimplyAppDevs |
| Maintainers | azmizar |
| Keywords | logging, typescript, javascript |

## Links

- npm: https://www.npmjs.com/package/@simplyappdevs/logging-helper
- Repository: https://github.com/simplyappdevs/logging-helper
- Homepage: https://github.com/simplyappdevs/logging-helper#readme
- Issues: https://github.com/simplyappdevs/logging-helper/issues
- npm.io page: https://npm.io/package/@simplyappdevs/logging-helper

## Dependencies (1)

- [browser-or-node](https://npm.io/package/browser-or-node.md) ^1.3.0

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 1.1.0 (latest) — 2021-09-04
- 1.0.3 — 2021-09-04
- 1.0.2 — 2021-07-17
- 1.0.1 — 2021-05-03

## README

# Logging Helper Module

> Module to standardize logging output.

## Why?

> I don't like using `console.log` everywhere in my code. So this module allows me to standardize log statements with certain format.

## Notable Features

* Log levels
* Output by log levels
* Standardized log structure that includes (but not limited to) app name, module name, function name, and other information
* High-order functions to wrap module name and function name

## Log Entry

```javascript
export interface LogEntry {
  logType: LOGTYPES;        // Log type
  appName: string;          // Application name
  modName: string;          // Module name
  fnName: string;           // Function name
  entryTS: Date;            // Log entry timestamp in UTC
  friendlyMsg: string;      // Log friendly/brief message
  detailMsg?: string;       // Log detail message (ex: StackTrace from Error)
  task?: string;            // Step/task being executed
  durationIsMS?: number;    // Duration taken in millisecond
}

export interface LogEntryWithDuration extends LogEntry {
  endTS: Date;             // Log entry end timestamp in UTC
  durationIsMS?: number;    // Duration taken in millisecond
}
```

## Loggers

### Main logger

> Logger that takes all parameters

### Module logger

> High-order logger on top of main logger to pin the module name

### Function logger

> High-order logger on top of module logger to pin the function name

## Log Output Override

This logger helper module does not actually output the log entries. It expects a logger output to be assigned via `setLoggerOutput()` function available from the main logger interface.

```javascript
export type LoggerOutput = (entry: Readonly<LogEntry> | Readonly<LogEntryWithDuration>) => void;
```

## Example

> [https://github.com/simplyappdevs/logging-helper-example](https://github.com/simplyappdevs/logging-helper-example)

## Reminder for ESM Application

### npm exec command option

> You will need to run your application with `--es-module-specifier-resolution=node` option.
>
> Ex: `"exec": "node --es-module-specifier-resolution=node ./dist/index.js"` for your NPM script `npm run exec`.

### Configure package.json

> Set type to module `"type": "module"`

```json
{
  "name": "my-awesome-app",
  "version": "1.0.0",
  "description": "My Awesome App",
  "main": "index.js",
  "type": "module",
  "scripts": {
  }
}
```

### Configure tsconfig.json

> Set module to one of ECMA script `"module": "esnext"` in `compilerOptions` section

```json
{
  "compilerOptions": {
    "module": "esnext",
  }
}
```

> Set module resolution to node `"moduleResolution": "node"` in `compilerOptions` section

```json
{
  "compilerOptions": {
    "moduleResolution": "node",
  }
}
```

Brought to you by www.simplyappdevs.com (2021)

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