@za-utils/logger

    0.0.19 • Public • Published

    Simple Logger

    Logger based on winston and includes debug namespaces

    Install

    npm install @za-utils/logger

    Usage

    Initialize

    const {Logger} = require('@za-utils/logger');
    
    const options = {
        configureHandler: (logger, winston) => logger, // Custom configure logger
        debug: require('debug'), // If you want control enabled/disabled namespaces by debug.enable()/debug.disable()
    };
    
    Logger.init('My Project', options); // Project name will be use in namespaces

    Sample

    const {Logger} = require('@za-utils/logger');
    
    // return winston logger instance
    const logger = Logger.createLogger('my-name-space'); // Total namespace = My Project:my-name-space

    Control namespace

    • From ENV

      DEBUG=my-name-space*

    • From script using debug

      const debug = require('debug');
      
      debug.enable('my-name-space*');
    • From script using this lib

      const {Logger} = require('@za-utils/logger');
      
      console.log(Logger.enabled); // Get state
      
      Logger.enable(); // Enable logging if it is disabled
      Logger.disbale(); // Disbale logging
      
      Logger.applyNamespaceString('my-name-space*'); // Apply namespace from string (overwrite previous namespaces)
      
      Logger.enableNamespace('my-name-space,some*,-other'); // Add namespaces to enable and disable from string
      Logger.enableNamespace(['my-name-space','some*','-other']); // Add namespaces to enable and disable from array
      
      Logger.disableNamespace('my-name-space,some*,-other'); // Add namespaces to disable from string
      Logger.disableNamespace(['my-name-space','some*','-other']); // Add namespaces to disable from array
      
      Logger.enableNamespace(); // Get enabled
      Logger.disableNamespace(); // Get disabled

    Reconfigure logger

    const {Logger} = require('@za-utils/logger');
    
    Logger.configureLogger((logger, winston) => {
        // some configure
        
        return logger;
    });

    Install

    npm i @za-utils/logger

    DownloadsWeekly Downloads

    6

    Version

    0.0.19

    License

    ISC

    Unpacked Size

    13.3 kB

    Total Files

    6

    Last publish

    Collaborators

    • zaycevdev