Socket
Book a DemoInstallSign in
Socket

ts-smart-logger

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-smart-logger

An implementation of logger at TypeScript (TS 2 compatible).

0.1.0
latest
Source
npmnpm
Version published
Weekly downloads
229
43.13%
Maintainers
1
Weekly downloads
 
Created
Source

ts-smart-logger

An implementation of logger at TypeScript (TS 2 compatible).

Installation

First you need to install the npm module:

npm install ts-smart-logger --save

Use

main.ts

import {LoggerFactory} from 'ts-smart-logger/index';

LoggerFactory.configure();
// or
LoggerFactory.configure({"logLevel": 3});
// or
LoggerFactory.configure(require('./config/log/default.json'));
// or
LoggerFactory.configure(require('./config/log/ProductionLoggerConfig').ProductionLoggerConfig);

LoggedFirstClass.ts

class LoggedFirstClass {
   private logger:ILogger = LoggerFactory.makeLogger(LoggedFirstClass);

   public logAtFirstClass() {
       this.logger.info(1);                                    // <=> console.info(1);
       this.logger.warn(() => 2);                              // <=> console.warn(2);
       this.logger.error(new Error("3"));                      // <=> console.error(new Error("3"));

       this.logger.info(1, 2, 3);                              // <=> console.info(1, 2, 3);
       this.logger.warn(() => [1, 2, 3]);                      // <=> console.warn([1, 2, 3]);
       this.logger.error("Custom error:", new Error("2"));     // <=> console.error("Custom error:", new Error("2"));
       this.logger.debug((logger:IEnvironmentLogger) => {
           // Here may be different kinds of complex calculations, performed only in logging mode
           logger.write('Debug log mode enabled: ', 1, 2, 3);  // <=> console.debug('Debug log mode enabled: ', 1, 2, 3);
       });
       this.logger.warn((logger:IEnvironmentLogger) => {
           // Here may be different kinds of complex calculations, performed only in logging mode
           logger.write('Warn log mode enabled: ', 1, 2, 3);   // <=> console.warn('Warn log mode enabled: ', 1, 2, 3);
           return [1, 2, 3].length;                            // <=> console.warn([1, 2, 3].length);
       });
   }
}

config.json

{
    "debugLevelPath": "[0-9]+",
    "infoLevelPath": ".",
    "logLevelPath": ".",
    "warnLevelPath": ".",
    "errorLevelPath": "[^LoggedFirstClass]",
    "logLevel": 3
}

Configure the runtime

$$LoggerFactory.storeConfig({"errorLevelPath": "[^Main]", "logLevel": 3})

Attention Since the "LoggerFactory" may be shared between the different dependencies we must include the script "npm dedupe" in this case into the package.json:

  ...
  "scripts": {
    "postinstall": "npm dedupe && ...",
  },
  ...

Configure the runtime

Publish

npm run deploy

License

Licensed under MIT.

FAQs

Package last updated on 24 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.