All Projects → ostdotcom → base

ostdotcom / base

Licence: LGPL-3.0 license
OST Base provides advanced Promise Queue Manager and other utilities.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to base

notification
OST Notification helps publish critical events for cross platform communications
Stars: ✭ 20 (+5.26%)
Mutual labels:  ost, openst
ng2-logger
Isomorphic logger for Browser and NodeJS, ( typescript / javascript ) apps
Stars: ✭ 61 (+221.05%)
Mutual labels:  logger
l
Golang Pretty Logger
Stars: ✭ 51 (+168.42%)
Mutual labels:  logger
JJSwiftLog
Swift log library for all platform
Stars: ✭ 51 (+168.42%)
Mutual labels:  logger
ets2-job-logger
ETS2 Job Logger
Stars: ✭ 15 (-21.05%)
Mutual labels:  logger
logops
Really simple and performant logger for node projects compatible with any kind of deployments as your server operations/environment defined
Stars: ✭ 20 (+5.26%)
Mutual labels:  logger
Torch-Scope
A Toolkit for Training, Tracking, Saving Models and Syncing Results
Stars: ✭ 62 (+226.32%)
Mutual labels:  logger
RxLogs
An Android & Kotlin Reactive Advanced Logging Framework.
Stars: ✭ 12 (-36.84%)
Mutual labels:  logger
G-Earth
Cross-platform Habbo packet manipulator
Stars: ✭ 52 (+173.68%)
Mutual labels:  logger
lines-logger
Browser logger that rests lines in peace
Stars: ✭ 26 (+36.84%)
Mutual labels:  logger
logback-access-spring-boot-starter
Spring Boot Starter for Logback-access.
Stars: ✭ 153 (+705.26%)
Mutual labels:  logger
Web-Tracker
Stand alone program that Tracks/Logs all the opened websites in the Chrome Browser. Even incognito! *No need to install anything in browser*
Stars: ✭ 34 (+78.95%)
Mutual labels:  logger
wlog
A simple logging interface that supports cross-platform color and concurrency.
Stars: ✭ 59 (+210.53%)
Mutual labels:  logger
loggers
Abstract logging for Golang projects. A kind of log4go in the spirit of log4j
Stars: ✭ 17 (-10.53%)
Mutual labels:  logger
phoenix passwordless login
Phoenix Passwordless Login
Stars: ✭ 28 (+47.37%)
Mutual labels:  logger
WormholyForObjectiveC
Network debugging made easy,This network debugging tool is developed based on the swift version of Wormholy.
Stars: ✭ 21 (+10.53%)
Mutual labels:  logger
perforce-commit-discord-bot
🗒️ ✏️Posts the most recent commit messages from a Perforce version control server to a Discord channel.
Stars: ✭ 22 (+15.79%)
Mutual labels:  logger
DRF-API-Logger
An API Logger for your Django Rest Framework project.
Stars: ✭ 184 (+868.42%)
Mutual labels:  logger
Android-NativeLogger
Android Logger
Stars: ✭ 21 (+10.53%)
Mutual labels:  logger
QLogger
Multi-threading logger for Qt applications
Stars: ✭ 46 (+142.11%)
Mutual labels:  logger

OST Base provides advanced Promise Queue Manager and other utilities.

Build Status npm version

Install

npm install @ostdotcom/base --save

PromiseQueueManager Usage

const OSTBase = require('@ostdotcom/base'),
  logger  = new OSTBase.Logger("my_module_name");

const queueManagerOptions = {
  // Specify the name for easy identification in logs.
  name: "my_module_name_promise_queue"

  // resolvePromiseOnTimeout :: set this flag to false if you need custom handling.
  // By Default, the manager will neither resolve nor reject the Promise on time out.
  , resolvePromiseOnTimeout: false
  // The value to be passed to resolve when the Promise has timedout.
  , resolvedValueOnTimeout: null

  // rejectPromiseOnTimeout :: set this flag to true if you need custom handling.
  , rejectPromiseOnTimeout : false

  //  Pass timeoutInMilliSecs in options to set the timeout.
  //  If less than or equal to zero, timeout will not be observed.
  , timeoutInMilliSecs: 5000

  //  Pass maxZombieCount in options to set the max acceptable zombie count.
  //  When this zombie promise count reaches this limit, onMaxZombieCountReached will be triggered.
  //  If less than or equal to zero, onMaxZombieCountReached callback will not triggered.
  , maxZombieCount: 0

  //  Pass logInfoTimeInterval in options to log queue healthcheck information.
  //  If less than or equal to zero, healthcheck will not be logged.
  , logInfoTimeInterval : 0


  , onPromiseResolved: function ( resolvedValue, promiseContext ) {
    //onPromiseResolved will be executed when the any promise is resolved.
    //This callback method should be set by instance creator.
    //It can be set using options parameter in constructor.
    const oThis = this;

    logger.log(oThis.name, " :: a promise has been resolved. resolvedValue:", resolvedValue);
  }

  , onPromiseRejected: function ( rejectReason, promiseContext ) {
    //onPromiseRejected will be executed when the any promise is timedout.
    //This callback method should be set by instance creator.
    //It can be set using options parameter in constructor.
    const oThis = this;

    logger.log(oThis.name, " :: a promise has been rejected. rejectReason: ", rejectReason);
  }

  , onPromiseTimedout: function ( promiseContext ) {
    //onPromiseTimedout will be executed when the any promise is timedout.
    //This callback method should be set by instance creator.
    //It can be set using options parameter in constructor.
    const oThis = this;

    logger.log(oThis.name, ":: a promise has timed out.", promiseContext.executorParams);
  }

  , onMaxZombieCountReached: function () {
    //onMaxZombieCountReached will be executed when maxZombieCount >= 0 && current zombie count (oThis.zombieCount) >= maxZombieCount.
    //This callback method should be set by instance creator.
    //It can be set using options parameter in constructor.
    const oThis = this;

    logger.log(oThis.name, ":: maxZombieCount reached.");

  }

  , onPromiseCompleted: function ( promiseContext ) {
    //onPromiseCompleted will be executed when the any promise is removed from pendingPromise queue.
    //This callback method should be set by instance creator.
    //It can be set using options parameter in constructor.
    const oThis = this;

    logger.log(oThis.name, ":: a promise has been completed.");
  }  
  , onAllPromisesCompleted: function () {
    //onAllPromisesCompleted will be executed when the last promise in pendingPromise is resolved/rejected.
    //This callback method should be set by instance creator.
    //It can be set using options parameter in constructor.
    //Ideally, you should set this inside SIGINT/SIGTERM handlers.

    logger.log("Examples.allResolve :: onAllPromisesCompleted triggered");
    manager.logInfo();
  }
};


