56 lines
7.5 KiB
JavaScript
56 lines
7.5 KiB
JavaScript
|
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTG9nLmpzIiwic291cmNlUm9v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