Refactor logging

This commit is contained in:
Calvin Montgomery 2017-04-04 23:02:31 -07:00
parent b1a328d2e0
commit 8306d2d1b6
29 changed files with 268 additions and 194 deletions

View File

@ -6,6 +6,7 @@ if (/^v0/.test(process.version)) {
} }
try { try {
require("./lib/logger");
var Server = require("./lib/server"); var Server = require("./lib/server");
} catch (err) { } catch (err) {
console.error('FATAL: Failed to require() lib/server.js'); console.error('FATAL: Failed to require() lib/server.js');

View File

@ -2,12 +2,13 @@
"author": "Calvin Montgomery", "author": "Calvin Montgomery",
"name": "CyTube", "name": "CyTube",
"description": "Online media synchronizer and chat", "description": "Online media synchronizer and chat",
"version": "3.34.10", "version": "3.35.0",
"repository": { "repository": {
"url": "http://github.com/calzoneman/sync" "url": "http://github.com/calzoneman/sync"
}, },
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@calzoneman/jsli": "^1.0.1",
"babel-cli": "^6.1.4", "babel-cli": "^6.1.4",
"babel-core": "^6.1.4", "babel-core": "^6.1.4",
"babel-plugin-add-module-exports": "^0.2.1", "babel-plugin-add-module-exports": "^0.2.1",
@ -43,6 +44,7 @@
"socket.io": "^1.4.0", "socket.io": "^1.4.0",
"socket.io-redis": "^1.0.0", "socket.io-redis": "^1.0.0",
"source-map-support": "^0.4.0", "source-map-support": "^0.4.0",
"sprintf-js": "^1.0.3",
"status-message-polyfill": "git://github.com/calzoneman/status-message-polyfill", "status-message-polyfill": "git://github.com/calzoneman/status-message-polyfill",
"toml": "^2.3.0", "toml": "^2.3.0",
"uuid": "^2.0.1", "uuid": "^2.0.1",
@ -51,6 +53,7 @@
"scripts": { "scripts": {
"build-player": "$npm_node_execpath build-player.js", "build-player": "$npm_node_execpath build-player.js",
"build-server": "babel -D --source-maps --loose es6.destructuring,es6.forOf --out-dir lib/ src/", "build-server": "babel -D --source-maps --loose es6.destructuring,es6.forOf --out-dir lib/ src/",
"flow": "flow",
"postinstall": "./postinstall.sh", "postinstall": "./postinstall.sh",
"server-dev": "babel -D --watch --source-maps --loose es6.destructuring,es6.forOf --out-dir lib/ src/", "server-dev": "babel -D --watch --source-maps --loose es6.destructuring,es6.forOf --out-dir lib/ src/",
"generate-userscript": "$npm_node_execpath gdrive-userscript/generate-userscript $@ > www/js/cytube-google-drive.user.js", "generate-userscript": "$npm_node_execpath gdrive-userscript/generate-userscript $@ > www/js/cytube-google-drive.user.js",
@ -58,7 +61,9 @@
"integration-test": "mocha --recursive integration_test" "integration-test": "mocha --recursive integration_test"
}, },
"devDependencies": { "devDependencies": {
"babel-plugin-transform-flow-strip-types": "^6.22.0",
"coffee-script": "^1.9.2", "coffee-script": "^1.9.2",
"flow-bin": "^0.43.0",
"mocha": "^3.2.0" "mocha": "^3.2.0"
}, },
"babel": { "babel": {
@ -72,7 +77,8 @@
"loose": true "loose": true
} }
], ],
"add-module-exports" "add-module-exports",
"transform-flow-strip-types"
] ]
} }
} }

View File

