1.0.6 • Published 6 years ago

@fusionworks/advanced-logger v1.0.6

Weekly downloads
94
License
ISC
Repository
github
Last release
6 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

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.85

6 years ago

0.0.84

6 years ago

0.0.83

6 years ago

0.0.82

6 years ago

0.0.81

6 years ago

0.0.80

6 years ago

0.0.79

6 years ago

0.0.78

6 years ago

0.0.77

6 years ago

0.0.76

6 years ago

0.0.75

6 years ago

0.0.74

6 years ago

0.0.73

6 years ago

0.0.72

6 years ago

0.0.71

6 years ago

0.0.70

6 years ago

0.0.69

6 years ago

0.0.68

6 years ago

0.0.67

6 years ago

0.0.66

6 years ago

0.0.65

6 years ago

0.0.64

6 years ago

0.0.63

6 years ago

0.0.62

6 years ago

0.0.61

6 years ago

0.0.60

6 years ago

0.0.59

6 years ago

0.0.58

6 years ago

0.0.57

6 years ago

0.0.56

6 years ago

0.0.55

6 years ago

0.0.54

6 years ago

0.0.53

6 years ago

0.0.52

6 years ago

0.0.51

6 years ago

0.0.50

6 years ago

0.0.49

6 years ago

0.0.48

6 years ago

0.0.47

6 years ago

0.0.46

6 years ago

0.0.45

6 years ago

0.0.44

6 years ago

0.0.43

6 years ago

0.0.42

6 years ago

0.0.41

6 years ago

0.0.40

6 years ago

0.0.39

6 years ago

0.0.38

6 years ago

0.0.37

6 years ago

0.0.36

6 years ago

0.0.35

6 years ago

0.0.34

6 years ago

0.0.33

6 years ago

0.0.32

6 years ago

0.0.31

6 years ago

0.0.30

6 years ago

0.0.29

6 years ago

0.0.28

6 years ago

0.0.27

6 years ago

0.0.26

6 years ago

0.0.25

6 years ago

0.0.24

6 years ago

0.0.23

6 years ago

0.0.22

6 years ago

0.0.21

6 years ago

0.0.20

6 years ago

0.0.19

6 years ago

0.0.18

6 years ago

0.0.17

6 years ago

0.0.16

6 years ago

0.0.15

6 years ago

0.0.14

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago

0.0.0

6 years ago