How to use the loglevel.methodFactory function in loglevel

To help you get started, we’ve selected a few loglevel examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bitlum / bitlum-front / app / sources / src / utils / logging.js View on Github external
const loglevel = require('loglevel');

// -----------------------------------------------------------------------------
// Code
// -----------------------------------------------------------------------------

const colors = {
  trace: '',
  debug: '\x1b[90m',
  info: '\x1b[94m',
  warn: '\x1b[93m',
  error: '\x1b[91m',
};

const originalFactory = loglevel.methodFactory;
loglevel.methodFactory = (methodName, logLevel, loggerName) => {
  const rawMethod = originalFactory(methodName, logLevel, loggerName);
  return message => {
    // Getting stacktrace
    const err = new Error();
    const callerLine = err.stack.split('\n')[2];
    let invokeLocation = callerLine.match(/\(\/.*\)/);
    if (invokeLocation) {
      // Removing () brackets around line and replace core folder
      // where app is stored inside Docker container
      invokeLocation = invokeLocation[0].slice(1, -1).replace('/opt/app', '');
    } else {
      invokeLocation = '';
    }

    let prefix = '';
github bitlum / bitlum-front / app / sources / src / utils / logging.js View on Github external
const loglevel = require('loglevel');

// -----------------------------------------------------------------------------
// Code
// -----------------------------------------------------------------------------

const colors = {
  trace: '',
  debug: '\x1b[90m',
  info: '\x1b[94m',
  warn: '\x1b[93m',
  error: '\x1b[91m',
};

const originalFactory = loglevel.methodFactory;
loglevel.methodFactory = (methodName, logLevel, loggerName) => {
  const rawMethod = originalFactory(methodName, logLevel, loggerName);
  return message => {
    // Getting stacktrace
    const err = new Error();
    const callerLine = err.stack.split('\n')[2];
    let invokeLocation = callerLine.match(/\(\/.*\)/);
    if (invokeLocation) {
      // Removing () brackets around line and replace core folder
      // where app is stored inside Docker container
      invokeLocation = invokeLocation[0].slice(1, -1).replace('/opt/app', '');
    } else {
      invokeLocation = '';
    }

    let prefix = '';
    if (process.env.NODE_ENV === 'development') {
github podlove / podlove-ui / src / old / js / logging.js View on Github external
var loglevel = require('loglevel');
var originalFactory = loglevel.methodFactory;

// extend loglevel here
function logWithLoggerName(methodName, logLevel, loggerName) {
  var rawMethod = originalFactory(methodName, logLevel, loggerName);

  return function () {
    var args = [loggerName];
    for (var l = arguments.length, i = 0; i < l; i++) {
      args.push(arguments[i]);
    }
    rawMethod.apply(loglevel, args);
  };
}

// loglevel.methodFactory = logWithLoggerName;
github pwa-builder / PWABuilder-CLI / manifoldjs-lib / src / log.js View on Github external
'use strict';

var log = require('loglevel'),
		path = require('path');

var appPath = path.dirname(require.main.filename);
var app = require(path.join(appPath, 'package.json'));

var maxLenSeverity = 5;
var maxLenSource = 12;

var originalFactory = log.methodFactory;
log.methodFactory = function (methodName, logLevel, loggerName) {
	var rawMethod = originalFactory(methodName, logLevel, loggerName);

	return function (message, source, severity) {
		message = message.replace(/\n/g, '\n' + Array(maxLenSeverity + maxLenSource + 6).join(' '));
		source = source || loggerName || app.name;
		severity = severity || methodName;
		rawMethod(
			'[' + severity + Array(Math.max(maxLenSeverity - severity.length + 1, 0)).join(' ') + '] '
			+ source + Array(Math.max(maxLenSource - source.length + 1, 0)).join(' ') + ': '
			+ message);
	};
}

module.exports = log;
github muuvmuuv / vscode-sundial / src / logger.ts View on Github external
import logger from 'loglevel'

const originalFactory = logger.methodFactory

logger.methodFactory = (methodName, logLevel, loggerName) => {
  const rawMethod = originalFactory(methodName, logLevel, loggerName)
  const devider = ':'
  const name = loggerName ? devider + loggerName : ''
  const prefix = `(Sundial${name}) => `

  return (...messages) => {
    rawMethod(prefix, ...messages)
  }
}

logger.setDefaultLevel(logger.levels.INFO)

function setGlobalLevel(level: any) {
  Object.values(logger.getLoggers()).forEach((lg) => {
    lg.setLevel(level)
  })
github sienori / simple-translate / src / common / log.js View on Github external
export const overWriteLogLevel = () => {
  if (isInited) return;
  isInited = true;

  const originalFactory = log.methodFactory;
  log.methodFactory = (methodName, logLevel, loggerName) => {
    const rawMethod = originalFactory(methodName, logLevel, loggerName);

    return (logDir, ...args) => {
      rawMethod(`[${methodName}]`, `${logDir}:`, ...args);
    };
  };
};
github muuvmuuv / vscode-sundial / src / logger.ts View on Github external
import logger from 'loglevel'

const originalFactory = logger.methodFactory

logger.methodFactory = (methodName, logLevel, loggerName) => {
  const rawMethod = originalFactory(methodName, logLevel, loggerName)
  const devider = ':'
  const name = loggerName ? devider + loggerName : ''
  const prefix = `(Sundial${name}) => `

  return (...messages) => {
    rawMethod(prefix, ...messages)
  }
}

logger.setDefaultLevel(logger.levels.INFO)

function setGlobalLevel(level: any) {
  Object.values(logger.getLoggers()).forEach((lg) => {
github sienori / simple-translate / src / common / log.js View on Github external
export const overWriteLogLevel = () => {
  if (isInited) return;
  isInited = true;

  const originalFactory = log.methodFactory;
  log.methodFactory = (methodName, logLevel, loggerName) => {
    const rawMethod = originalFactory(methodName, logLevel, loggerName);

    return (logDir, ...args) => {
      rawMethod(`[${methodName}]`, `${logDir}:`, ...args);
    };
  };
};
github pwa-builder / PWABuilder-CLI / manifoldjs-lib / src / log.js View on Github external
'use strict';

var log = require('loglevel'),
		path = require('path');

var appPath = path.dirname(require.main.filename);
var app = require(path.join(appPath, 'package.json'));

var maxLenSeverity = 5;
var maxLenSource = 12;

var originalFactory = log.methodFactory;
log.methodFactory = function (methodName, logLevel, loggerName) {
	var rawMethod = originalFactory(methodName, logLevel, loggerName);

	return function (message, source, severity) {
		message = message.replace(/\n/g, '\n' + Array(maxLenSeverity + maxLenSource + 6).join(' '));
		source = source || loggerName || app.name;
		severity = severity || methodName;
		rawMethod(
			'[' + severity + Array(Math.max(maxLenSeverity - severity.length + 1, 0)).join(' ') + '] '
			+ source + Array(Math.max(maxLenSource - source.length + 1, 0)).join(' ') + ': '
			+ message);
	};
}

module.exports = log;