import Model from "../db/Model"; import { LogLevel } from "../Logger"; import Validator from "../db/Validator"; export default class Log extends Model { defineProperties() { this.defineProperty('level', new Validator().defined()); this.defineProperty('message', new Validator().defined().between(0, 65535)); this.defineProperty('log_id', new Validator().acceptUndefined().length(16)); this.defineProperty('error_name', new Validator().acceptUndefined().between(0, 128)); this.defineProperty('error_message', new Validator().acceptUndefined().between(0, 512)); this.defineProperty('error_stack', new Validator().acceptUndefined().between(0, 65535)); this.defineProperty('created_at', new Validator()); } getLevel() { if (typeof this.level !== 'number') return 'ERROR'; return LogLevel[this.level]; } setLevel(level) { this.level = LogLevel[level]; } getLogID() { if (!this.log_id) return null; const chars = this.log_id.toString('hex'); let out = ''; let i = 0; for (const l of [8, 4, 4, 4, 12]) { if (i > 0) out += '-'; out += chars.substr(i, l); i += l; } return out; } setLogID(buffer) { this.log_id = buffer; } getErrorName() { return this.error_name || ''; } getErrorMessage() { return this.error_message || ''; } getErrorStack() { return this.error_stack || ''; } setError(error) { if (!error) return; this.error_name = error.name; this.error_message = error.message; this.error_stack = error.stack; } } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTG9nLmpzIiwic291cmNlUm9vdCI6Ii4vIiwic291cmNlcyI6WyJtb2RlbHMvTG9nLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxNQUFNLGFBQWEsQ0FBQztBQUNoQyxPQUFPLEVBQUMsUUFBUSxFQUFlLE1BQU0sV0FBVyxDQUFDO0FBQ2pELE9BQU8sU0FBUyxNQUFNLGlCQUFpQixDQUFDO0FBRXhDLE1BQU0sQ0FBQyxPQUFPLE9BQU8sR0FBSSxTQUFRLEtBQUs7SUFTeEIsZ0JBQWdCO1FBQ3RCLElBQUksQ0FBQyxjQUFjLENBQVMsT0FBTyxFQUFFLElBQUksU0FBUyxFQUFVLENBQUMsT0FBTyxFQUFFLENBQUMsQ0FBQztRQUN4RSxJQUFJLENBQUMsY0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