1.0.6 • Published 4 years ago

@fusionworks/advanced-logger v1.0.6

Weekly downloads
94
License
ISC
Repository
github
Last release
4 years ago

@FusionWorks/advanced-logger

GitHub package.json version npm downloads Coverage Status

Advanced logger which can replace default console but are higly customizable.

advanced-logger is an javascript solution for presenting large amount of logging tasks. The logger was designed to be extremely flexible and light; it doesn't require you to replace original console with it but its design to.

It was built for modern browsers using TypeScript.

Features

  • Handle large amount of logs by one configuration.
  • Expressive configuration for each method apart.
  • Custom styles for each method apart.
  • Custom prefix/postfix for each method apart.
  • Custom standalon configuration for unique call.

Features todo

  • AoT Compilation Support
  • Handle arrays by configuration and display them as console.table instead of console.log

Installation

To use advanced-logger in your project install it via npm:

npm i @fusionworks/advanced-logger --save

Get to some entry point at your project and init by next syntax:

import { Console } from '@fusionworks/advanced-logger';
// For nodeJs will be `const { Console } = require('@fusionworks/advanced-logger');`

console = new Console();

console.log('thats just a log');
console.warn('thats just a warn');
console.info('thats just a info');
console.error('thats just a error');
console.debug('thats just a debug');

Configuration

Console class has several configurations which are given by new Console(config) or console.update(config);

Configuration model is:

{
  public debug?: {
    public hide?: boolean,
    public css?: string,
    public prefix?: string | string[],
    public sufix?: string | string[],
  };
  public info?: {
    public hide?: boolean,
    public css?: string,
    public prefix?: string | string[],
    public sufix?: string | string[],
  };
  public log?: {
    public hide?: boolean,
    public css?: string,
    public prefix?: string | string[],
    public sufix?: string | string[],
  };
  public error?: {
    public hide?: boolean,
    public css?: string,
    public prefix?: string | string[],
    public sufix?: string | string[],
  };
  public warn?: {
    public hide?: boolean,
    public css?: string,
    public prefix?: string | string[],
    public sufix?: string | string[],
  };
  public hide?: boolean,
  public css?: string,
  public prefix?: string | string[],
  public sufix?: string | string[],
}

Here are some example of configuration you may use.

Usage

import { Console, ConfigurationModel } from '@fusionworks/advanced-logger';

const configuration: ConfigurationModel = {
  debug: {
    css: 'color: blue',
    hide: false, // default
    prefix: '[debug]',
    sufix: '[post-debug]',
  },
  info: {
    css: 'color: green',
    hide: false, // default
    prefix: '[info]',
    sufix: '[post-info]',
  },
  log: {
    css: 'color: black',
    hide: false, // default
    prefix: '[log]',
    sufix: '[post-log]',
  },
  error: {
    css: 'color: red',
    hide: false, // default
    prefix: '[error]',
    sufix: '[post-error]',
  },
  warn: {
    css: 'color: yellow',
    hide: false, // default
    prefix: '[warn]',
    sufix: '[post-warn]',
  },
  // Global configuration
  // will be used for those method which has no configuration
  hide: false, // default
  css: 'color: black',
  prefix: '[DEFAULT-PREFIX]',
  sufix: '[DEFAULT-SUFIX]',
};

console = new Console(configuration);

Override configuration

Configuration can be overrided:

  const newConfig = { log: false };
  // This will override only configuration for console
  // it means that any other configuration will be the same.
  console.update(newConfig);

  // If you want to fully override configuration you must
  console.update(newConfig, true);

Clone console instance

To create copy based on old instance of console.

  const newConfig = { log: false };
  // This will create new instance of console
  const anotherConsole = console.standalone(newConfig);

  // To override configuration of new instance
  // Better use new Console(newConfig) instead.
  const anotherConsole = console.standalone(newConfig, true);

  // Also you can use it as one-time function
  console.standalone({css: 'background: green;'}).log('Hello green world!');

Testing

You can test it out by running

  • cd demo
  • npm install
  • node index for latest released version.
    OR
  • node demo for current source code.
1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.85

5 years ago

0.0.84

5 years ago

0.0.83

5 years ago

0.0.82

5 years ago

0.0.81

5 years ago

0.0.80

5 years ago

0.0.79

5 years ago

0.0.78

5 years ago

0.0.77

5 years ago

0.0.76

5 years ago

0.0.75

5 years ago

0.0.74

5 years ago

0.0.73

5 years ago

0.0.72

5 years ago

0.0.71

5 years ago

0.0.70

5 years ago

0.0.69

5 years ago

0.0.68

5 years ago

0.0.67

5 years ago

0.0.66

5 years ago

0.0.65

5 years ago

0.0.64

5 years ago

0.0.63

5 years ago

0.0.62

5 years ago

0.0.61

5 years ago

0.0.60

5 years ago

0.0.59

5 years ago

0.0.58

5 years ago

0.0.57

5 years ago

0.0.56

5 years ago

0.0.55

5 years ago

0.0.54

5 years ago

0.0.53

5 years ago

0.0.52

5 years ago

0.0.51

5 years ago

0.0.50

5 years ago

0.0.49

5 years ago

0.0.48

5 years ago

0.0.47

5 years ago

0.0.46

5 years ago

0.0.45

5 years ago

0.0.44

5 years ago

0.0.43

5 years ago

0.0.42

5 years ago

0.0.41

5 years ago

0.0.40

5 years ago

0.0.39

5 years ago

0.0.38

5 years ago

0.0.37

5 years ago

0.0.36

5 years ago

0.0.35

5 years ago

0.0.34

5 years ago

0.0.33

5 years ago

0.0.32

5 years ago

0.0.31

5 years ago

0.0.30

5 years ago

0.0.29

5 years ago

0.0.28

5 years ago

0.0.27

5 years ago

0.0.26

5 years ago

0.0.25

5 years ago

0.0.24

5 years ago

0.0.23

5 years ago

0.0.22

5 years ago

0.0.21

5 years ago

0.0.20

5 years ago

0.0.19

5 years ago

0.0.18

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

0.0.0

5 years ago