1.0.1 • Published 4 years ago

@alt-javascript/logger-darkly v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

A Listener For Updating The LoggerCategoryCache From A Launch Darkly Variation

NPM Language Badge Package Badge release notes

Introduction

An "Arctor" implementation for listening for and updating the LoggerCategoryCache from a Launch Darkly variation in server-side node.js.

Usage

To use the module, follow the example in the included below file, which plays nicely with all the other @alt-javascript modules.

The Scanner, takes a LoggerCategoryCacheVariation which is injected with the global root context LoggerCategoryCache instance (each logger has a handle to it, though we could get it directly from global.boot.contexts.root.loggercategoryCache) that will act on flagged LaunchDarkly JSON config and replace the internal cache object within it's see(clearly) function.

const LaunchDarkly = require('launchdarkly-node-server-sdk');
const ScannerDarkly = require('@alt-javascript/scanner-darkly');
const {config} = require("@alt-javascript/config");
const {boot} = require("@alt-javascript/boot");
const {LoggerFactory} = require('@alt-javascript/logger');
boot({config});


const LoggerCategoryCacheVariation = require('@alt-javascript/scanner-darkly'); // this  uses booted logging config, so is required after boot().

const logger = LoggerFactory.getLogger('@alt-javascript/scanner-darkly/scan');
const ldlogger = LoggerFactory.getLogger('LaunchDarkly');
const SDK_KEY = config.get('scanner.darkly.sdk-key');
const scannerDarkly = new ScannerDarkly(
    new LoggerCategoryCacheVariation('logging-levels', {"key": "user@test.com"}, {"/":"error"},logger.cache),
    SDK_KEY,
    {logger: ldlogger});

scannerDarkly.init();
// ... later, on process exit.
scannerDarkly.destroy();