UNPKG

@betit/orion-node-sdk

Version:
75 lines 1.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const index_1 = require("../utils/index"); const levels_1 = require("./levels"); class Message { constructor(_client, _host, _message) { this._client = _client; this._host = _host; this._message = _message; this._vm_host = process.env.HOST; this._level = levels_1.INFO; } setLevel(level) { this._level = level; return this; } /** * @deprecated */ setLOC(err) { const LOC = index_1.getLineFromError(err); this._loc = LOC.filepath + ':' + LOC.line; if (LOC.stack !== undefined) { this._stack = LOC.stack; } return this; } setId(id) { this._id = id; return this; } setParams(params) { this._params = params; return this; } setMap(params) { this._args = params; return this; } setError(err) { const parsed = index_1.parseError(err); const error = { message: parsed.message, stack: parsed.stack, code: parsed.code, }; this._error = JSON.stringify(error); return this; } send() { let m = { vm_host: this._vm_host, host: this._host, message: this._message, level: this._level, }; if (this._params !== undefined) { m.params = this._params; } if (this._error !== undefined) { m.error = this._error; } if (this._id !== undefined) { m['x-trace-id'] = this._id; } if (this._args !== undefined) { for (let key in this._args) { m[key] = this._args[key]; } } this._client.send(m); } } exports.Message = Message; //# sourceMappingURL=message.js.map