summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2022-04-15 14:33:53 +0200
committerTor Andersson <tor@ccxvii.net>2022-04-15 14:34:52 +0200
commit1e2eb28a8dc2fe4cbcd1ffa17fc5f7d778c39d90 (patch)
treeba344b7e5017f1cde849e7f2beae67b03acafdb4
parent017f4f89ef9af119caf9961e23c66994e8c3ff90 (diff)
downloadserver-1e2eb28a8dc2fe4cbcd1ffa17fc5f7d778c39d90.tar.gz
Use builting string pad functions.
-rw-r--r--server.js14
1 files changed, 5 insertions, 9 deletions
diff --git a/server.js b/server.js
index a514bb0..e7f2bd8 100644
--- a/server.js
+++ b/server.js
@@ -152,14 +152,10 @@ function random_seed() {
return crypto.randomInt(1, 0x7ffffffe);
}
-function pad(s, fmt) {
- return s + fmt.slice(s.length);
-}
-
function SLOG(socket, ...msg) {
let time = new Date().toISOString().substring(11,19);
- let name = pad(socket.user ? socket.user.name : "guest", " ");
- let ip = pad(socket.ip, " ");
+ let name = (socket.user ? socket.user.name : "guest").padEnd(20);
+ let ip = String(socket.ip).padEnd(15);
let ws = "----------";
console.log(time, ip, ws, name, "WS",
socket.title_id,
@@ -336,9 +332,9 @@ app.use(function (req, res, next) {
// Log non-static accesses.
let time = new Date().toISOString().substring(11,19);
- let name = pad(req.user ? req.user.name : "guest", " ");
- let ua = pad(req.user_agent, " ");
- ip = pad(ip, " ");
+ let name = (req.user ? req.user.name : "guest").padEnd(20);
+ let ua = req.user_agent.padEnd(10);
+ ip = String(ip).padEnd(15);
console.log(time, ip, ua, name, req.method, req.url);
return next();