Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 = '';
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') {
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;
'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;
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)
})
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);
};
};
};
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) => {
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);
};
};
};
'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;