[upd] plankton
This commit is contained in:
parent
75c9f8456c
commit
50d24c9841
3 changed files with 231 additions and 23 deletions
42
lib/plankton/plankton.d.ts
vendored
42
lib/plankton/plankton.d.ts
vendored
|
@ -923,6 +923,16 @@ declare namespace lib_plankton.file {
|
|||
*/
|
||||
function delete_(path: string): Promise<void>;
|
||||
}
|
||||
declare namespace lib_plankton.email {
|
||||
/**
|
||||
*/
|
||||
function send(smtp_credentials: {
|
||||
host: string;
|
||||
port: int;
|
||||
username: string;
|
||||
password: string;
|
||||
}, sender: string, receivers: Array<string>, subject: string, content: string): Promise<void>;
|
||||
}
|
||||
declare namespace lib_plankton.log {
|
||||
/**
|
||||
*/
|
||||
|
@ -996,10 +1006,40 @@ declare namespace lib_plankton.log {
|
|||
* the path of the log file
|
||||
*/
|
||||
private path;
|
||||
/**
|
||||
*/
|
||||
private human_readable;
|
||||
/**
|
||||
* [constructor]
|
||||
*/
|
||||
constructor(path: string);
|
||||
constructor(path: string, human_readable: boolean);
|
||||
/**
|
||||
*/
|
||||
add(entry: type_entry): void;
|
||||
}
|
||||
}
|
||||
declare namespace lib_plankton.log {
|
||||
/**
|
||||
*/
|
||||
class class_channel_email extends class_channel {
|
||||
/**
|
||||
*/
|
||||
private smtp_credentials;
|
||||
/**
|
||||
*/
|
||||
private sender;
|
||||
/**
|
||||
*/
|
||||
private receivers;
|
||||
/**
|
||||
* [constructor]
|
||||
*/
|
||||
constructor(smtp_credentials: {
|
||||
host: string;
|
||||
port: int;
|
||||
username: string;
|
||||
password: string;
|
||||
}, sender: string, receivers: Array<string>);
|
||||
/**
|
||||
*/
|
||||
add(entry: type_entry): void;
|
||||
|
|
|
@ -2173,6 +2173,100 @@ var lib_plankton;
|
|||
file.delete_ = delete_;
|
||||
})(file = lib_plankton.file || (lib_plankton.file = {}));
|
||||
})(lib_plankton || (lib_plankton = {}));
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
/*
|
||||
This file is part of »bacterio-plankton:email«.
|
||||
|
||||
Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||
<info@greenscale.de>
|
||||
|
||||
»bacterio-plankton:email« is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
»bacterio-plankton:lang« is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with »bacterio-plankton:email«. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
var lib_plankton;
|
||||
(function (lib_plankton) {
|
||||
var email;
|
||||
(function (email) {
|
||||
/**
|
||||
*/
|
||||
function send(smtp_credentials, sender, receivers, subject, content) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var nm_nodemailer, transporter, info;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
nm_nodemailer = require("nodemailer");
|
||||
transporter = nm_nodemailer.createTransport({
|
||||
"host": smtp_credentials.host,
|
||||
"port": smtp_credentials.port,
|
||||
"secure": false,
|
||||
"auth": {
|
||||
"user": smtp_credentials.username,
|
||||
"pass": smtp_credentials.password
|
||||
},
|
||||
"debug": true
|
||||
});
|
||||
return [4 /*yield*/, transporter.sendMail({
|
||||
"from": sender,
|
||||
"to": receivers.join(", "),
|
||||
"subject": subject,
|
||||
"text": content
|
||||
})];
|
||||
case 1:
|
||||
info = _a.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
email.send = send;
|
||||
})(email = lib_plankton.email || (lib_plankton.email = {}));
|
||||
})(lib_plankton || (lib_plankton = {}));
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
|
@ -2445,9 +2539,10 @@ var lib_plankton;
|
|||
/**
|
||||
* [constructor]
|
||||
*/
|
||||
function class_channel_file(path) {
|
||||
function class_channel_file(path, human_readable) {
|
||||
var _this = _super.call(this) || this;
|
||||
_this.path = path;
|
||||
_this.human_readable = human_readable;
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
|
@ -2455,24 +2550,40 @@ var lib_plankton;
|
|||
class_channel_file.prototype.add = function (entry) {
|
||||
var _this = this;
|
||||
var nm_fs = require("fs");
|
||||
nm_fs.writeFile(this.path, {
|
||||
var line = (this.human_readable
|
||||
? (("<" + (new Date(Date.now())).toISOString().slice(0, 19) + ">")
|
||||
+
|
||||
" "
|
||||
+
|
||||
("[" + log.level_show(entry.level) + "]")
|
||||
+
|
||||
" "
|
||||
+
|
||||
("" + entry.incident + "")
|
||||
+
|
||||
": "
|
||||
+
|
||||
JSON.stringify(entry.details, undefined, " ")
|
||||
+
|
||||
"\n")
|
||||
: (JSON.stringify({
|
||||
"timestamp": lib_plankton.base.get_current_timestamp(),
|
||||
"level_number": entry.level,
|
||||
"level_name": log.level_show(entry.level),
|
||||
"incident": entry.incident,
|
||||
"details": entry.details
|
||||
})
|
||||
+
|
||||
"\n"));
|
||||
nm_fs.writeFile(this.path, line, {
|
||||
"flag": "a+"
|
||||
}, (("<" + (new Date(Date.now())).toISOString().slice(0, 19) + ">")
|
||||
+
|
||||
" "
|
||||
+
|
||||
("[" + log.level_show(entry.level) + "]")
|
||||
+
|
||||
" "
|
||||
+
|
||||
("" + entry.incident + "")
|
||||
+
|
||||
": "
|
||||
+
|
||||
JSON.stringify(entry.details, undefined, " ")
|
||||
+
|
||||
"\n"), function (error) {
|
||||
process.stderr.write('-- [plankton] could not add log entry to file ' + _this.path + "\n");
|
||||
}, function (error) {
|
||||
if (error !== null) {
|
||||
process.stderr.write('-- [plankton] could not add log entry to file ' + _this.path + "\n");
|
||||
}
|
||||
else {
|
||||
// do nothing
|
||||
}
|
||||
});
|
||||
};
|
||||
return class_channel_file;
|
||||
|
@ -2496,6 +2607,58 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with »bacterio-plankton:log«. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
var lib_plankton;
|
||||
(function (lib_plankton) {
|
||||
var log;
|
||||
(function (log) {
|
||||
/**
|
||||
*/
|
||||
var class_channel_email = /** @class */ (function (_super) {
|
||||
__extends(class_channel_email, _super);
|
||||
/**
|
||||
* [constructor]
|
||||
*/
|
||||
function class_channel_email(smtp_credentials, sender, receivers) {
|
||||
var _this = _super.call(this) || this;
|
||||
_this.smtp_credentials = smtp_credentials;
|
||||
_this.sender = sender;
|
||||
_this.receivers = receivers;
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class_channel_email.prototype.add = function (entry) {
|
||||
var nm_fs = require("fs");
|
||||
lib_plankton.email.send(this.smtp_credentials, this.sender, this.receivers, (("[" + log.level_show(entry.level) + "]")
|
||||
+
|
||||
" "
|
||||
+
|
||||
("" + entry.incident + "")), JSON.stringify(entry.details, undefined, " "));
|
||||
};
|
||||
return class_channel_email;
|
||||
}(log.class_channel));
|
||||
log.class_channel_email = class_channel_email;
|
||||
})(log = lib_plankton.log || (lib_plankton.log = {}));
|
||||
})(lib_plankton || (lib_plankton = {}));
|
||||
/*
|
||||
This file is part of »bacterio-plankton:log«.
|
||||
|
||||
Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||
<info@greenscale.de>
|
||||
|
||||
»bacterio-plankton:log« is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
»bacterio-plankton:lang« is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with »bacterio-plankton:log«. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
@ -2635,7 +2798,7 @@ var lib_plankton;
|
|||
/**
|
||||
*/
|
||||
function channel_make(description) {
|
||||
var _a, _b, _c, _d;
|
||||
var _a, _b, _c, _d, _e;
|
||||
switch (description.kind) {
|
||||
default: {
|
||||
throw (new Error("unhandled log channel kind: " + description.kind));
|
||||
|
@ -2646,11 +2809,15 @@ var lib_plankton;
|
|||
break;
|
||||
}
|
||||
case "file": {
|
||||
return (new log.class_channel_minlevel(new log.class_channel_file((_b = description.data["path"]) !== null && _b !== void 0 ? _b : "/tmp/plankton.log"), translate_level((_c = description.data["threshold"]) !== null && _c !== void 0 ? _c : "debug")));
|
||||
return (new log.class_channel_minlevel(new log.class_channel_file(((_b = description.data["path"]) !== null && _b !== void 0 ? _b : "/tmp/plankton.log"), false), translate_level((_c = description.data["threshold"]) !== null && _c !== void 0 ? _c : "debug")));
|
||||
break;
|
||||
}
|
||||
case "email": {
|
||||
return (new log.class_channel_minlevel(new log.class_channel_email(description.data["smtp_credentials"], description.data["sender"], description.data["receivers"]), translate_level((_d = description.data["threshold"]) !== null && _d !== void 0 ? _d : "debug")));
|
||||
break;
|
||||
}
|
||||
case "notify": {
|
||||
return (new log.class_channel_minlevel(new log.class_channel_notify(), translate_level((_d = description.data["threshold"]) !== null && _d !== void 0 ? _d : "debug")));
|
||||
return (new log.class_channel_minlevel(new log.class_channel_notify(), translate_level((_e = description.data["threshold"]) !== null && _e !== void 0 ? _e : "debug")));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -10453,7 +10620,7 @@ var lib_plankton;
|
|||
// "input_shape": options.input_type,
|
||||
// "output_shape": options.output_type,
|
||||
});
|
||||
lib_plankton.log.info("rest_route_added", {
|
||||
lib_plankton.log.debug("rest_route_added", {
|
||||
"http_method": http_method,
|
||||
"path": path,
|
||||
// "routetree": rest.routetree,
|
||||
|
|
|
@ -19,6 +19,7 @@ modules="${modules} api"
|
|||
modules="${modules} rest"
|
||||
modules="${modules} http"
|
||||
modules="${modules} server"
|
||||
modules="${modules} email"
|
||||
modules="${modules} args"
|
||||
modules="${modules} translate"
|
||||
modules="${modules} log"
|
||||
|
|
Loading…
Add table
Reference in a new issue