const promiseExecutor = function ( resolve, reject, params, promiseContext ) {
  //promiseExecutor
  setTimeout(function () {
    resolve( params.cnt ); // Try different things here.
  }, 1000);
};

const manager = new OSTBase.OSTPromise.QueueManager( promiseExecutor, queueManagerOptions);

for( let cnt = 0; cnt < 50; cnt++ ) {
  manager.createPromise( {"cnt": (cnt + 1) } );
}

Logger Usage

const OSTBase = require('@ostdotcom/base'),
  Logger  = OSTBase.Logger,
  logger  = new Logger("my_module_name", Logger.LOG_LEVELS.TRACE);

//Log Level FATAL 
logger.notify("notify called");

//Log Level ERROR
logger.error("error called");

//Log Level WARN
logger.warn("warn called");

//Log Level INFO
logger.info("info Invoked");
logger.step("step Invoked");
logger.win("win called");

//Log Level DEBUG
logger.log("log called");
logger.debug("debug called");
logger.dir({ l1: { l2 : { l3Val: "val3", l3: { l4Val: { val: "val"  }}} }});

//Log Level TRACE
logger.trace("trace called");

All methods will be available for use irrespcetive of configured log level. Log Level only controls what needs to be logged.

Method to Log Level Map

Method Enabling Log Level
notify FATAL
error ERROR
warn WARN
info INFO
step INFO
win INFO
debug DEBUG
log DEBUG
dir DEBUG
trace TRACE

Response formatter usage

const rootPrefix = '.',
  paramErrorConfig = require(rootPrefix + '/tests/mocha/lib/formatter/param_error_config'),
  apiErrorConfig = require(rootPrefix + '/tests/mocha/lib/formatter/api_error_config');

const OSTBase = require('@ostdotcom/base'),
  ResponseHelper  = OSTBase.responseHelper,
  responseHelper = new ResponseHelper({
      moduleName: 'companyRestFulApi'
  });
    
//using error function
responseHelper.error({
  internal_error_identifier: 's_vt_1', 
  api_error_identifier: 'test_1',
  debug_options: {id: 1234},
  error_config: {
    param_error_config: paramErrorConfig,
    api_error_config: apiErrorConfig   
  }
});
    
//using paramValidationError function
responseHelper.paramValidationError({
  internal_error_identifier:"s_vt_2", 
  api_error_identifier: "test_1", 
  params_error_identifiers: ["user_name_inappropriate"], 
  debug_options: {id: 1234},
  error_config: {
    param_error_config: paramErrorConfig,
    api_error_config: apiErrorConfig   
  }
});

// Result object is returned from responseHelper method invocations above, we can chain several methods as shown below
    
responseHelper.error({
  internal_error_identifier: 's_vt_1', 
  api_error_identifier: 'invalid_api_params',
  debug_options: {id: 1234},
  error_config: {
    param_error_config: paramErrorConfig,
    api_error_config: apiErrorConfig   
  }
}).isSuccess();

responseHelper.error({
  internal_error_identifier: 's_vt_1', 
  api_error_identifier: 'invalid_api_params',
  debug_options: {id: 1234},
  error_config: {
    param_error_config: paramErrorConfig,
    api_error_config: apiErrorConfig   
  }
}).isFailure();

responseHelper.error({
  internal_error_identifier: 's_vt_1', 
  api_error_identifier: 'invalid_api_params',
  debug_options: {id: 1234},
  error_config: {
    param_error_config: paramErrorConfig,
    api_error_config: apiErrorConfig   
  }
}).toHash();    
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].