@ -5,10 +5,12 @@
running. running.
*/ */
var Logger = require("./logger");
var Config = require("./config"); var Config = require("./config");
var db = require("./database"); var db = require("./database");
var Promise = require("bluebird"); var Promise = require("bluebird");
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('bgtask');
var init = null; var init = null;
@ -39,9 +41,9 @@ function initAliasCleanup(Server) {
setInterval(function () { setInterval(function () {
db.cleanOldAliases(CLEAN_EXPIRE, function (err) { db.cleanOldAliases(CLEAN_EXPIRE, function (err) {
Logger.syslog.log("Cleaned old aliases"); LOGGER.info("Cleaned old aliases");
if (err) if (err)
Logger.errlog.log(err); LOGGER.error(err);
}); });
}, CLEAN_INTERVAL); }, CLEAN_INTERVAL);
} }
@ -53,7 +55,7 @@ function initPasswordResetCleanup(Server) {
setInterval(function () { setInterval(function () {
db.cleanOldPasswordResets(function (err) { db.cleanOldPasswordResets(function (err) {
if (err) if (err)
Logger.errlog.log(err); LOGGER.error(err);
}); });
}, CLEAN_INTERVAL); }, CLEAN_INTERVAL);
} }
@ -63,28 +65,28 @@ function initChannelDumper(Server) {
* 60000; * 60000;
setInterval(function () { setInterval(function () {
var wait = CHANNEL_SAVE_INTERVAL / Server.channels.length; var wait = CHANNEL_SAVE_INTERVAL / Server.channels.length;
Logger.syslog.log(`Saving channels with delay ${wait}`); LOGGER.info(`Saving channels with delay ${wait}`);
Promise.reduce(Server.channels, (_, chan) => { Promise.reduce(Server.channels, (_, chan) => {
return Promise.delay(wait).then(() => { return Promise.delay(wait).then(() => {
if (!chan.dead && chan.users && chan.users.length > 0) { if (!chan.dead && chan.users && chan.users.length > 0) {
return chan.saveState().tap(() => { return chan.saveState().tap(() => {
Logger.syslog.log(`Saved /r/${chan.name}`); LOGGER.info(`Saved /r/${chan.name}`);
}).catch(err => { }).catch(err => {
Logger.errlog.log(`Failed to save /r/${chan.name}: ${err.stack}`); LOGGER.error(`Failed to save /r/${chan.name}: ${err.stack}`);
}); });
} }
}).catch(error => { }).catch(error => {
Logger.errlog.log(`Failed to save channel: ${error.stack}`); LOGGER.error(`Failed to save channel: ${error.stack}`);
}); });
}, 0).catch(error => { }, 0).catch(error => {
Logger.errlog.log(`Failed to save channels: ${error.stack}`); LOGGER.error(`Failed to save channels: ${error.stack}`);
}); });
}, CHANNEL_SAVE_INTERVAL); }, CHANNEL_SAVE_INTERVAL);
} }
module.exports = function (Server) { module.exports = function (Server) {
if (init === Server) { if (init === Server) {
Logger.errlog.log("WARNING: Attempted to re-init background tasks"); LOGGER.warn("Attempted to re-init background tasks");
return; return;
} }

View File

@ -3,8 +3,6 @@ import Promise from 'bluebird';
import Config from '../config'; import Config from '../config';
import db from '../database'; import db from '../database';
import { DatabaseStore } from './dbstore'; import { DatabaseStore } from './dbstore';
import { syslog } from '../logger';
syslog.log = () => undefined;
function main() { function main() {
Config.load('config.yaml'); Config.load('config.yaml');

View File

@ -1,11 +1,11 @@
import Promise from 'bluebird'; import Promise from 'bluebird';
import { ChannelStateSizeError, import { ChannelStateSizeError } from '../errors';
ChannelNotFoundError } from '../errors';
import db from '../database'; import db from '../database';
import Logger from '../logger'; import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('dbstore');
const SIZE_LIMIT = 1048576; const SIZE_LIMIT = 1048576;
const QUERY_CHANNEL_ID_FOR_NAME = 'SELECT id FROM channels WHERE name = ?';
const QUERY_CHANNEL_DATA = 'SELECT `key`, `value` FROM channel_data WHERE channel_id = ?'; const QUERY_CHANNEL_DATA = 'SELECT `key`, `value` FROM channel_data WHERE channel_id = ?';
function queryAsync(query, substitutions) { function queryAsync(query, substitutions) {
@ -46,7 +46,7 @@ export class DatabaseStore {
try { try {
data[row.key] = JSON.parse(row.value); data[row.key] = JSON.parse(row.value);
} catch (e) { } catch (e) {
Logger.errlog.log(`Channel data for channel "${channelName}", ` + LOGGER.error(`Channel data for channel "${channelName}", ` +
`key "${row.key}" is invalid: ${e}`); `key "${row.key}" is invalid: ${e}`);
} }
}); });

View File

@ -1,8 +1,5 @@
var Logger = require("../logger");
var ChannelModule = require("./module"); var ChannelModule = require("./module");
var Flags = require("../flags"); var Flags = require("../flags");
var Account = require("../account");
var util = require("../utilities");
var fs = require("graceful-fs"); var fs = require("graceful-fs");
var path = require("path"); var path = require("path");
var sio = require("socket.io"); var sio = require("socket.io");
@ -12,6 +9,10 @@ import { ChannelStateSizeError } from '../errors';
import Promise from 'bluebird'; import Promise from 'bluebird';
import { EventEmitter } from 'events'; import { EventEmitter } from 'events';
import { throttle } from '../util/throttle'; import { throttle } from '../util/throttle';
import Logger from '../logger';
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('channel');
const USERCOUNT_THROTTLE = 10000; const USERCOUNT_THROTTLE = 10000;
@ -43,7 +44,7 @@ class ReferenceCounter {
delete this.references[caller]; delete this.references[caller];
} }
} else { } else {
Logger.errlog.log("ReferenceCounter::unref() called by caller [" + LOGGER.error("ReferenceCounter::unref() called by caller [" +
caller + "] but this caller had no active references! " + caller + "] but this caller had no active references! " +
`(channel: ${this.channelName})`); `(channel: ${this.channelName})`);
} }
@ -56,7 +57,7 @@ class ReferenceCounter {
checkRefCount() { checkRefCount() {
if (this.refCount === 0) { if (this.refCount === 0) {
if (Object.keys(this.references).length > 0) { if (Object.keys(this.references).length > 0) {
Logger.errlog.log("ReferenceCounter::refCount reached 0 but still had " + LOGGER.error("ReferenceCounter::refCount reached 0 but still had " +
"active references: " + "active references: " +
JSON.stringify(Object.keys(this.references)) + JSON.stringify(Object.keys(this.references)) +
` (channel: ${this.channelName})`); ` (channel: ${this.channelName})`);
@ -64,7 +65,7 @@ class ReferenceCounter {
this.refCount += this.references[caller]; this.refCount += this.references[caller];
} }
} else if (this.channel.users.length > 0) { } else if (this.channel.users.length > 0) {
Logger.errlog.log("ReferenceCounter::refCount reached 0 but still had " + LOGGER.error("ReferenceCounter::refCount reached 0 but still had " +
this.channel.users.length + " active users" + this.channel.users.length + " active users" +
` (channel: ${this.channelName})`); ` (channel: ${this.channelName})`);
this.refCount = this.channel.users.length; this.refCount = this.channel.users.length;
@ -208,7 +209,7 @@ Channel.prototype.loadState = function () {
try { try {
this.modules[m].load(data); this.modules[m].load(data);
} catch (e) { } catch (e) {
Logger.errlog.log("Failed to load module " + m + " for channel " + LOGGER.error("Failed to load module " + m + " for channel " +
this.uniqueName); this.uniqueName);
} }
}); });
@ -219,7 +220,7 @@ Channel.prototype.loadState = function () {
"enforced by this server. Please contact an administrator " + "enforced by this server. Please contact an administrator " +
"for assistance."; "for assistance.";
Logger.errlog.log(err.stack); LOGGER.error(err.stack);
errorLoad(message, false); errorLoad(message, false);
}).catch(err => { }).catch(err => {
if (err.code === 'ENOENT') { if (err.code === 'ENOENT') {
@ -233,7 +234,7 @@ Channel.prototype.loadState = function () {
"disk. Please contact an administrator for assistance. " + "disk. Please contact an administrator for assistance. " +
`The error was: ${err}.`; `The error was: ${err}.`;
Logger.errlog.log(err.stack); LOGGER.error(err.stack);
errorLoad(message); errorLoad(message);
} }
}); });
@ -369,7 +370,7 @@ Channel.prototype.acceptUser = function (user) {
user.autoAFK(); user.autoAFK();
user.socket.on("readChanLog", this.handleReadLog.bind(this, user)); user.socket.on("readChanLog", this.handleReadLog.bind(this, user));
Logger.syslog.log(user.realip + " joined " + this.name); LOGGER.info(user.realip + " joined " + this.name);
if (user.socket._isUsingTor) { if (user.socket._isUsingTor) {
if (this.modules.options && this.modules.options.get("torbanned")) { if (this.modules.options && this.modules.options.get("torbanned")) {
user.kick("This channel has banned connections from Tor."); user.kick("This channel has banned connections from Tor.");
@ -420,7 +421,7 @@ Channel.prototype.acceptUser = function (user) {
Channel.prototype.partUser = function (user) { Channel.prototype.partUser = function (user) {
if (!this.logger) { if (!this.logger) {
Logger.errlog.log("partUser called on dead channel"); LOGGER.error("partUser called on dead channel");
return; return;
} }

View File

@ -1,6 +1,8 @@
var FilterList = require("cytubefilters"); var FilterList = require("cytubefilters");
var ChannelModule = require("./module"); var ChannelModule = require("./module");
var Logger = require("../logger"); import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('filters');
/* /*
* Converts JavaScript-style replacements ($1, $2, etc.) with * Converts JavaScript-style replacements ($1, $2, etc.) with
@ -76,7 +78,7 @@ ChatFilterModule.prototype.load = function (data) {
try { try {
this.filters = new FilterList(filters); this.filters = new FilterList(filters);
} catch (e) { } catch (e) {
Logger.errlog.log("Filter load failed: " + e + " (channel:" + LOGGER.error("Filter load failed: " + e + " (channel:" +
this.channel.name); this.channel.name);
this.channel.logger.log("Failed to load filters: " + e); this.channel.logger.log("Failed to load filters: " + e);
} }

View File

@ -2,7 +2,9 @@ var Vimeo = require("cytube-mediaquery/lib/provider/vimeo");
var ChannelModule = require("./module"); var ChannelModule = require("./module");
var Config = require("../config"); var Config = require("../config");
var InfoGetter = require("../get-info"); var InfoGetter = require("../get-info");
var Logger = require("../logger"); import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('mediarefresher');
function MediaRefresherModule(channel) { function MediaRefresherModule(channel) {
ChannelModule.apply(this, arguments); ChannelModule.apply(this, arguments);
@ -55,7 +57,7 @@ MediaRefresherModule.prototype.unload = function () {
clearInterval(this._interval); clearInterval(this._interval);
this._interval = null; this._interval = null;
} catch (error) { } catch (error) {
Logger.errlog.log(error.stack); LOGGER.error(error.stack);
} }
}; };
@ -94,7 +96,7 @@ MediaRefresherModule.prototype.initVimeo = function (data, cb) {
if (cb) cb(); if (cb) cb();
}).catch(function (err) { }).catch(function (err) {
Logger.errlog.log("Unexpected vimeo::extract() fail: " + err.stack); LOGGER.error("Unexpected vimeo::extract() fail: " + err.stack);
if (cb) cb(); if (cb) cb();
}).finally(() => { }).finally(() => {
self.channel.refCounter.unref("MediaRefresherModule::initVimeo"); self.channel.refCounter.unref("MediaRefresherModule::initVimeo");
@ -145,7 +147,7 @@ MediaRefresherModule.prototype.refreshGoogleDocs = function (media, cb) {
if (err) { if (err) {
self.channel.logger.log("[mediarefresher] Google Docs refresh failed: " + self.channel.logger.log("[mediarefresher] Google Docs refresh failed: " +
err); err);
Logger.errlog.log("Google Docs refresh failed for ID " + media.id + LOGGER.error("Google Docs refresh failed for ID " + media.id +
": " + err); ": " + err);
self.channel.refCounter.unref("MediaRefresherModule::refreshGoogleDocs"); self.channel.refCounter.unref("MediaRefresherModule::refreshGoogleDocs");
if (cb) cb(); if (cb) cb();
@ -204,7 +206,7 @@ MediaRefresherModule.prototype.initGooglePlus = function (media, cb) {
if (err) { if (err) {
self.channel.logger.log("[mediarefresher] Google+ refresh failed: " + self.channel.logger.log("[mediarefresher] Google+ refresh failed: " +
err); err);
Logger.errlog.log("Google+ refresh failed for ID " + media.id + LOGGER.error("Google+ refresh failed for ID " + media.id +
": " + err); ": " + err);
self.channel.refCounter.unref("MediaRefresherModule::initGooglePlus"); self.channel.refCounter.unref("MediaRefresherModule::initGooglePlus");
if (cb) cb(); if (cb) cb();

View File

@ -6,9 +6,11 @@ var InfoGetter = require("../get-info");
var Config = require("../config"); var Config = require("../config");
var Flags = require("../flags"); var Flags = require("../flags");
var db = require("../database"); var db = require("../database");
var Logger = require("../logger");
var CustomEmbedFilter = require("../customembed").filter; var CustomEmbedFilter = require("../customembed").filter;
var XSS = require("../xss"); var XSS = require("../xss");
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('playlist');
const MAX_ITEMS = Config.get("playlist.max-items"); const MAX_ITEMS = Config.get("playlist.max-items");
// Limit requestPlaylist to once per 60 seconds // Limit requestPlaylist to once per 60 seconds
@ -928,7 +930,7 @@ PlaylistModule.prototype._addItem = function (media, data, user, cb) {
const limit = this.channel.modules.options.get("playlist_max_duration_per_user"); const limit = this.channel.modules.options.get("playlist_max_duration_per_user");
const totalDuration = usersItems.map(item => item.media.seconds).reduce((a, b) => a + b, 0) + media.seconds; const totalDuration = usersItems.map(item => item.media.seconds).reduce((a, b) => a + b, 0) + media.seconds;
if (isNaN(totalDuration)) { if (isNaN(totalDuration)) {
Logger.errlog.log("playlist_max_duration_per_user check calculated NaN: " + require('util').inspect(usersItems)); LOGGER.error("playlist_max_duration_per_user check calculated NaN: " + require('util').inspect(usersItems));
} else if (totalDuration >= limit && !this.channel.modules.permissions.canExceedMaxDurationPerUser(user)) { } else if (totalDuration >= limit && !this.channel.modules.permissions.canExceedMaxDurationPerUser(user)) {
return qfail("Channel limit exceeded: maximum total playlist time per user"); return qfail("Channel limit exceeded: maximum total playlist time per user");
} }
@ -1356,9 +1358,9 @@ PlaylistModule.prototype.handleQueuePlaylist = function (user, data) {
self._addItem(m, qdata, user); self._addItem(m, qdata, user);
}); });
} catch (e) { } catch (e) {
Logger.errlog.log("Loading user playlist failed!"); LOGGER.error("Loading user playlist failed!");
Logger.errlog.log("PL: " + user.getName() + "-" + data.name); LOGGER.error("PL: " + user.getName() + "-" + data.name);
Logger.errlog.log(e.stack); LOGGER.error(e.stack);
user.socket.emit("queueFail", { user.socket.emit("queueFail", {
msg: "Internal error occurred when loading playlist.", msg: "Internal error occurred when loading playlist.",
link: null link: null

View File

@ -1,10 +1,13 @@
var fs = require("fs"); var fs = require("fs");
var path = require("path"); var path = require("path");
var Logger = require("./logger");
var nodemailer = require("nodemailer"); var nodemailer = require("nodemailer");
var net = require("net"); var net = require("net");
var YAML = require("yamljs"); var YAML = require("yamljs");
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('config');
var defaults = { var defaults = {
mysql: { mysql: {
server: "localhost", server: "localhost",
@ -135,7 +138,7 @@ function merge(obj, def, path) {
merge(obj[key], def[key], path + "." + key); merge(obj[key], def[key], path + "." + key);
} }
} else { } else {
Logger.syslog.log("[WARNING] Missing config key " + (path + "." + key) + LOGGER.warn("Missing config key " + (path + "." + key) +
"; using default: " + JSON.stringify(def[key])); "; using default: " + JSON.stringify(def[key]));
obj[key] = def[key]; obj[key] = def[key];
} }
@ -152,14 +155,14 @@ exports.load = function (file) {
cfg = YAML.load(path.join(__dirname, "..", file)); cfg = YAML.load(path.join(__dirname, "..", file));
} catch (e) { } catch (e) {
if (e.code === "ENOENT") { if (e.code === "ENOENT") {
Logger.syslog.log(file + " does not exist, assuming default configuration"); LOGGER.info(file + " does not exist, assuming default configuration");
cfg = defaults; cfg = defaults;
return; return;
} else { } else {
Logger.errlog.log("Error loading config file " + file + ": "); LOGGER.error("Error loading config file " + file + ": ");
Logger.errlog.log(e); LOGGER.error(e);
if (e.stack) { if (e.stack) {
Logger.errlog.log(e.stack); LOGGER.error(e.stack);
} }
cfg = defaults; cfg = defaults;
return; return;
@ -167,7 +170,7 @@ exports.load = function (file) {
} }
if (cfg == null) { if (cfg == null) {
Logger.syslog.log(file + " is an Invalid configuration file, " + LOGGER.info(file + " is an Invalid configuration file, " +
"assuming default configuration"); "assuming default configuration");
cfg = defaults; cfg = defaults;
return; return;
@ -182,13 +185,14 @@ exports.load = function (file) {
cfg.mail.config = mailconfig; cfg.mail.config = mailconfig;
preprocessConfig(cfg); preprocessConfig(cfg);
Logger.syslog.log("Loaded configuration from " + file); LOGGER.info("Loaded configuration from " + file);
}; };
// I'm sorry
function preprocessConfig(cfg) { function preprocessConfig(cfg) {
/* Detect 3.0.0-style config and warng the user about it */ /* Detect 3.0.0-style config and warng the user about it */
if ("host" in cfg.http || "port" in cfg.http || "port" in cfg.https) { if ("host" in cfg.http || "port" in cfg.http || "port" in cfg.https) {
Logger.syslog.log("[WARN] The method of specifying which IP/port to bind has "+ LOGGER.warn("The method of specifying which IP/port to bind has "+
"changed. The config loader will try to handle this "+ "changed. The config loader will try to handle this "+
"automatically, but you should read config.template.yaml "+ "automatically, but you should read config.template.yaml "+
"and change your config.yaml to the new format."); "and change your config.yaml to the new format.");
@ -304,21 +308,21 @@ function preprocessConfig(cfg) {
if (net.isIPv6(srv.ip) || srv.ip === "::") { if (net.isIPv6(srv.ip) || srv.ip === "::") {
if (srv.https && !cfg.io["ipv6-ssl"]) { if (srv.https && !cfg.io["ipv6-ssl"]) {
if (!srv.url) { if (!srv.url) {
Logger.errlog.log("Config Error: no URL defined for IPv6 " + LOGGER.error("Config Error: no URL defined for IPv6 " +
"Socket.IO listener! Ignoring this listener " + "Socket.IO listener! Ignoring this listener " +
"because the Socket.IO client cannot connect to " + "because the Socket.IO client cannot connect to " +
"a raw IPv6 address."); "a raw IPv6 address.");
Logger.errlog.log("(Listener was: " + JSON.stringify(srv) + ")"); LOGGER.error("(Listener was: " + JSON.stringify(srv) + ")");
} else { } else {
cfg.io["ipv6-ssl"] = srv.url; cfg.io["ipv6-ssl"] = srv.url;
} }
} else if (!cfg.io["ipv6-nossl"]) { } else if (!cfg.io["ipv6-nossl"]) {
if (!srv.url) { if (!srv.url) {
Logger.errlog.log("Config Error: no URL defined for IPv6 " + LOGGER.error("Config Error: no URL defined for IPv6 " +
"Socket.IO listener! Ignoring this listener " + "Socket.IO listener! Ignoring this listener " +
"because the Socket.IO client cannot connect to " + "because the Socket.IO client cannot connect to " +
"a raw IPv6 address."); "a raw IPv6 address.");
Logger.errlog.log("(Listener was: " + JSON.stringify(srv) + ")"); LOGGER.error("(Listener was: " + JSON.stringify(srv) + ")");
} else { } else {
cfg.io["ipv6-nossl"] = srv.url; cfg.io["ipv6-nossl"] = srv.url;
} }
@ -372,7 +376,7 @@ function preprocessConfig(cfg) {
require("cytube-mediaquery/lib/provider/youtube").setApiKey( require("cytube-mediaquery/lib/provider/youtube").setApiKey(
cfg["youtube-v3-key"]); cfg["youtube-v3-key"]);
} else { } else {
Logger.errlog.log("Warning: No YouTube v3 API key set. YouTube links will " + LOGGER.warn("No YouTube v3 API key set. YouTube links will " +
"not work. See youtube-v3-key in config.template.yaml and " + "not work. See youtube-v3-key in config.template.yaml and " +
"https://developers.google.com/youtube/registering_an_application for " + "https://developers.google.com/youtube/registering_an_application for " +
"information on registering an API key."); "information on registering an API key.");
@ -382,7 +386,7 @@ function preprocessConfig(cfg) {
require("cytube-mediaquery/lib/provider/twitch-vod").setClientID( require("cytube-mediaquery/lib/provider/twitch-vod").setClientID(
cfg["twitch-client-id"]); cfg["twitch-client-id"]);
} else { } else {
Logger.errlog.log("Warning: No Twitch Client ID set. Twitch VOD links will " + LOGGER.warn("No Twitch Client ID set. Twitch VOD links will " +
"not work. See twitch-client-id in config.template.yaml and " + "not work. See twitch-client-id in config.template.yaml and " +
"https://github.com/justintv/Twitch-API/blob/master/authentication.md#developer-setup" + "https://github.com/justintv/Twitch-API/blob/master/authentication.md#developer-setup" +
"for more information on registering a client ID"); "for more information on registering a client ID");

View File

@ -1,11 +1,10 @@
var Logger = require('./logger');
var path = require('path');
var counterLog = new Logger.Logger(path.resolve(__dirname, '..', 'counters.log'));
import os from 'os';
import io from 'socket.io'; import io from 'socket.io';
import Socket from 'socket.io/lib/socket'; import Socket from 'socket.io/lib/socket';
import * as Metrics from 'cytube-common/lib/metrics/metrics'; import * as Metrics from 'cytube-common/lib/metrics/metrics';
import { JSONFileMetricsReporter } from 'cytube-common/lib/metrics/jsonfilemetricsreporter'; import { JSONFileMetricsReporter } from 'cytube-common/lib/metrics/jsonfilemetricsreporter';
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('counters');
var counters = {}; var counters = {};
var server = null; var server = null;
@ -45,7 +44,7 @@ function setChannelCounts(metrics) {
metrics.addProperty('channelCount:all', allCount); metrics.addProperty('channelCount:all', allCount);
metrics.addProperty('channelCount:public', publicCount); metrics.addProperty('channelCount:public', publicCount);
} catch (error) { } catch (error) {
Logger.errlog.log(error.stack); LOGGER.error(error.stack);
} }
} }

View File

@ -1,12 +1,13 @@
var mysql = require("mysql"); var mysql = require("mysql");
var bcrypt = require("bcrypt"); var bcrypt = require("bcrypt");
var $util = require("./utilities");
var Logger = require("./logger");
var Config = require("./config"); var Config = require("./config");
var tables = require("./database/tables"); var tables = require("./database/tables");
var net = require("net"); var net = require("net");
var util = require("./utilities"); var util = require("./utilities");
import * as Metrics from 'cytube-common/lib/metrics/metrics'; import * as Metrics from 'cytube-common/lib/metrics/metrics';
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('database');
var pool = null; var pool = null;
var global_ipbans = {}; var global_ipbans = {};
@ -26,7 +27,7 @@ module.exports.init = function () {
// Test the connection // Test the connection
pool.getConnection(function (err, conn) { pool.getConnection(function (err, conn) {
if (err) { if (err) {
Logger.errlog.log("Initial database connection failed: " + err.stack); LOGGER.error("Initial database connection failed: " + err.stack);
process.exit(1); process.exit(1);
} else { } else {
tables.init(module.exports.query, function (err) { tables.init(module.exports.query, function (err) {
@ -68,17 +69,17 @@ module.exports.query = function (query, sub, callback) {
pool.getConnection(function (err, conn) { pool.getConnection(function (err, conn) {
if (err) { if (err) {
Logger.errlog.log("! DB connection failed: " + err); LOGGER.error("! DB connection failed: " + err);
callback("Database failure", null); callback("Database failure", null);
} else { } else {
function cback(err, res) { function cback(err, res) {
conn.release(); conn.release();
if (err) { if (err) {
Logger.errlog.log("! DB query failed: " + query); LOGGER.error("! DB query failed: " + query);
if (sub) { if (sub) {
Logger.errlog.log("Substitutions: " + sub); LOGGER.error("Substitutions: " + sub);
} }
Logger.errlog.log(err); LOGGER.error(err);
callback("Database failure", null); callback("Database failure", null);
} else { } else {
callback(null, res); callback(null, res);
@ -97,7 +98,7 @@ module.exports.query = function (query, sub, callback) {
conn.query(query, cback); conn.query(query, cback);
} }
} catch (error) { } catch (error) {
Logger.errlog.log("Broken query: " + error.stack); LOGGER.error("Broken query: " + error.stack);
callback("Broken query", null); callback("Broken query", null);
conn.release(); conn.release();
} }
@ -344,7 +345,7 @@ module.exports.resetUserPassword = function (name, callback) {
bcrypt.hash(pw, 10, function (err, data) { bcrypt.hash(pw, 10, function (err, data) {
if(err) { if(err) {
Logger.errlog.log("bcrypt error: " + err); LOGGER.error("bcrypt error: " + err);
callback("Password reset failure", null); callback("Password reset failure", null);
return; return;
} }
@ -588,7 +589,7 @@ module.exports.loadAnnouncement = function () {
try { try {
announcement = JSON.parse(announcement); announcement = JSON.parse(announcement);
} catch (e) { } catch (e) {
Logger.errlog.log("Invalid announcement data in database: " + LOGGER.error("Invalid announcement data in database: " +
announcement.value); announcement.value);
module.exports.clearAnnouncement(); module.exports.clearAnnouncement();
return; return;

View File

@ -2,7 +2,9 @@ var $util = require("../utilities");
var bcrypt = require("bcrypt"); var bcrypt = require("bcrypt");
var db = require("../database"); var db = require("../database");
var Config = require("../config"); var Config = require("../config");
var Logger = require("../logger"); import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('database/accounts');
var registrationLock = {}; var registrationLock = {};
var blackHole = function () { }; var blackHole = function () { };
@ -450,7 +452,7 @@ module.exports = {
userprof.text = profile.text || ""; userprof.text = profile.text || "";
callback(null, userprof); callback(null, userprof);
} catch (e) { } catch (e) {
Logger.errlog.log("Corrupt profile: " + rows[0].profile + LOGGER.error("Corrupt profile: " + rows[0].profile +
" (user: " + name + ")"); " (user: " + name + ")");
callback(null, userprof); callback(null, userprof);
} }

View File

@ -2,10 +2,12 @@ var db = require("../database");
var valid = require("../utilities").isValidChannelName; var valid = require("../utilities").isValidChannelName;
var fs = require("fs"); var fs = require("fs");
var path = require("path"); var path = require("path");
var Logger = require("../logger");
var tables = require("./tables"); var tables = require("./tables");
var Flags = require("../flags"); var Flags = require("../flags");
var util = require("../utilities"); var util = require("../utilities");
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('database/channels');
var blackHole = function () { }; var blackHole = function () { };
@ -193,27 +195,27 @@ module.exports = {
module.exports.deleteBans(name, function (err) { module.exports.deleteBans(name, function (err) {
if (err) { if (err) {
Logger.errlog.log("Failed to delete bans for " + name + ": " + err); LOGGER.error("Failed to delete bans for " + name + ": " + err);
} }
}); });
module.exports.deleteLibrary(name, function (err) { module.exports.deleteLibrary(name, function (err) {
if (err) { if (err) {
Logger.errlog.log("Failed to delete library for " + name + ": " + err); LOGGER.error("Failed to delete library for " + name + ": " + err);
} }
}); });
module.exports.deleteAllRanks(name, function (err) { module.exports.deleteAllRanks(name, function (err) {
if (err) { if (err) {
Logger.errlog.log("Failed to delete ranks for " + name + ": " + err); LOGGER.error("Failed to delete ranks for " + name + ": " + err);
} }
}); });
fs.unlink(path.join(__dirname, "..", "..", "chandump", name), fs.unlink(path.join(__dirname, "..", "..", "chandump", name),
function (err) { function (err) {
if (err && err.code !== "ENOENT") { if (err && err.code !== "ENOENT") {
Logger.errlog.log("Deleting chandump failed:"); LOGGER.error("Deleting chandump failed:");
Logger.errlog.log(err); LOGGER.error(err);
} }
}); });
@ -654,7 +656,7 @@ module.exports = {
db.query("UPDATE channels SET last_loaded = ? WHERE id = ?", [new Date(), channelId], error => { db.query("UPDATE channels SET last_loaded = ? WHERE id = ?", [new Date(), channelId], error => {
if (error) { if (error) {
Logger.errlog.log(`Failed to update last_loaded column for channel ID ${channelId}: ${error}`); LOGGER.error(`Failed to update last_loaded column for channel ID ${channelId}: ${error}`);
} }
}); });
}, },
@ -669,7 +671,7 @@ module.exports = {
db.query("UPDATE channels SET owner_last_seen = ? WHERE id = ?", [new Date(), channelId], error => { db.query("UPDATE channels SET owner_last_seen = ? WHERE id = ?", [new Date(), channelId], error => {
if (error) { if (error) {
Logger.errlog.log(`Failed to update owner_last_seen column for channel ID ${channelId}: ${error}`); LOGGER.error(`Failed to update owner_last_seen column for channel ID ${channelId}: ${error}`);
} }
}); });
} }

View File

@ -1,7 +1,9 @@
var db = require("../database"); var db = require("../database");
var Logger = require("../logger");
var Q = require("q"); var Q = require("q");
import Promise from 'bluebird'; import Promise from 'bluebird';
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('database/update');
const DB_VERSION = 11; const DB_VERSION = 11;
var hasUpdates = []; var hasUpdates = [];
@ -13,7 +15,7 @@ module.exports.checkVersion = function () {
} }
if (rows.length === 0) { if (rows.length === 0) {
Logger.errlog.log("[Warning] db_version key missing from database. Setting " + LOGGER.warn("db_version key missing from database. Setting " +
"db_version=" + DB_VERSION); "db_version=" + DB_VERSION);
db.query("INSERT INTO `meta` (`key`, `value`) VALUES ('db_version', ?)", db.query("INSERT INTO `meta` (`key`, `value`) VALUES ('db_version', ?)",
[DB_VERSION], [DB_VERSION],
@ -26,7 +28,7 @@ module.exports.checkVersion = function () {
} }
var next = function () { var next = function () {
hasUpdates.push(v); hasUpdates.push(v);
Logger.syslog.log("Updated database to version " + v); LOGGER.info("Updated database to version " + v);
if (v < DB_VERSION) { if (v < DB_VERSION) {
update(v++, next); update(v++, next);
} else { } else {
@ -48,7 +50,7 @@ function update(version, cb) {
Q.nfcall(mergeChannelRanks), Q.nfcall(mergeChannelRanks),
Q.nfcall(mergeChannelBans) Q.nfcall(mergeChannelBans)
]).done(function () { ]).done(function () {
Logger.syslog.log("Merged channel tables. Please verify that everything " + LOGGER.info("Merged channel tables. Please verify that everything " +
"is working correctly, and then type '/delete_old_tables'" + "is working correctly, and then type '/delete_old_tables'" +
" into the CyTube process to remove the unused tables."); " into the CyTube process to remove the unused tables.");
cb(); cb();
@ -71,7 +73,7 @@ function update(version, cb) {
} }
function addMetaColumnToLibraries(cb) { function addMetaColumnToLibraries(cb) {
Logger.syslog.log("[database] db version indicates channel libraries don't have " + LOGGER.info("db version indicates channel libraries don't have " +
"meta column. Updating..."); "meta column. Updating...");
Q.nfcall(db.query, "SHOW TABLES") Q.nfcall(db.query, "SHOW TABLES")
.then(function (rows) { .then(function (rows) {
@ -85,14 +87,14 @@ function addMetaColumnToLibraries(cb) {
rows.forEach(function (table) { rows.forEach(function (table) {
queue.push(Q.nfcall(db.query, "ALTER TABLE `" + table + "` ADD meta TEXT") queue.push(Q.nfcall(db.query, "ALTER TABLE `" + table + "` ADD meta TEXT")
.then(function () { .then(function () {
Logger.syslog.log("Added meta column to " + table); LOGGER.info("Added meta column to " + table);
}) })
); );
}); });
return Q.all(queue); return Q.all(queue);
}).catch(function (err) { }).catch(function (err) {
Logger.errlog.log("Adding meta column to library tables failed: " + err); LOGGER.error("Adding meta column to library tables failed: " + err);
}).done(cb); }).done(cb);
} }
@ -112,12 +114,12 @@ function mergeChannelLibraries(cb) {
"INSERT INTO `channel_libraries` SELECT id, title, seconds, type, meta, ?" + "INSERT INTO `channel_libraries` SELECT id, title, seconds, type, meta, ?" +
" AS channel FROM `" + table + "`", [name]) " AS channel FROM `" + table + "`", [name])
.then(function () { .then(function () {
Logger.syslog.log("Copied " + table + " to channel_libraries"); LOGGER.info("Copied " + table + " to channel_libraries");
}).catch(function (err) { }).catch(function (err) {
Logger.errlog.log("Copying " + table + " to channel_libraries failed: " + LOGGER.error("Copying " + table + " to channel_libraries failed: " +
err); err);
if (err.stack) { if (err.stack) {
Logger.errlog.log(err.stack); LOGGER.error(err.stack);
} }
}) })
); );
@ -125,9 +127,9 @@ function mergeChannelLibraries(cb) {
return Q.all(queue); return Q.all(queue);
}).catch(function (err) { }).catch(function (err) {
Logger.errlog.log("Copying libraries to channel_libraries failed: " + err); LOGGER.error("Copying libraries to channel_libraries failed: " + err);
if (err.stack) { if (err.stack) {
Logger.errlog.log(err.stack); LOGGER.error(err.stack);
} }
}).done(function () { cb(null); }); }).done(function () { cb(null); });
} }
@ -148,12 +150,12 @@ function mergeChannelRanks(cb) {
"INSERT INTO `channel_ranks` SELECT name, rank, ?" + "INSERT INTO `channel_ranks` SELECT name, rank, ?" +
" AS channel FROM `" + table + "`", [name]) " AS channel FROM `" + table + "`", [name])
.then(function () { .then(function () {
Logger.syslog.log("Copied " + table + " to channel_ranks"); LOGGER.info("Copied " + table + " to channel_ranks");
}).catch(function (err) { }).catch(function (err) {
Logger.errlog.log("Copying " + table + " to channel_ranks failed: " + LOGGER.error("Copying " + table + " to channel_ranks failed: " +
err); err);
if (err.stack) { if (err.stack) {
Logger.errlog.log(err.stack); LOGGER.error(err.stack);
} }
}) })
); );
@ -161,9 +163,9 @@ function mergeChannelRanks(cb) {
return Q.all(queue); return Q.all(queue);
}).catch(function (err) { }).catch(function (err) {
Logger.errlog.log("Copying ranks to channel_ranks failed: " + err); LOGGER.error("Copying ranks to channel_ranks failed: " + err);
if (err.stack) { if (err.stack) {
Logger.errlog.log(err.stack); LOGGER.error(err.stack);
} }
}).done(function () { cb(null); }); }).done(function () { cb(null); });
} }
@ -184,12 +186,12 @@ function mergeChannelBans(cb) {
"INSERT INTO `channel_bans` SELECT id, ip, name, bannedby, reason, ?" + "INSERT INTO `channel_bans` SELECT id, ip, name, bannedby, reason, ?" +
" AS channel FROM `" + table + "`", [name]) " AS channel FROM `" + table + "`", [name])
.then(function () { .then(function () {
Logger.syslog.log("Copied " + table + " to channel_bans"); LOGGER.info("Copied " + table + " to channel_bans");
}).catch(function (err) { }).catch(function (err) {
Logger.errlog.log("Copying " + table + " to channel_bans failed: " + LOGGER.error("Copying " + table + " to channel_bans failed: " +
err); err);
if (err.stack) { if (err.stack) {
Logger.errlog.log(err.stack); LOGGER.error(err.stack);
} }
}) })
); );
@ -197,9 +199,9 @@ function mergeChannelBans(cb) {
return Q.all(queue); return Q.all(queue);
}).catch(function (err) { }).catch(function (err) {
Logger.errlog.log("Copying ranks to channel_bans failed: " + err); LOGGER.error("Copying ranks to channel_bans failed: " + err);
if (err.stack) { if (err.stack) {
Logger.errlog.log(err.stack); LOGGER.error(err.stack);
} }
}).done(function () { cb(null); }); }).done(function () { cb(null); });
} }
@ -217,11 +219,11 @@ module.exports.deleteOldChannelTables = function (cb) {
rows.forEach(function (table) { rows.forEach(function (table) {
queue.push(Q.nfcall(db.query, "DROP TABLE `" + table + "`") queue.push(Q.nfcall(db.query, "DROP TABLE `" + table + "`")
.then(function () { .then(function () {
Logger.syslog.log("Deleted " + table); LOGGER.info("Deleted " + table);
}).catch(function (err) { }).catch(function (err) {
Logger.errlog.log("Deleting " + table + " failed: " + err); LOGGER.error("Deleting " + table + " failed: " + err);
if (err.stack) { if (err.stack) {
Logger.errlog.log(err.stack); LOGGER.error(err.stack);
} }
}) })
); );
@ -229,9 +231,9 @@ module.exports.deleteOldChannelTables = function (cb) {
return Q.all(queue); return Q.all(queue);
}).catch(function (err) { }).catch(function (err) {
Logger.errlog.log("Deleting old tables failed: " + err); LOGGER.error("Deleting old tables failed: " + err);
if (err.stack) { if (err.stack) {
Logger.errlog.log(err.stack); LOGGER.error(err.stack);
} }
}).done(cb); }).done(cb);
}; };
@ -247,10 +249,10 @@ function fixUtf8mb4(cb) {
Q.allSettled(queries.map(function (query) { Q.allSettled(queries.map(function (query) {
return Q.nfcall(db.query, query); return Q.nfcall(db.query, query);
})).then(function () { })).then(function () {
Logger.syslog.log("Fixed utf8mb4"); LOGGER.info("Fixed utf8mb4");
cb(); cb();
}).catch(function (e) { }).catch(function (e) {
Logger.errlog.log("Failed to fix utf8mb4: " + e); LOGGER.error("Failed to fix utf8mb4: " + e);
}); });
}; };
@ -276,7 +278,7 @@ function fixCustomEmbeds(cb) {
}); });
Q.allSettled(all).then(function () { Q.allSettled(all).then(function () {
Logger.syslog.log("Converted custom embeds."); LOGGER.info("Converted custom embeds.");
cb(); cb();
}); });
}); });
@ -312,7 +314,7 @@ function fixCustomEmbedsInUserPlaylists(cb) {
try { try {
media = CustomEmbedFilter(item.id); media = CustomEmbedFilter(item.id);
} catch (e) { } catch (e) {
Logger.syslog.log("WARNING: Unable to convert " + item.id); LOGGER.info("WARNING: Unable to convert " + item.id);
continue; continue;
} }
@ -332,19 +334,19 @@ function fixCustomEmbedsInUserPlaylists(cb) {
}); });
Q.allSettled(all).then(function () { Q.allSettled(all).then(function () {
Logger.syslog.log('Fixed custom embeds in user_playlists'); LOGGER.info('Fixed custom embeds in user_playlists');
cb(); cb();
}); });
}).catch(function (err) { }).catch(function (err) {
Logger.errlog.log(err.stack); LOGGER.error(err.stack);
}); });
} }
function addUsernameDedupeColumn(cb) { function addUsernameDedupeColumn(cb) {
Logger.syslog.log("Adding name_dedupe column on the users table"); LOGGER.info("Adding name_dedupe column on the users table");
db.query("ALTER TABLE users ADD COLUMN name_dedupe VARCHAR(20) UNIQUE DEFAULT NULL", (error) => { db.query("ALTER TABLE users ADD COLUMN name_dedupe VARCHAR(20) UNIQUE DEFAULT NULL", (error) => {
if (error) { if (error) {
Logger.errlog.log(`Unable to add name_dedupe column: ${error}`); LOGGER.error(`Unable to add name_dedupe column: ${error}`);
} else { } else {
cb(); cb();
} }
@ -353,10 +355,10 @@ function addUsernameDedupeColumn(cb) {
function populateUsernameDedupeColumn(cb) { function populateUsernameDedupeColumn(cb) {
const dbUsers = require("./accounts"); const dbUsers = require("./accounts");
Logger.syslog.log("Populating name_dedupe column on the users table"); LOGGER.info("Populating name_dedupe column on the users table");
db.query("SELECT id, name FROM users WHERE name_dedupe IS NULL", (err, rows) => { db.query("SELECT id, name FROM users WHERE name_dedupe IS NULL", (err, rows) => {
if (err) { if (err) {
Logger.errlog.log("Unable to perform database upgrade to add dedupe column: " + err); LOGGER.error("Unable to perform database upgrade to add dedupe column: " + err);
return; return;
} }
@ -369,12 +371,12 @@ function populateUsernameDedupeColumn(cb) {
} }
const dedupedName = dbUsers.dedupeUsername(row.name); const dedupedName = dbUsers.dedupeUsername(row.name);
Logger.syslog.log(`Deduping [${row.name}] as [${dedupedName}]`); LOGGER.info(`Deduping [${row.name}] as [${dedupedName}]`);
conn.query("UPDATE users SET name_dedupe = ? WHERE id = ?", [dedupedName, row.id], (error, res) => { conn.query("UPDATE users SET name_dedupe = ? WHERE id = ?", [dedupedName, row.id], (error, res) => {
conn.release(); conn.release();
if (error) { if (error) {
if (error.errno === 1062) { if (error.errno === 1062) {
Logger.syslog.log(`WARNING: could not set name_dedupe for [${row.name}] due to an existing row for [${dedupedName}]`); LOGGER.info(`WARNING: could not set name_dedupe for [${row.name}] due to an existing row for [${dedupedName}]`);
resolve(); resolve();
} else { } else {
reject(error); reject(error);
@ -388,7 +390,7 @@ function populateUsernameDedupeColumn(cb) {
}, { concurrency: 10 }).then(() => { }, { concurrency: 10 }).then(() => {
cb(); cb();
}).catch(error => { }).catch(error => {
Logger.errlog.log("Unable to perform database upgrade to add dedupe column: " + (error.stack ? error.stack : error)); LOGGER.error("Unable to perform database upgrade to add dedupe column: " + (error.stack ? error.stack : error));
}) })
}); });
} }
@ -396,13 +398,13 @@ function populateUsernameDedupeColumn(cb) {
function addChannelLastLoadedColumn(cb) { function addChannelLastLoadedColumn(cb) {
db.query("ALTER TABLE channels ADD COLUMN last_loaded TIMESTAMP NOT NULL DEFAULT 0", error => { db.query("ALTER TABLE channels ADD COLUMN last_loaded TIMESTAMP NOT NULL DEFAULT 0", error => {
if (error) { if (error) {
Logger.errlog.log(`Failed to add last_loaded column: ${error}`); LOGGER.error(`Failed to add last_loaded column: ${error}`);
return; return;
} }
db.query("ALTER TABLE channels ADD INDEX i_last_loaded (last_loaded)", error => { db.query("ALTER TABLE channels ADD INDEX i_last_loaded (last_loaded)", error => {
if (error) { if (error) {
Logger.errlog.log(`Failed to add index on last_loaded column: ${error}`); LOGGER.error(`Failed to add index on last_loaded column: ${error}`);
return; return;
} }
@ -414,13 +416,13 @@ function addChannelLastLoadedColumn(cb) {
function addChannelOwnerLastSeenColumn(cb) { function addChannelOwnerLastSeenColumn(cb) {
db.query("ALTER TABLE channels ADD COLUMN owner_last_seen TIMESTAMP NOT NULL DEFAULT 0", error => { db.query("ALTER TABLE channels ADD COLUMN owner_last_seen TIMESTAMP NOT NULL DEFAULT 0", error => {
if (error) { if (error) {
Logger.errlog.log(`Failed to add owner_last_seen column: ${error}`); LOGGER.error(`Failed to add owner_last_seen column: ${error}`);
return; return;
} }
db.query("ALTER TABLE channels ADD INDEX i_owner_last_seen (owner_last_seen)", error => { db.query("ALTER TABLE channels ADD INDEX i_owner_last_seen (owner_last_seen)", error => {
if (error) { if (error) {
Logger.errlog.log(`Failed to add index on owner_last_seen column: ${error}`); LOGGER.error(`Failed to add index on owner_last_seen column: ${error}`);
return; return;
} }

View File

@ -6,6 +6,9 @@ var http = require("http");
var urlparse = require("url"); var urlparse = require("url");
var path = require("path"); var path = require("path");
require("status-message-polyfill"); require("status-message-polyfill");
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('ffmpeg');
var USE_JSON = true; var USE_JSON = true;
var TIMEOUT = 30000; var TIMEOUT = 30000;
@ -244,7 +247,7 @@ exports.ffprobe = function ffprobe(filename, cb) {
var stdout = ""; var stdout = "";
var stderr = ""; var stderr = "";
var timer = setTimeout(function () { var timer = setTimeout(function () {
Logger.errlog.log("Possible runaway ffprobe process for file " + filename); LOGGER.error("Possible runaway ffprobe process for file " + filename);
fflog("Killing ffprobe for " + filename + " after " + (TIMEOUT/1000) + " seconds"); fflog("Killing ffprobe for " + filename + " after " + (TIMEOUT/1000) + " seconds");
childErr = new Error("File query exceeded time limit of " + (TIMEOUT/1000) + childErr = new Error("File query exceeded time limit of " + (TIMEOUT/1000) +
" seconds. To avoid this issue, encode your videos " + " seconds. To avoid this issue, encode your videos " +
@ -277,7 +280,7 @@ exports.ffprobe = function ffprobe(filename, cb) {
fflog("ffprobe exited with code " + code + " for file " + filename); fflog("ffprobe exited with code " + code + " for file " + filename);
if (code !== 0) { if (code !== 0) {
if (stderr.match(/unrecognized option|json/i) && USE_JSON) { if (stderr.match(/unrecognized option|json/i) && USE_JSON) {
Logger.errlog.log("Warning: ffprobe does not support -of json. " + LOGGER.warn("ffprobe does not support -of json. " +
"Assuming it will have old output format."); "Assuming it will have old output format.");
USE_JSON = false; USE_JSON = false;
return ffprobe(filename, cb); return ffprobe(filename, cb);
@ -346,13 +349,13 @@ exports.query = function (filename, cb) {
// Ignore ffprobe error messages, they are common and most often // Ignore ffprobe error messages, they are common and most often
// indicate a problem with the remote file, not with this code. // indicate a problem with the remote file, not with this code.
if (!/(av|ff)probe/.test(String(err))) if (!/(av|ff)probe/.test(String(err)))
Logger.errlog.log(err.stack || err); LOGGER.error(err.stack || err);
return cb("An unexpected error occurred while trying to process " + return cb("An unexpected error occurred while trying to process " +
"the link. Contact support for troubleshooting " + "the link. Contact support for troubleshooting " +
"assistance."); "assistance.");
} else { } else {
if (!/(av|ff)probe/.test(String(err))) if (!/(av|ff)probe/.test(String(err)))
Logger.errlog.log(err.stack || err); LOGGER.error(err.stack || err);
return cb("An unexpected error occurred while trying to process " + return cb("An unexpected error occurred while trying to process " +
"the link. Contact support for troubleshooting " + "the link. Contact support for troubleshooting " +
"assistance."); "assistance.");
@ -362,7 +365,7 @@ exports.query = function (filename, cb) {
try { try {
data = reformatData(data); data = reformatData(data);
} catch (e) { } catch (e) {
Logger.errlog.log(e.stack || e); LOGGER.error(e.stack || e);
return cb("An unexpected error occurred while trying to process " + return cb("An unexpected error occurred while trying to process " +
"the link. Contact support for troubleshooting " + "the link. Contact support for troubleshooting " +
"assistance."); "assistance.");

View File

@ -1,10 +1,8 @@
var http = require("http"); var http = require("http");
var https = require("https"); var https = require("https");
var cheerio = require('cheerio'); var cheerio = require('cheerio');
var Logger = require("./logger.js");
var Media = require("./media"); var Media = require("./media");
var CustomEmbedFilter = require("./customembed").filter; var CustomEmbedFilter = require("./customembed").filter;
var Server = require("./server");
var Config = require("./config"); var Config = require("./config");
var ffmpeg = require("./ffmpeg"); var ffmpeg = require("./ffmpeg");
var mediaquery = require("cytube-mediaquery"); var mediaquery = require("cytube-mediaquery");
@ -14,6 +12,9 @@ var Vidme = require("cytube-mediaquery/lib/provider/vidme");
var Streamable = require("cytube-mediaquery/lib/provider/streamable"); var Streamable = require("cytube-mediaquery/lib/provider/streamable");
var GoogleDrive = require("cytube-mediaquery/lib/provider/googledrive"); var GoogleDrive = require("cytube-mediaquery/lib/provider/googledrive");
var TwitchVOD = require("cytube-mediaquery/lib/provider/twitch-vod"); var TwitchVOD = require("cytube-mediaquery/lib/provider/twitch-vod");
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('get-info');
/* /*
* Preference map of quality => youtube formats. * Preference map of quality => youtube formats.
@ -43,7 +44,7 @@ const CONTENT_TYPES = {
var urlRetrieve = function (transport, options, callback) { var urlRetrieve = function (transport, options, callback) {
var req = transport.request(options, function (res) { var req = transport.request(options, function (res) {
res.on("error", function (err) { res.on("error", function (err) {
Logger.errlog.log("HTTP response " + options.host + options.path + " failed: "+ LOGGER.error("HTTP response " + options.host + options.path + " failed: "+
err); err);
callback(503, ""); callback(503, "");
}); });
@ -59,7 +60,7 @@ var urlRetrieve = function (transport, options, callback) {
}); });
req.on("error", function (err) { req.on("error", function (err) {
Logger.errlog.log("HTTP request " + options.host + options.path + " failed: " + LOGGER.error("HTTP request " + options.host + options.path + " failed: " +
err); err);
callback(503, ""); callback(503, "");
}); });
@ -512,7 +513,7 @@ var Getters = {
if (/invalid embed/i.test(e.message)) { if (/invalid embed/i.test(e.message)) {
return callback(e.message); return callback(e.message);
} else { } else {
Logger.errlog.log(e.stack); LOGGER.error(e.stack);
return callback("Unknown error processing embed"); return callback("Unknown error processing embed");
} }
} }

View File

@ -5,7 +5,8 @@ var path = require('path');
var querystring = require('querystring'); var querystring = require('querystring');
var crypto = require('crypto'); var crypto = require('crypto');
var Logger = require('./logger'); import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('google2vtt');
function md5(input) { function md5(input) {
var hash = crypto.createHash('md5'); var hash = crypto.createHash('md5');
@ -96,7 +97,7 @@ function handleGetSubtitles(req, res) {
fetchSubtitles(id, lang, name, vid, fileAbsolute, function (err) { fetchSubtitles(id, lang, name, vid, fileAbsolute, function (err) {
delete subtitleLock[fileAbsolute]; delete subtitleLock[fileAbsolute];
if (err) { if (err) {
Logger.errlog.log(err.stack); LOGGER.error(err.stack);
return res.sendStatus(500); return res.sendStatus(500);
} }
@ -141,7 +142,7 @@ function fetchSubtitles(id, lang, name, vid, file, cb) {
if (err) { if (err) {
cb(err); cb(err);
} else { } else {
Logger.syslog.log('Saved subtitle file ' + file); LOGGER.info('Saved subtitle file ' + file);
cb(); cb();
} }
}); });
@ -154,19 +155,19 @@ function fetchSubtitles(id, lang, name, vid, file, cb) {
function clearOldSubtitles() { function clearOldSubtitles() {
fs.readdir(subtitleDir, function (err, files) { fs.readdir(subtitleDir, function (err, files) {
if (err) { if (err) {
Logger.errlog.log(err.stack); LOGGER.error(err.stack);
return; return;
} }
files.forEach(function (file) { files.forEach(function (file) {
fs.stat(path.join(subtitleDir, file), function (err, stats) { fs.stat(path.join(subtitleDir, file), function (err, stats) {
if (err) { if (err) {
Logger.errlog.log(err.stack); LOGGER.error(err.stack);
return; return;
} }
if (stats.mtime.getTime() < Date.now() - ONE_DAY) { if (stats.mtime.getTime() < Date.now() - ONE_DAY) {
Logger.syslog.log('Deleting old subtitle file: ' + file); LOGGER.info('Deleting old subtitle file: ' + file);
fs.unlink(path.join(subtitleDir, file)); fs.unlink(path.join(subtitleDir, file));
} }
}); });

View File

@ -1,5 +1,4 @@
var sio = require("socket.io"); var sio = require("socket.io");
var Logger = require("../logger");
var db = require("../database"); var db = require("../database");
var User = require("../user"); var User = require("../user");
var Server = require("../server"); var Server = require("../server");
@ -16,9 +15,12 @@ var session = require("../session");
import counters from '../counters'; import counters from '../counters';
import { verifyIPSessionCookie } from '../web/middleware/ipsessioncookie'; import { verifyIPSessionCookie } from '../web/middleware/ipsessioncookie';
import Promise from 'bluebird'; import Promise from 'bluebird';
import { LoggerFactory } from '@calzoneman/jsli';
const verifySession = Promise.promisify(session.verifySession); const verifySession = Promise.promisify(session.verifySession);
const getAliases = Promise.promisify(db.getAliases); const getAliases = Promise.promisify(db.getAliases);
const LOGGER = LoggerFactory.getLogger('ioserver');
var CONNECT_RATE = { var CONNECT_RATE = {
burst: 5, burst: 5,
sustained: 0.1 sustained: 0.1
@ -93,7 +95,7 @@ function throttleIP(sock) {
} }
if (ipThrottle[ip].throttle(CONNECT_RATE)) { if (ipThrottle[ip].throttle(CONNECT_RATE)) {
Logger.syslog.log("WARN: IP throttled: " + ip); LOGGER.warn("IP throttled: " + ip);
sock.emit("kick", { sock.emit("kick", {
reason: "Your IP address is connecting too quickly. Please "+ reason: "Your IP address is connecting too quickly. Please "+
"wait 10 seconds before joining again." "wait 10 seconds before joining again."
@ -225,7 +227,7 @@ function handleConnection(sock) {
// Check for global ban on the IP // Check for global ban on the IP
if (db.isGlobalIPBanned(ip)) { if (db.isGlobalIPBanned(ip)) {
Logger.syslog.log("Rejecting " + ip + " - global banned"); LOGGER.info("Rejecting " + ip + " - global banned");
sock.emit("kick", { reason: "Your IP is globally banned." }); sock.emit("kick", { reason: "Your IP is globally banned." });
sock.disconnect(); sock.disconnect();
return; return;
@ -235,7 +237,7 @@ function handleConnection(sock) {
return; return;
} }
Logger.syslog.log("Accepted socket from " + ip); LOGGER.info("Accepted socket from " + ip);
counters.add("socket.io:accept", 1); counters.add("socket.io:accept", 1);
addTypecheckedFunctions(sock); addTypecheckedFunctions(sock);
@ -252,7 +254,7 @@ function handleConnection(sock) {
user.socket.emit("rank", user.account.effectiveRank); user.socket.emit("rank", user.account.effectiveRank);
user.setFlag(Flags.U_LOGGED_IN); user.setFlag(Flags.U_LOGGED_IN);
user.emit("login", user.account); user.emit("login", user.account);
Logger.syslog.log(ip + " logged in as " + user.getName()); LOGGER.info(ip + " logged in as " + user.getName());
user.setFlag(Flags.U_READY); user.setFlag(Flags.U_READY);
} else { } else {
user.socket.emit("rank", -1); user.socket.emit("rank", -1);
@ -280,7 +282,7 @@ module.exports = {
} }
var id = bind.ip + ":" + bind.port; var id = bind.ip + ":" + bind.port;
if (id in bound) { if (id in bound) {
Logger.syslog.log("[WARN] Ignoring duplicate listen address " + id); LOGGER.warn("Ignoring duplicate listen address " + id);
return; return;
} }

View File

@ -1,5 +1,9 @@
// @flow
var fs = require("graceful-fs"); var fs = require("graceful-fs");
var path = require("path"); var path = require("path");
import { LoggerFactory, Logger as JsliLogger, LogLevel } from '@calzoneman/jsli';
import { sprintf } from 'sprintf-js';
function getTimeString() { function getTimeString() {
var d = new Date(); var d = new Date();
@ -59,3 +63,27 @@ exports.Logger = Logger;
exports.errlog = errlog; exports.errlog = errlog;
exports.syslog = syslog; exports.syslog = syslog;
exports.eventlog = eventlog; exports.eventlog = eventlog;
class LegacyLogger extends JsliLogger {
constructor(level: LogLevel, loggerName: string) {
super(level, loggerName);
}
log(level: LogLevel, ...args: any[]) {
var message: string = "[" + level.name + "] " + this.loggerName + ": ";
message += sprintf(args[0], ...args.slice(1));
if (level.shouldLogAtLevel(LogLevel.ERROR)) {
errlog.log(message);
} else {
syslog.log(message);
}
}
}
const level: LogLevel = !!process.env.DEBUG ? LogLevel.DEBUG : LogLevel.INFO;
LoggerFactory.setLoggerImplFactory({
getLogger(loggerName: string): LegacyLogger {
return new LegacyLogger(level, loggerName);
}
});

View File

@ -1,5 +1,7 @@
import Logger from '../logger';
import uuid from 'uuid'; import uuid from 'uuid';
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('announcementrefresher');
var SERVER; var SERVER;
const SERVER_ANNOUNCEMENTS = 'serverAnnouncements'; const SERVER_ANNOUNCEMENTS = 'serverAnnouncements';
@ -31,7 +33,7 @@ class AnnouncementRefresher {
try { try {
data = JSON.parse(message); data = JSON.parse(message);
} catch (error) { } catch (error) {
Logger.errlog.log('Unable to unmarshal server announcement: ' + error.stack LOGGER.error('Unable to unmarshal server announcement: ' + error.stack
+ '\nMessage was: ' + message); + '\nMessage was: ' + message);
return; return;
} }

View File

@ -2,7 +2,9 @@ import Promise from 'bluebird';
import uuid from 'uuid'; import uuid from 'uuid';
import { runLuaScript } from 'cytube-common/lib/redis/lualoader'; import { runLuaScript } from 'cytube-common/lib/redis/lualoader';
import path from 'path'; import path from 'path';
import Logger from '../logger'; import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('partitionchannelindex');
var SERVER = null; var SERVER = null;
const CHANNEL_INDEX = 'publicChannelList'; const CHANNEL_INDEX = 'publicChannelList';
@ -16,7 +18,7 @@ class PartitionChannelIndex {
this.uid = uuid.v4(); this.uid = uuid.v4();
this.cachedList = []; this.cachedList = [];
this.redisClient.on('error', error => { this.redisClient.on('error', error => {
Logger.errlog.log(`Redis error: ${error}`); LOGGER.error(`Redis error: ${error}`);
}); });
process.nextTick(() => { process.nextTick(() => {
@ -34,7 +36,7 @@ class PartitionChannelIndex {
]).then(result => { ]).then(result => {
this.cachedList = JSON.parse(result); this.cachedList = JSON.parse(result);
}).catch(error => { }).catch(error => {
Logger.errlog.log(`Failed to refresh channel list: ${error.stack}`); LOGGER.error(`Failed to refresh channel list: ${error.stack}`);
}); });
} }
@ -54,7 +56,7 @@ class PartitionChannelIndex {
}); });
this.redisClient.hsetAsync(CHANNEL_INDEX, this.uid, entry).catch(error => { this.redisClient.hsetAsync(CHANNEL_INDEX, this.uid, entry).catch(error => {
Logger.errlog.log(`Failed to publish local channel list: ${error.stack}`); LOGGER.error(`Failed to publish local channel list: ${error.stack}`);
}); });
} }

View File

@ -4,10 +4,13 @@ var Config = require("./config");
var Promise = require("bluebird"); var Promise = require("bluebird");
import * as ChannelStore from './channel-storage/channelstore'; import * as ChannelStore from './channel-storage/channelstore';
import { EventEmitter } from 'events'; import { EventEmitter } from 'events';
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('server');
module.exports = { module.exports = {
init: function () { init: function () {
Logger.syslog.log("Starting CyTube v" + VERSION); LOGGER.info("Starting CyTube v%s", VERSION);
var chanlogpath = path.join(__dirname, "../chanlogs"); var chanlogpath = path.join(__dirname, "../chanlogs");
fs.exists(chanlogpath, function (exists) { fs.exists(chanlogpath, function (exists) {
exists || fs.mkdirSync(chanlogpath); exists || fs.mkdirSync(chanlogpath);
@ -36,10 +39,7 @@ var fs = require("fs");
var http = require("http"); var http = require("http");
var https = require("https"); var https = require("https");
var express = require("express"); var express = require("express");
var Logger = require("./logger");
var Channel = require("./channel/channel"); var Channel = require("./channel/channel");
var User = require("./user");
var $util = require("./utilities");
var db = require("./database"); var db = require("./database");
var Flags = require("./flags"); var Flags = require("./flags");
var sio = require("socket.io"); var sio = require("socket.io");
@ -129,7 +129,7 @@ var Server = function () {
Config.get("listen").forEach(function (bind) { Config.get("listen").forEach(function (bind) {
var id = bind.ip + ":" + bind.port; var id = bind.ip + ":" + bind.port;
if (id in self.servers) { if (id in self.servers) {
Logger.syslog.log("[WARN] Ignoring duplicate listen address " + id); LOGGER.warn("Ignoring duplicate listen address %s", id);
return; return;
} }
@ -234,7 +234,7 @@ Server.prototype.unloadChannel = function (chan, options) {
if (!options.skipSave) { if (!options.skipSave) {
chan.saveState().catch(error => { chan.saveState().catch(error => {
Logger.errlog.log(`Failed to save /r/${chan.name} for unload: ${error.stack}`); LOGGER.error(`Failed to save /r/${chan.name} for unload: ${error.stack}`);
}); });
} }
@ -252,13 +252,13 @@ Server.prototype.unloadChannel = function (chan, options) {
*/ */
Object.keys(chan.modules[k]).forEach(function (prop) { Object.keys(chan.modules[k]).forEach(function (prop) {
if (chan.modules[k][prop] && chan.modules[k][prop]._onTimeout) { if (chan.modules[k][prop] && chan.modules[k][prop]._onTimeout) {
Logger.errlog.log("Warning: detected non-null timer when unloading " + LOGGER.warn("Detected non-null timer when unloading " +
"module " + k + ": " + prop); "module " + k + ": " + prop);
try { try {
clearTimeout(chan.modules[k][prop]); clearTimeout(chan.modules[k][prop]);
clearInterval(chan.modules[k][prop]); clearInterval(chan.modules[k][prop]);
} catch (error) { } catch (error) {
Logger.errlog.log(error.stack); LOGGER.error(error.stack);
} }
} }
}); });
@ -271,7 +271,7 @@ Server.prototype.unloadChannel = function (chan, options) {
} }
} }
Logger.syslog.log("Unloaded channel " + chan.name); LOGGER.info("Unloaded channel " + chan.name);
chan.broadcastUsercount.cancel(); chan.broadcastUsercount.cancel();
// Empty all outward references from the channel // Empty all outward references from the channel
var keys = Object.keys(chan); var keys = Object.keys(chan);
@ -320,22 +320,22 @@ Server.prototype.setAnnouncement = function (data) {
}; };
Server.prototype.shutdown = function () { Server.prototype.shutdown = function () {
Logger.syslog.log("Unloading channels"); LOGGER.info("Unloading channels");
Promise.map(this.channels, channel => { Promise.map(this.channels, channel => {
try { try {
return channel.saveState().tap(() => { return channel.saveState().tap(() => {
Logger.syslog.log(`Saved /r/${channel.name}`); LOGGER.info(`Saved /r/${channel.name}`);
}).catch(err => { }).catch(err => {
Logger.errlog.log(`Failed to save /r/${channel.name}: ${err.stack}`); LOGGER.error(`Failed to save /r/${channel.name}: ${err.stack}`);
}); });
} catch (error) { } catch (error) {
Logger.errlog.log(`Failed to save channel: ${error.stack}`); LOGGER.error(`Failed to save channel: ${error.stack}`);
} }
}, { concurrency: 5 }).then(() => { }, { concurrency: 5 }).then(() => {
Logger.syslog.log("Goodbye"); LOGGER.info("Goodbye");
process.exit(0); process.exit(0);
}).catch(err => { }).catch(err => {
Logger.errlog.log(`Caught error while saving channels: ${err.stack}`); LOGGER.error(`Caught error while saving channels: ${err.stack}`);
process.exit(1); process.exit(1);
}); });
}; };
@ -348,7 +348,7 @@ Server.prototype.handlePartitionMapChange = function () {
} }
if (!this.partitionDecider.isChannelOnThisPartition(channel.uniqueName)) { if (!this.partitionDecider.isChannelOnThisPartition(channel.uniqueName)) {
Logger.syslog.log("Partition changed for " + channel.uniqueName); LOGGER.info("Partition changed for " + channel.uniqueName);
return channel.saveState().then(() => { return channel.saveState().then(() => {
channel.broadcastAll("partitionChange", channel.broadcastAll("partitionChange",
this.partitionDecider.getPartitionForChannel(channel.uniqueName)); this.partitionDecider.getPartitionForChannel(channel.uniqueName));
@ -361,12 +361,12 @@ Server.prototype.handlePartitionMapChange = function () {
}); });
this.unloadChannel(channel, { skipSave: true }); this.unloadChannel(channel, { skipSave: true });
}).catch(error => { }).catch(error => {
Logger.errlog.log(`Failed to unload /r/${channel.name} for ` + LOGGER.error(`Failed to unload /r/${channel.name} for ` +
`partition map flip: ${error.stack}`); `partition map flip: ${error.stack}`);
}); });
} }
}, { concurrency: 5 }).then(() => { }, { concurrency: 5 }).then(() => {
Logger.syslog.log("Partition reload complete"); LOGGER.info("Partition reload complete");
}); });
}; };

View File

@ -2,7 +2,9 @@ var https = require("https");
var path = require("path"); var path = require("path");
var fs = require("fs"); var fs = require("fs");
var domain = require("domain"); var domain = require("domain");
var Logger = require("./logger"); import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('tor');
function retrieveIPs(cb) { function retrieveIPs(cb) {
var options = { var options = {
@ -25,9 +27,9 @@ function retrieveIPs(cb) {
var d = domain.create(); var d = domain.create();
d.on("error", function (err) { d.on("error", function (err) {
if (err.stack) if (err.stack)
Logger.errlog.log(err.stack); LOGGER.error(err.stack);
else else
Logger.errlog.log(err); LOGGER.error(err);
}); });
d.run(function () { d.run(function () {
@ -66,11 +68,11 @@ function getTorIPs(cb) {
var _ipList = []; var _ipList = [];
getTorIPs(function (err, ips) { getTorIPs(function (err, ips) {
if (err) { if (err) {
Logger.errlog.log(err); LOGGER.error(err);
return; return;
} }
Logger.syslog.log("Loaded Tor IP list"); LOGGER.info("Loaded Tor IP list");
_ipList = ips; _ipList = ips;
}); });

View File

@ -1,13 +1,15 @@
var Logger = require("./logger");
var Server = require("./server"); var Server = require("./server");
var util = require("./utilities"); var util = require("./utilities");
var db = require("./database"); var db = require("./database");
var InfoGetter = require("./get-info");
var Config = require("./config"); var Config = require("./config");
var ACP = require("./acp"); var ACP = require("./acp");
var Account = require("./account"); var Account = require("./account");
var Flags = require("./flags"); var Flags = require("./flags");
import { EventEmitter } from 'events'; import { EventEmitter } from 'events';
import { LoggerFactory } from '@calzoneman/jsli';
import Logger from './logger';
const LOGGER = LoggerFactory.getLogger('user');
function User(socket) { function User(socket) {
var self = this; var self = this;
@ -314,7 +316,7 @@ User.prototype.login = function (name, pw) {
name: user.name name: user.name
}); });
db.recordVisit(self.realip, self.getName()); db.recordVisit(self.realip, self.getName());
Logger.syslog.log(self.realip + " logged in as " + user.name); LOGGER.info(self.realip + " logged in as " + user.name);
self.setFlag(Flags.U_LOGGED_IN); self.setFlag(Flags.U_LOGGED_IN);
self.clearFlag(Flags.U_LOGGING_IN); self.clearFlag(Flags.U_LOGGING_IN);
self.emit("login", self.account); self.emit("login", self.account);
@ -392,7 +394,7 @@ User.prototype.guestLogin = function (name) {
guest: true guest: true
}); });
db.recordVisit(self.realip, self.getName()); db.recordVisit(self.realip, self.getName());
Logger.syslog.log(self.realip + " signed in as " + name); LOGGER.info(self.realip + " signed in as " + name);
self.setFlag(Flags.U_LOGGED_IN); self.setFlag(Flags.U_LOGGED_IN);
self.emit("login", self.account); self.emit("login", self.account);
}); });
@ -421,7 +423,7 @@ User.prototype.getFirstSeenTime = function getFirstSeenTime() {
} else if (this.socket.ipSessionFirstSeen) { } else if (this.socket.ipSessionFirstSeen) {
return this.socket.ipSessionFirstSeen.getTime(); return this.socket.ipSessionFirstSeen.getTime();
} else { } else {
Logger.errlog.log(`User "${this.getName()}" (IP: ${this.realip}) has neither ` + LOGGER.error(`User "${this.getName()}" (IP: ${this.realip}) has neither ` +
"an IP sesion first seen time nor a registered account."); "an IP sesion first seen time nor a registered account.");
return Date.now(); return Date.now();
} }

View File

@ -14,6 +14,9 @@ var Server = require("../server");
var session = require("../session"); var session = require("../session");
var csrf = require("./csrf"); var csrf = require("./csrf");
const url = require("url"); const url = require("url");
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('database/accounts');
/** /**
* Handles a GET request for /account/edit * Handles a GET request for /account/edit
@ -581,7 +584,7 @@ function handlePasswordReset(req, res) {
Config.get("mail.nodemailer").sendMail(mail, function (err, response) { Config.get("mail.nodemailer").sendMail(mail, function (err, response) {
if (err) { if (err) {
Logger.errlog.log("mail fail: " + err); LOGGER.error("mail fail: " + err);
sendPug(res, "account-passwordreset", { sendPug(res, "account-passwordreset", {
reset: false, reset: false,
resetEmail: email, resetEmail: email,

View File

@ -7,7 +7,6 @@
var pug = require("pug"); var pug = require("pug");
var path = require("path"); var path = require("path");
var webserver = require("./webserver"); var webserver = require("./webserver");
var cookieall = webserver.cookieall;
var sendPug = require("./pug").sendPug; var sendPug = require("./pug").sendPug;
var Logger = require("../logger"); var Logger = require("../logger");
var $util = require("../utilities"); var $util = require("../utilities");
@ -16,6 +15,9 @@ var Config = require("../config");
var url = require("url"); var url = require("url");
var session = require("../session"); var session = require("../session");
var csrf = require("./csrf"); var csrf = require("./csrf");
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('web/auth');
/** /**
* Processes a login request. Sets a cookie upon successful authentication * Processes a login request. Sets a cookie upon successful authentication
@ -37,7 +39,7 @@ function handleLogin(req, res) {
var host = req.hostname; var host = req.hostname;
if (host.indexOf(Config.get("http.root-domain")) === -1 && if (host.indexOf(Config.get("http.root-domain")) === -1 &&
Config.get("http.alt-domains").indexOf(host) === -1) { Config.get("http.alt-domains").indexOf(host) === -1) {
Logger.syslog.log("WARNING: Attempted login from non-approved domain " + host); LOGGER.warn("Attempted login from non-approved domain " + host);
return res.sendStatus(403); return res.sendStatus(403);
} }

View File

@ -1,7 +1,8 @@
import Config from '../../config';
import CyTubeUtil from '../../utilities'; import CyTubeUtil from '../../utilities';
import Logger from '../../logger';
import * as HTTPStatus from '../httpstatus'; import * as HTTPStatus from '../httpstatus';
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('web/routes/socketconfig');
export default function initialize(app, clusterClient) { export default function initialize(app, clusterClient) {
app.get('/socketconfig/:channel.json', (req, res) => { app.get('/socketconfig/:channel.json', (req, res) => {
@ -14,7 +15,7 @@ export default function initialize(app, clusterClient) {
clusterClient.getSocketConfig(req.params.channel).then(config => { clusterClient.getSocketConfig(req.params.channel).then(config => {
res.json(config); res.json(config);
}).catch(err => { }).catch(err => {
Logger.errlog.log(err.stack); LOGGER.error(err.stack);
return res.status(500).json({ return res.status(500).json({
error: err.message error: err.message
}); });

View File

@ -1,9 +1,7 @@
import fs from 'fs'; import fs from 'fs';
import path from 'path'; import path from 'path';
import net from 'net'; import net from 'net';
import express from 'express';
import { sendPug } from './pug'; import { sendPug } from './pug';
import Logger from '../logger';
import Config from '../config'; import Config from '../config';
import bodyParser from 'body-parser'; import bodyParser from 'body-parser';
import cookieParser from 'cookie-parser'; import cookieParser from 'cookie-parser';
@ -13,6 +11,9 @@ import csrf from './csrf';
import * as HTTPStatus from './httpstatus'; import * as HTTPStatus from './httpstatus';
import { CSRFError, HTTPError } from '../errors'; import { CSRFError, HTTPError } from '../errors';
import counters from "../counters"; import counters from "../counters";
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('webserver');
function initializeLog(app) { function initializeLog(app) {
const logFormat = ':real-address - :remote-user [:date] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent"'; const logFormat = ':real-address - :remote-user [:date] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent"';
@ -111,7 +112,7 @@ function initializeErrorHandlers(app) {
// Log 5xx (server) errors // Log 5xx (server) errors
if (Math.floor(status / 100) === 5) { if (Math.floor(status / 100) === 5) {
Logger.errlog.log(err.stack); LOGGER.error(err.stack);
} }
res.status(status); res.status(status);
@ -141,7 +142,7 @@ module.exports = {
limit: '1kb' // No POST data should ever exceed this size under normal usage limit: '1kb' // No POST data should ever exceed this size under normal usage
})); }));
if (webConfig.getCookieSecret() === 'change-me') { if (webConfig.getCookieSecret() === 'change-me') {
Logger.errlog.log('WARNING: The configured cookie secret was left as the ' + LOGGER.warn('The configured cookie secret was left as the ' +
'default of "change-me".'); 'default of "change-me".');
} }
app.use(cookieParser(webConfig.getCookieSecret())); app.use(cookieParser(webConfig.getCookieSecret()));
@ -154,7 +155,7 @@ module.exports = {
app.use(require('compression')({ app.use(require('compression')({
threshold: webConfig.getGzipThreshold() threshold: webConfig.getGzipThreshold()
})); }));
Logger.syslog.log('Enabled gzip compression'); LOGGER.info('Enabled gzip compression');
} }
if (webConfig.getEnableMinification()) { if (webConfig.getEnableMinification()) {
@ -172,7 +173,7 @@ module.exports = {
app.use(require('express-minify')({ app.use(require('express-minify')({
cache: cacheDir cache: cacheDir
})); }));
Logger.syslog.log('Enabled express-minify for CSS and JS'); LOGGER.info('Enabled express-minify for CSS and JS');
} }
require('./routes/channel')(app, ioConfig); require('./routes/channel')(app, ioConfig);