From 1e2eb28a8dc2fe4cbcd1ffa17fc5f7d778c39d90 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 15 Apr 2022 14:33:53 +0200 Subject: Use builting string pad functions. --- server.js | 14 +++++--------- 1 file 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(); -- cgit v1.2.3