Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /usr/local/lib/node_modules/wonlog/node_modules/wonlog-agent/dist/ drwxr-xr-x | |
| Viewing file: Select action/file-type: "use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
const axios_1 = __importDefault(require("axios"));
const split2_1 = __importDefault(require("split2"));
const json5_1 = __importDefault(require("json5"));
const strip_ansi_1 = __importDefault(require("strip-ansi"));
const commander_1 = require("commander");
const nanoid_1 = require("nanoid");
const date_fns_1 = require("date-fns");
const program = new commander_1.Command();
program
.option('-h, --server-host [host]', 'HTTP Server host', '127.0.0.1')
.option('-p, --server-port [port]', 'HTTP Server port', '7978')
.option('-s, --stream-name [name]', 'Stream name')
.option('-v, --verbose [type]', 'Print logs', false);
program.parse(process.argv);
const _options = program.opts();
_options.streamName = (_a = _options.streamName) !== null && _a !== void 0 ? _a : (0, nanoid_1.nanoid)();
if (_options.verbose) {
process.stdin.pipe(process.stdout);
}
const axiosInstance = axios_1.default.create({
baseURL: `http://${_options.serverHost}:${_options.serverPort}/api/v1/`,
});
const JUNK_MAX_SIZE = 50000;
let _buffer = [];
let _bufferSize = 0;
let _isTimedOut = false;
const timer = setInterval(() => {
_isTimedOut = true;
}, 300);
process.stdin.pipe((0, split2_1.default)()).on('data', function (str) {
try {
let textLog = (0, strip_ansi_1.default)(str); // Strin ANSI escape codes
if (textLog.length > JUNK_MAX_SIZE) {
textLog = `A single log can't exceeeds the size of ${JUNK_MAX_SIZE} Bytes. - ${textLog.substring(0, JUNK_MAX_SIZE)}...`;
}
const hydratedLog = {
wonlogMetadata: {
streamID: _options.streamName,
logXRefID: (0, nanoid_1.nanoid)(),
timestamp: Date.now(),
},
data: {},
};
let isJSON = true;
let isObject = false;
let parsedLog = undefined;
try {
parsedLog = json5_1.default.parse(textLog);
isObject = typeof parsedLog === 'object' && !Array.isArray(parsedLog);
}
catch (_a) {
isJSON = false;
}
if (isJSON && isObject) {
hydratedLog.data = parsedLog;
if (!hydratedLog.data.message) {
hydratedLog.data.message = `${textLog.substring(0, 200)}...`;
}
if (isJSON && typeof (parsedLog === null || parsedLog === void 0 ? void 0 : parsedLog.timestamp) === 'number') {
hydratedLog.wonlogMetadata.timestamp = parsedLog.timestamp;
}
else if (isJSON && typeof (parsedLog === null || parsedLog === void 0 ? void 0 : parsedLog.timestamp) === 'string') {
const parsedTime = (0, date_fns_1.parseISO)(parsedLog.timestamp).getTime();
hydratedLog.wonlogMetadata.timestamp = isNaN(parsedTime)
? Date.now()
: parsedTime;
}
}
else {
// Either text log or non-object JSON
hydratedLog.data = { message: textLog };
hydratedLog.wonlogMetadata.timestamp = Date.now();
}
const stringifiedData = JSON.stringify(hydratedLog);
const stringifiedDataSize = stringifiedData.length;
if (JUNK_MAX_SIZE < _bufferSize + stringifiedDataSize || _isTimedOut) {
axiosInstance
.post('logs', {
data: `[${_buffer.join(',')}]`,
meta: { timestamp: Date.now() },
})
.catch((err) => {
console.error(err.message);
});
_bufferSize = stringifiedDataSize;
_buffer = [stringifiedData];
_isTimedOut = false;
}
else {
_bufferSize += stringifiedDataSize;
_buffer.push(stringifiedData);
}
}
catch (err) {
// Never stop this process.
console.error('wonlog-agent error, reason: ', err);
console.error('wonlog-agent error, original log: ', str);
}
});
process.stdin.on('end', function () {
clearInterval(timer);
if (_buffer.length > 0) {
axiosInstance
.post('logs', {
data: `[${_buffer.join(',')}]`,
meta: { timestamp: Date.now() },
})
.catch((err) => {
console.error(err.message);
});
}
});
//# sourceMappingURL=index.js.map |
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0213 ]-- |