Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private static getCaller(): string {
// get the stack trace above logInner. casting is necessary because the stack trace package only accepts () => void functions.
const stack = Stacktrace.get(Log.logInner as unknown as () => void);
// 6 frames is the magic number to get around __awaiters, past the Log.x function, and up to the frame we care about.
const frame = stack[6];
if (frame == null) {
return "N/A";
}
let methodName = frame.getMethodName() || frame.getFunctionName();
if (methodName != null) {
// If it's a callback, there will be extra stuff we aren't interested in separated by dots
// eg "Project.__dirname.constructor.connection.update"
// strip out everything up to the last dot, if there is one
const splitByPeriod: string[] = methodName.split(".");
if (splitByPeriod.length > 1) {
methodName = splitByPeriod[splitByPeriod.length - 1];
}
methodName = `.${methodName}()`;
constructor (level, source) {
if (!level) {
throw new Error('Level is missing.');
}
/* eslint-disable global-require */
const flaschenpost = require('../flaschenpost');
/* eslint-enable global-require */
const options = {};
options.objectMode = true;
options.source = source || stackTrace.get()[1].getFileName();
super(options);
this.level = level;
this.logger = flaschenpost.getLogger(options.source);
if (!this.logger[this.level]) {
throw new Error('Level is invalid.');
}
}
export default function (folder, recursive = false, pattern = patternDefault, parentDir = undefined) {
folder = path.normalize(folder)
if (!parentDir) {
parentDir = path.dirname(stackTrace.get()[1].getFileName())
}
const contextDir = path.join(parentDir, folder)
const contextDirLen = contextDir.length + 1
const normalizedFolder = path.resolve(parentDir, folder)
const folderContents = getFolderContents(normalizedFolder, recursive)
.filter(item => {
return pattern.test(item)
})
.map(item => {
return '.' + SEP + item.substr(contextDirLen)
})
const keys = function () {
return folderContents
}
public mutate(options: MutationOptions<q> | string): Promise {
if (typeof options === "string") {
options = {
name: options,
};
}
const m = internalGraphql.mutate({
mutation: options.mutation,
path: options.path,
name: options.name,
moduleDir: (options as any).moduleDir ? (options as any).moduleDir : trace.get()[1].getFileName(),
});
return this.executeMutation(m, options.variables, options.options);
}
</q>
function getMessage() {
var trace = stack.get()[2];
var fileName = trace.getFileName();
if (fileName !== 'repl') {
return getSource(trace);
} else {
return trace.fun.toString();
}
}
exports.makeTaskInfo = function getTaskInfo(name, calleeOffset) {
calleeOffset = undefined !== calleeOffset ? calleeOffset : 2;
var trace = stackTrace.get();
var gulpFile = trace[calleeOffset];
if (!gulpFile) {
return null;
}
return {
name: name,
file: gulpFile.getFileName(),
line: gulpFile.getLineNumber()
};
};
function getData(func) {
var trace = stackTrace.get(func || getCaller(getData));
var caller = trace[0];
return {
typeName: caller.getTypeName(),
functionName: caller.getFunctionName(),
methodName: caller.getMethodName(),
filePath: caller.getFileName(),
lineNumber: caller.getLineNumber(),
topLevelFlag: caller.isToplevel(),
nativeFlag: caller.isNative(),
evalFlag: caller.isEval(),
evalOrigin: caller.getEvalOrigin()
};
}
public error(...items: Array): void {
this.addEntry(LogMessageSeverity.ERROR, this.getFunc(stackTrace.get()), ...items);
}
exception.getTrace = function (err) {
var trace = err ? stackTrace.parse(err) : stackTrace.get();
return trace.map(function (site) {
return {
column: site.getColumnNumber(),
file: site.getFileName(),
function: site.getFunctionName(),
line: site.getLineNumber(),
method: site.getMethodName(),
native: site.isNative(),
}
});
};
template (logLevel, data) {
const trace = stackTrace.get()
trace.splice(0, 2)
let methodName = ''
_.forEach(trace, (item) => {
if (item.getFunctionName() != null) {
methodName = item.getFunctionName()
return false
}
})
methodName = colors.green(methodName)
if (logLevel == null) { logLevel = this._trace }
const prefix = `${this.timestamp()} ${logLevel.prefix} ${methodName}`
if (_.isArray(data) && data.length === 1) { data = _.first(data) }
if (_.isString(data)) {
logLevel.instance('%s %s', prefix, data)
} else {
if (_.isString(_.first(data))) {