### File

`projects/ngui-common/src/lib/ngui-utils/src/konsole.ts`

### Description

window.konsole alternative

### example

    konsole.setLogLevel('error');
    konwole.log(1,2,3,4,5);

### Index

###### Properties
Static LOG_LEVELS Static logLevel
###### Methods
Static debug Static error Static info Static log Static setLogLevel Static toLog Static warn

### Properties

Static LOG_LEVELS
`LOG_LEVELS: `object``
Type : `object`
Default value : `{ ALL: parseInt('00000', 2), DEBUG: parseInt('00001', 2), LOG: parseInt('00010', 2), INFO: parseInt('00100', 2), WARN: parseInt('01000', 2), ERROR: parseInt('10000', 2), NONE: parseInt('11111', 2) }`
Defined in projects/ngui-common/src/lib/ngui-utils/src/konsole.ts:11
all log levels

Static logLevel
`logLevel: `string``
Type : `string`
Default value : `'INFO'`
Defined in projects/ngui-common/src/lib/ngui-utils/src/konsole.ts:22
current log level set by setLogLevel, default 'INFO'

### Methods

Static debug
`debug(...args: Array)`
Defined in projects/ngui-common/src/lib/ngui-utils/src/konsole.ts:47
The same as `console.debug()` if the current log level is greater than `debug` Parameters :
Name | Type | Optional
args | `Array<any>` | no
Returns : `void`

Static error
`error(...args: Array)`
Defined in projects/ngui-common/src/lib/ngui-utils/src/konsole.ts:75
The same as `console.error()` if the current log level is greater than `error` Parameters :
Name | Type | Optional
args | `Array<any>` | no
Returns : `void`

Static info
`info(...args: Array)`
Defined in projects/ngui-common/src/lib/ngui-utils/src/konsole.ts:61
The same as `console.info()` if the current log level is greater than `info` Parameters :
Name | Type | Optional
args | `Array<any>` | no
Returns : `void`

Static log
`log(...args: Array)`
Defined in projects/ngui-common/src/lib/ngui-utils/src/konsole.ts:54
The same as `console.log()` if the current log level is greater than `log` Parameters :
Name | Type | Optional
args | `Array<any>` | no
Returns : `void`

Static setLogLevel
`setLogLevel(logLevel: string)`
Defined in projects/ngui-common/src/lib/ngui-utils/src/konsole.ts:33
sets the current log level Parameters :
Name | Type | Optional
logLevel | `string` | no
Returns : `any`

Static toLog
`toLog(param: )`
Defined in projects/ngui-common/src/lib/ngui-utils/src/konsole.ts:25
returns if it should call `window.console` or not Parameters :
Name | Optional
param | no
Returns : `boolean`

Static warn
`warn(...args: Array)`
Defined in projects/ngui-common/src/lib/ngui-utils/src/konsole.ts:68
The same as `console.warn()` if the current log level is greater than `warn` Parameters :
Name | Type | Optional
args | `Array<any>` | no
Returns : `void`

    export abstract class konsole { // tslint:disable-line
      /** all log levels */
      static LOG_LEVELS = {
        ALL:   parseInt('00000', 2),
        DEBUG: parseInt('00001', 2),
        LOG:   parseInt('00010', 2),
        INFO:  parseInt('00100', 2),
        WARN:  parseInt('01000', 2),
        ERROR: parseInt('10000', 2),
        NONE:  parseInt('11111', 2)
      };

      /** current log level set by setLogLevel, default 'INFO' */
      static logLevel = 'INFO';

      /** returns if it should call `window.console` or not */
      static toLog(param): boolean { // returns to log or not
        const restrictionNum = this.LOG_LEVELS[this.logLevel];
        const requiredNum = this.LOG_LEVELS[param];

        return requiredNum > restrictionNum;
      }

      /** sets the current log level */
      static setLogLevel(logLevel: string): any {
        logLevel = logLevel.toUpperCase();
        const logLevels = Object.keys(this.LOG_LEVELS);
        if (logLevels.indexOf(logLevel) > -1) {
          if (window && window.sessionStorage) { // for browser env.
            window.sessionStorage.setItem('konsole.LOG_LEVEL', logLevel);
          }
          this.logLevel = logLevel;
        } else {
          console.error(`Error, invalid logLevel, it must be one of ${logLevels}`);
        }
      }

      /** The same as `console.debug()` if the current log level is greater than `debug` */
      static debug(...args: Array<any>): void {
        if (this.toLog('DEBUG')) {
            console.debug.apply(console, arguments); // tslint:disable-line
        }
      }

      /** The same as `console.log()` if the current log level is greater than `log` */
      static log(...args: Array<any>): void {
        if (this.toLog('LOG')) {
            console.log.apply(console, arguments); // tslint:disable-line
        }
      }

      /** The same as `console.info()` if the current log level is greater than `info` */
      static info(...args: Array<any>): void {
        if (this.toLog('INFO')) {
            console.info.apply(console, arguments); // tslint:disable-line
        }
      }

      /** The same as `console.warn()` if the current log level is greater than `warn` */
      static warn(...args: Array<any>): void {
        if (this.toLog('WARN')) {
            console.warn.apply(console, arguments);
        }
      }

      /** The same as `console.error()` if the current log level is greater than `error` */
      static error(...args: Array<any>): void {
        if (this.toLog('ERROR')) {
            console.error.apply(console, arguments);
        }
      }
    }

    // konsole.setLogLevel('all');
    // konsole.debug('yes');
    // konsole.log('yes');
    // konsole.info('yes');
    // konsole.warn('yes');
    // konsole.error('yes');

    // konsole.setLogLevel('none');
    // konsole.debug('no');
    // konsole.log('no');
    // konsole.info('no');
    // konsole.warn('no');
    // konsole.error('no');

    // konsole.setLogLevel('info');
    // konsole.debug('no');
    // konsole.log('no');
    // konsole.info('yes');
    // konsole.warn('yes');
    // konsole.error('yes');

    // konsole.setLogLevel('WARN');
    // konsole.debug('no');
    // konsole.log('no');
    // konsole.info('no');
    // konsole.warn('yes');
    // konsole.error('yes');

    // konsole.setLogLevel('ERROR');
    // konsole.debug('no');
    // konsole.log('no');
    // konsole.info('no');
    // konsole.warn('no');
    // konsole.error('yes');

# results matching ""

# No results matching ""