ts-smart-logger

WebJar for ts-smart-logger

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

ts-smart-logger
Last Version

Last Version

0.0.4
Release Date

Release Date

Type

Type

jar
Description

Description

ts-smart-logger
WebJar for ts-smart-logger
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/apoterenko/ts-smart-logger

Download ts-smart-logger

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/ts-smart-logger/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>ts-smart-logger</artifactId>
    <version>0.0.4</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/ts-smart-logger/
implementation 'org.webjars.npm:ts-smart-logger:0.0.4'
// https://jarcasting.com/artifacts/org.webjars.npm/ts-smart-logger/
implementation ("org.webjars.npm:ts-smart-logger:0.0.4")
'org.webjars.npm:ts-smart-logger:jar:0.0.4'
<dependency org="org.webjars.npm" name="ts-smart-logger" rev="0.0.4">
  <artifact name="ts-smart-logger" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='ts-smart-logger', version='0.0.4')
)
libraryDependencies += "org.webjars.npm" % "ts-smart-logger" % "0.0.4"
[org.webjars.npm/ts-smart-logger "0.0.4"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

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 = LoggerFactory.makeLogger(LoggedFirstClass);
   // private logger = LoggerFactory.makeLogger('LoggedFirstClass');    // In the case of "uglify" using

   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.

Versions

Version
0.0.4