ssh-terminal
Version:
SSH Terminal component based on xterm.js for multiple frontend frameworks
160 lines (159 loc) • 4.06 kB
JavaScript
var d = Object.defineProperty, L = Object.defineProperties;
var $ = Object.getOwnPropertyDescriptors;
var l = Object.getOwnPropertySymbols;
var m = Object.prototype.hasOwnProperty, w = Object.prototype.propertyIsEnumerable;
var s = (e, t, o) => t in e ? d(e, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[t] = o, h = (e, t) => {
for (var o in t || (t = {}))
m.call(t, o) && s(e, o, t[o]);
if (l)
for (var o of l(t))
w.call(t, o) && s(e, o, t[o]);
return e;
}, u = (e, t) => L(e, $(t));
var f = (e, t, o) => (s(e, typeof t != "symbol" ? t + "" : t, o), o);
import S from "./validation-d8717515.mjs";
const n = class n {
constructor() {
this.isProduction = typeof window != "undefined" && window.location.hostname !== "localhost" && window.location.hostname !== "127.0.0.1", this.logLevel = this.isProduction ? "error" : "debug", this.maxLogLength = 1e3;
}
/**
* Kiểm tra có nên log không
*/
shouldLog(t) {
return n.LEVELS[t] >= n.LEVELS[this.logLevel];
}
/**
* Làm sạch dữ liệu trước khi log
*/
sanitizeData(t) {
if (t == null)
return t;
const o = S.sanitizeForLogging(t), i = JSON.stringify(o);
return i.length > this.maxLogLength ? u(h({}, o), {
_truncated: !0,
_originalLength: i.length
}) : o;
}
/**
* Format log message
*/
formatMessage(t, o, i = null) {
const g = `[${(/* @__PURE__ */ new Date()).toISOString()}] [${t.toUpperCase()}] [CLIENT]`;
if (i) {
const c = this.sanitizeData(i);
return `${g} ${o} ${JSON.stringify(c)}`;
}
return `${g} ${o}`;
}
/**
* Debug log
*/
debug(t, o = null) {
this.shouldLog("debug") && console.debug(this.formatMessage("debug", t, o));
}
/**
* Info log
*/
info(t, o = null) {
this.shouldLog("info") && console.info(this.formatMessage("info", t, o));
}
/**
* Warning log
*/
warn(t, o = null) {
this.shouldLog("warn") && console.warn(this.formatMessage("warn", t, o));
}
/**
* Error log
*/
error(t, o = null) {
this.shouldLog("error") && console.error(this.formatMessage("error", t, o));
}
/**
* Log connection events
*/
logConnection(t, o = {}) {
const i = this.sanitizeData(o);
this.info(`Connection ${t}`, i);
}
/**
* Log authentication events
*/
logAuth(t, o = {}) {
const i = this.sanitizeData(o);
this.info(`Auth ${t}`, i);
}
/**
* Log security events
*/
logSecurity(t, o = {}) {
const i = this.sanitizeData(o);
this.warn(`Security ${t}`, i);
}
/**
* Log performance metrics
*/
logPerformance(t, o, i = "ms") {
this.debug(`Performance ${t}`, { value: o, unit: i });
}
/**
* Log với custom level
*/
log(t, o, i = null) {
this.shouldLog(t) && console[t](this.formatMessage(t, o, i));
}
/**
* Tạo logger instance với context
*/
createContextLogger(t) {
return {
debug: (o, i) => this.debug(`[${t}] ${o}`, i),
info: (o, i) => this.info(`[${t}] ${o}`, i),
warn: (o, i) => this.warn(`[${t}] ${o}`, i),
error: (o, i) => this.error(`[${t}] ${o}`, i),
logConnection: (o, i) => this.logConnection(`[${t}] ${o}`, i),
logAuth: (o, i) => this.logAuth(`[${t}] ${o}`, i),
logSecurity: (o, i) => this.logSecurity(`[${t}] ${o}`, i),
logPerformance: (o, i, a) => this.logPerformance(`[${t}] ${o}`, i, a)
};
}
/**
* Alias for backward compatibility
*/
createContext(t) {
return this.createContextLogger(t);
}
/**
* Set log level
*/
setLogLevel(t) {
n.LEVELS.hasOwnProperty(t) && (this.logLevel = t);
}
/**
* Get current log level
*/
getLogLevel() {
return this.logLevel;
}
/**
* Enable/disable production mode
*/
setProductionMode(t) {
this.isProduction = t, this.logLevel = t ? "error" : "debug";
}
};
/**
* Các mức độ log
*/
f(n, "LEVELS", {
debug: 0,
info: 1,
warn: 2,
error: 3
});
let r = n;
const D = new r();
export {
r as SecureLogger,
D as default
};