Merge pull request #2506 from thelounge/xpaw/rm-logs-format

Remove ability to change date format and timezone
This commit is contained in:
Pavel Djundik 2018-06-05 14:55:44 +03:00 committed by GitHub
commit 3248f0db1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 39 deletions

View File

@ -161,33 +161,6 @@ module.exports = {
// //
messageStorage: ["sqlite", "text"], messageStorage: ["sqlite", "text"],
//
// Log settings
//
// Logging has to be enabled per user. If enabled, logs will be stored in
// the 'logs/<user>/<network>/' folder.
//
// @type object
// @default {}
//
logs: {
//
// Timestamp format
//
// @type string
// @default "YYYY-MM-DD HH:mm:ss"
//
format: "YYYY-MM-DD HH:mm:ss",
//
// Timezone
//
// @type string
// @default "UTC+00:00"
//
timezone: "UTC+00:00",
},
// //
// Maximum number of history lines per channel // Maximum number of history lines per channel
// //

View File

@ -8,6 +8,7 @@ const fs = require("fs");
const net = require("net"); const net = require("net");
const bcrypt = require("bcryptjs"); const bcrypt = require("bcryptjs");
const colors = require("chalk"); const colors = require("chalk");
const moment = require("moment");
let homePath; let homePath;
let configPath; let configPath;
@ -30,6 +31,7 @@ const Helper = {
setHome, setHome,
getVersion, getVersion,
getGitCommit, getGitCommit,
getHumanDate,
ip2hex, ip2hex,
mergeConfig, mergeConfig,
getDefaultNick, getDefaultNick,
@ -205,6 +207,10 @@ function passwordCompare(password, expected) {
return bcrypt.compare(password, expected); return bcrypt.compare(password, expected);
} }
function getHumanDate() {
return moment().format("YYYY-MM-DD HH:mm:ss");
}
function getDefaultNick() { function getDefaultNick() {
if (!this.config.defaults.nick) { if (!this.config.defaults.nick) {
return "thelounge"; return "thelounge";

View File

@ -1,16 +1,11 @@
"use strict"; "use strict";
const colors = require("chalk"); const colors = require("chalk");
const moment = require("moment");
const read = require("read"); const read = require("read");
const Helper = require("./helper"); const Helper = require("./helper");
function timestamp() { function timestamp() {
const format = Helper.config.logs.format || "YYYY-MM-DD HH:mm:ss"; return colors.dim(Helper.getHumanDate());
const tz = Helper.config.logs.timezone || "UTC+00:00";
const time = moment().utcOffset(tz).format(format);
return colors.dim(time);
} }
module.exports = { module.exports = {

View File

@ -3,7 +3,6 @@
const fs = require("fs"); const fs = require("fs");
const fsextra = require("fs-extra"); const fsextra = require("fs-extra");
const path = require("path"); const path = require("path");
const moment = require("moment");
const filenamify = require("filenamify"); const filenamify = require("filenamify");
const Helper = require("../../helper"); const Helper = require("../../helper");
@ -40,11 +39,7 @@ class TextFileMessageStorage {
return; return;
} }
const format = Helper.config.logs.format || "YYYY-MM-DD HH:mm:ss"; let line = `[${Helper.getHumanDate()}] `;
const tz = Helper.config.logs.timezone || "UTC+00:00";
const time = moment(msg.time).utcOffset(tz).format(format);
let line = `[${time}] `;
if (msg.type === "message") { if (msg.type === "message") {
// Format: // Format:

View File

@ -2,6 +2,7 @@
const expect = require("chai").expect; const expect = require("chai").expect;
const os = require("os"); const os = require("os");
const moment = require("moment");
const Helper = require("../../src/helper"); const Helper = require("../../src/helper");
describe("Helper", function() { describe("Helper", function() {
@ -52,4 +53,8 @@ describe("Helper", function() {
expect(version).to.match(/v[0-9]+\.[0-9]+\.[0-9]+/); expect(version).to.match(/v[0-9]+\.[0-9]+\.[0-9]+/);
}); });
}); });
describe("#getHumanDate()", function() {
expect(Helper.getHumanDate()).to.equal(moment().format("YYYY-MM-DD HH:mm:ss"));
});
}); });