"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.Logger=void 0;var _asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _winston=require("winston");
var _stacktraceJs=_interopRequireDefault(require("stacktrace-js"));
var _utils=require("@corenode/utils");const

combine=_winston.format.combine,timestamp=_winston.format.timestamp,label=_winston.format.label,printf=_winston.format.printf;

class Logger{constructor(){(0,_defineProperty2.default)(this,"log",
(...context)=>{
_stacktraceJs.default.get().then(stack=>{
stack=stack[2];
this.output({level:"log",stack},...context);
});
});(0,_defineProperty2.default)(this,"warn",
(...context)=>{
_stacktraceJs.default.get().then(stack=>{
stack=stack[2];
this.output({level:"warn",stack},...context);
});
});(0,_defineProperty2.default)(this,"error",
(...context)=>{
_stacktraceJs.default.get().then(stack=>{
stack=stack[2];
this.output({level:"error",stack},...context);
});
});(0,_defineProperty2.default)(this,"dump",

(level,...context)=>{
_stacktraceJs.default.get().then(stack=>{
stack=stack[2];
this.createLogger({level:level,stack}).info(...context);
});
})}

output(payload,...context){var _this=this;return(0,_asyncToGenerator2.default)(function*(){const
level=payload.level,stack=payload.stack;

_this.createLogger({level,stack}).info(...context);
_utils.verbosity.options({method:`[${stack.functionName}]`})[level](...context)})();
}

createLogger({level,stack}){
return(0,_winston.createLogger)({
format:combine(
label({label:level}),
timestamp(),
printf(({message,label,timestamp})=>{var _stack$method;
return`> ${timestamp} ${((_stack$method=stack===null||stack===void 0?void 0:stack.method)!==null&&_stack$method!==void 0?_stack$method:false)?`${stack.method}`:""}[${label!==null&&label!==void 0?label:"log"}] : ${message}`;
})),

transports:[
new _winston.transports.File({filename:"dumps.log"})]});


}}exports.Logger=Logger;