# @ngx-loggable/core

> The logging library for Angular

Latest version **1.0.3** (published 2021-09-26) · 0 weekly downloads

## Install

```sh
npm install @ngx-loggable/core
pnpm add @ngx-loggable/core
yarn add @ngx-loggable/core
bun add @ngx-loggable/core
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2021-09-26 |
| First published | 2021-09-10 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 145.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Victor Hemmekam |
| Maintainers | ngx-loggable |
| Keywords | angular, logging, loggable, ngx-loggable |

## Links

- npm: https://www.npmjs.com/package/@ngx-loggable/core
- Repository: https://github.com/ngx-loggable/core
- Issues: https://github.com/ngx-loggable/core/issues
- npm.io page: https://npm.io/package/@ngx-loggable/core

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^2.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.0.3 (latest) — 2021-09-26
- 1.0.2 — 2021-09-26
- 1.0.1 — 2021-09-26
- 0.0.40 — 2021-09-26
- 0.0.39 — 2021-09-26
- 0.0.38 — 2021-09-26
- 0.0.37 — 2021-09-26
- 0.0.36 — 2021-09-26
- 0.0.35 — 2021-09-26
- 0.0.34 — 2021-09-26
- 0.0.33 — 2021-09-26
- 0.0.32 — 2021-09-26
- 0.0.31 — 2021-09-26
- 0.0.30 — 2021-09-13
- 0.0.29 — 2021-09-13
- … 28 more at https://npm.io/package/@ngx-loggable/core/versions

## README

# @ngx-loggable/core [![npm version](https://badge.fury.io/js/%40ngx-loggable%2Fcore.svg)](https://badge.fury.io/js/%40ngx-loggable%2Fcore)

The logging library for Angular. With this library you can use a decorator to log all functions of a class.

Simple example using ngx-loggable: https://stackblitz.com/github/ngx-loggable/example

## Table of Contents

* [Installation](#installation)
* [Usage](#usage)

## Installation

First you need to install the npm module:

```sh
npm install @ngx-loggable/core --save
```

## Usage

#### 1. Decorate the desired class with `@Loggable()`:

When you use the Loggable decorator without parameters, it uses the default configurations.

```ts
import {Component, OnInit} from '@angular/core';
import {Loggable} from '@ngx-loggable/core';

@Loggable()
@Component({
  selector: 'app-login',
  templateUrl: './login.page.html',
  styleUrls: ['./login.page.scss'],
})
export class LoginPage implements OnInit {
  // ...
}
```

The default configuration is as follows:

```ts
  import {LoggableConfiguration, LoggingLevel} from '@ngx-loggable/core';

const defaultConfiguration: LoggableConfiguration = {
  consoleLoggingLevel: LoggingLevel.all,
  enteringText: 'Entering...',
  exitingText: 'Exiting ({exitTime}ms elapsed)...',
  prefixText: 'LOGGABLE-{loggingLevel} {padEnd:16}{className}@{methodName}: {padEnd:30}'
};
```

To specify your own configuration, you can pass the configuration as a parameter in the Loggable decorator like this:

```ts
import {Component, OnInit} from '@angular/core';
import {Loggable, LoggingLevel} from '@ngx-loggable/core';

@Loggable({
  consoleLoggingLevel: LoggingLevel.all,
  enteringText: 'Entering...',
  exitingText: 'Exiting ({exitTime}ms elapsed)...',
  prefixText: 'LOGGABLE-{loggingLevel} {padEnd:16}{className}@{methodName}: {padEnd:30}'
})
@Component({
  selector: 'app-login',
  templateUrl: './login.page.html',
  styleUrls: ['./login.page.scss'],
})
export class LoginPage implements OnInit {
  // ...
}
```

Even a better approach would be to store the configuration in a separate file and pass it as a constant:

```ts
  import {LoggableConfiguration, LoggingLevel} from '@ngx-loggable/core';

export const myConfiguration: LoggableConfiguration = {
  consoleLoggingLevel: LoggingLevel.all,
  enteringText: 'Entering...',
  exitingText: 'Exiting ({exitTime}ms elapsed)...',
  prefixText: 'LOGGABLE-{loggingLevel} {padEnd:16}{className}@{methodName}: {padEnd:30}'
};
```

```ts
import {Component, OnInit} from '@angular/core';
import {Loggable} from '@ngx-loggable/core';
import {myConfiguration} from './configurations/my-configuration'

@Loggable(myConfiguration)
@Component({
  selector: 'app-login',
  templateUrl: './login.page.html',
  styleUrls: ['./login.page.scss'],
})
export class LoginPage implements OnInit {
  // ...
}
```

#### 2. Use `logger` to log messages:

When a class is decorated with `@Loggable()` you can use the `logger` constant to log messages:

```ts
import {Component, OnInit} from '@angular/core';
import {Loggable, logger} from '@ngx-loggable/core';
import {myConfiguration} from './configurations/my-configuration'

@Loggable(myConfiguration)
@Component({
  selector: 'app-login',
  templateUrl: './login.page.html',
  styleUrls: ['./login.page.scss'],
})
export class LoginPage implements OnInit {

  public example(): void {
    logger.info('The example function was called!');
  }

}
```

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