1.0.3 • Published 5 years ago

@ngx-loggable/core v1.0.3

Weekly downloads
-
License
-
Repository
github
Last release
5 years ago

@ngx-loggable/core npm version

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

First you need to install the npm module:

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.

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:

  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:

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:

  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}'
};
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:

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!');
  }

}
1.0.2

5 years ago

0.0.40

5 years ago

1.0.1

5 years ago

1.0.3

5 years ago

0.0.37

5 years ago

0.0.38

5 years ago

0.0.39

5 years ago

0.0.31

5 years ago

0.0.32

5 years ago

0.0.33

5 years ago

0.0.34

5 years ago

0.0.35

5 years ago

0.0.36

5 years ago

0.0.22

5 years ago

0.0.23

5 years ago

0.0.24

5 years ago

0.0.25

5 years ago

0.0.30

5 years ago

0.0.26

5 years ago

0.0.27

5 years ago

0.0.28

5 years ago

0.0.29

5 years ago

0.0.20

5 years ago

0.0.21

5 years ago

0.0.18

5 years ago

0.0.19

5 years ago

0.0.17

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago