mirror of https://github.com/calzoneman/sync.git
Refactor logging
This commit is contained in:
parent
b1a328d2e0
commit
8306d2d1b6
1
index.js
1
index.js
|
@ -6,6 +6,7 @@ if (/^v0/.test(process.version)) {
|
|||
}
|
||||
|
||||
try {
|
||||
require("./lib/logger");
|
||||
var Server = require("./lib/server");
|
||||
} catch (err) {
|
||||
console.error('FATAL: Failed to require() lib/server.js');
|
||||
|
|
10
package.json
10
package.json
|
@ -2,12 +2,13 @@
|
|||
"author": "Calvin Montgomery",
|
||||
"name": "CyTube",
|
||||
"description": "Online media synchronizer and chat",
|
||||
"version": "3.34.10",
|
||||
"version": "3.35.0",
|
||||
"repository": {
|
||||
"url": "http://github.com/calzoneman/sync"
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@calzoneman/jsli": "^1.0.1",
|
||||
"babel-cli": "^6.1.4",
|
||||
"babel-core": "^6.1.4",
|
||||
"babel-plugin-add-module-exports": "^0.2.1",
|
||||
|
@ -43,6 +44,7 @@
|
|||
"socket.io": "^1.4.0",
|
||||
"socket.io-redis": "^1.0.0",
|
||||
"source-map-support": "^0.4.0",
|
||||
"sprintf-js": "^1.0.3",
|
||||
"status-message-polyfill": "git://github.com/calzoneman/status-message-polyfill",
|
||||
"toml": "^2.3.0",
|
||||
"uuid": "^2.0.1",
|
||||
|
@ -51,6 +53,7 @@
|
|||
"scripts": {
|
||||
"build-player": "$npm_node_execpath build-player.js",
|
||||
"build-server": "babel -D --source-maps --loose es6.destructuring,es6.forOf --out-dir lib/ src/",
|
||||
"flow": "flow",
|
||||
"postinstall": "./postinstall.sh",
|
||||
"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",
|
||||
|
@ -58,7 +61,9 @@
|
|||
"integration-test": "mocha --recursive integration_test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-plugin-transform-flow-strip-types": "^6.22.0",
|
||||
"coffee-script": "^1.9.2",
|
||||
"flow-bin": "^0.43.0",
|
||||
"mocha": "^3.2.0"
|
||||
},
|
||||
"babel": {
|
||||
|
@ -72,7 +77,8 @@
|
|||
"loose": true
|
||||
}
|
||||
],
|
||||
"add-module-exports"
|
||||
"add-module-exports",
|
||||
"transform-flow-strip-types"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,10 +5,12 @@
|
|||
running.
|
||||
*/
|
||||
|
||||
var Logger = require("./logger");
|
||||
var Config = require("./config");
|
||||
var db = require("./database");
|
||||
var Promise = require("bluebird");
|
||||
import { LoggerFactory } from '@calzoneman/jsli';
|
||||
|
||||
const LOGGER = LoggerFactory.getLogger('bgtask');
|
||||
|
||||
var init = null;
|
||||
|
||||
|
@ -39,9 +41,9 @@ function initAliasCleanup(Server) {
|
|||
|
||||
setInterval(function () {
|
||||
db.cleanOldAliases(CLEAN_EXPIRE, function (err) {
|
||||
Logger.syslog.log("Cleaned old aliases");
|
||||
LOGGER.info("Cleaned old aliases");
|
||||
if (err)
|
||||
Logger.errlog.log(err);
|
||||
LOGGER.error(err);
|
||||
});
|
||||
}, CLEAN_INTERVAL);
|
||||
}
|
||||
|
@ -53,7 +55,7 @@ function initPasswordResetCleanup(Server) {
|
|||
setInterval(function () {
|
||||
db.cleanOldPasswordResets(function (err) {
|
||||
if (err)
|
||||
Logger.errlog.log(err);
|
||||
LOGGER.error(err);
|
||||
});
|
||||
}, CLEAN_INTERVAL);
|
||||
}
|
||||
|
@ -63,28 +65,28 @@ function initChannelDumper(Server) {
|
|||
* 60000;
|
||||
setInterval(function () {
|
||||
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) => {
|
||||
return Promise.delay(wait).then(() => {
|
||||
if (!chan.dead && chan.users && chan.users.length > 0) {
|
||||
return chan.saveState().tap(() => {
|
||||
Logger.syslog.log(`Saved /r/${chan.name}`);
|
||||
LOGGER.info(`Saved /r/${chan.name}`);
|
||||
}).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 => {
|
||||
Logger.errlog.log(`Failed to save channel: ${error.stack}`);
|
||||
LOGGER.error(`Failed to save channel: ${error.stack}`);
|
||||
});
|
||||
}, 0).catch(error => {
|
||||
Logger.errlog.log(`Failed to save channels: ${error.stack}`);
|
||||
LOGGER.error(`Failed to save channels: ${error.stack}`);
|
||||
});
|
||||
}, CHANNEL_SAVE_INTERVAL);
|
||||
}
|
||||
|
||||
module.exports = function (Server) {
|
||||
if (init === Server) {
|
||||
Logger.errlog.log("WARNING: Attempted to re-init background tasks");
|
||||
LOGGER.warn("Attempted to re-init background tasks");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,8 +3,6 @@ import Promise from 'bluebird';
|
|||
import Config from '../config';
|
||||
import db from '../database';
|
||||
import { DatabaseStore } from './dbstore';
|
||||
import { syslog } from '../logger';
|
||||
syslog.log = () => undefined;
|
||||
|
||||
function main() {
|
||||
Config.load('config.yaml');
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import Promise from 'bluebird';
|
||||
import { ChannelStateSizeError,
|
||||
ChannelNotFoundError } from '../errors';
|
||||
import { ChannelStateSizeError } from '../errors';
|
||||
import db from '../database';
|
||||
import Logger from '../logger';
|
||||
import { LoggerFactory } from '@calzoneman/jsli';
|
||||
|
||||
const LOGGER = LoggerFactory.getLogger('dbstore');
|
||||
|
||||
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 = ?';
|
||||
|
||||
function queryAsync(query, substitutions) {
|
||||
|
@ -46,7 +46,7 @@ export class DatabaseStore {
|
|||
try {
|
||||
data[row.key] = JSON.parse(row.value);
|
||||
} catch (e) {
|
||||
Logger.errlog.log(`Channel data for channel "${channelName}", ` +
|
||||
LOGGER.error(`Channel data for channel "${channelName}", ` +
|
||||
`key "${row.key}" is invalid: ${e}`);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
var Logger = require("../logger");
|
||||
var ChannelModule = require("./module");
|
||||
var Flags = require("../flags");
|
||||
var Account = require("../account");
|
||||
var util = require("../utilities");
|
||||
var fs = require("graceful-fs");
|
||||
var path = require("path");
|
||||
var sio = require("socket.io");
|
||||
|
@ -12,6 +9,10 @@ import { ChannelStateSizeError } from '../errors';
|
|||
import Promise from 'bluebird';
|
||||
import { EventEmitter } from 'events';
|
||||
import { throttle } from '../util/throttle';
|
||||
import Logger from '../logger';
|
||||
import { LoggerFactory } from '@calzoneman/jsli';
|
||||
|
||||
const LOGGER = LoggerFactory.getLogger('channel');
|
||||
|
||||
const USERCOUNT_THROTTLE = 10000;
|
||||
|
||||
|
@ -43,7 +44,7 @@ class ReferenceCounter {
|
|||
delete this.references[caller];
|
||||
}
|
||||
} else {
|
||||
Logger.errlog.log("ReferenceCounter::unref() called by caller [" +
|
||||
LOGGER.error("ReferenceCounter::unref() called by caller [" +
|
||||
caller + "] but this caller had no active references! " +
|
||||
`(channel: ${this.channelName})`);
|
||||
}
|
||||
|
@ -56,7 +57,7 @@ class ReferenceCounter {
|
|||
checkRefCount() {
|
||||
if (this.refCount === 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: " +
|
||||
JSON.stringify(Object.keys(this.references)) +
|
||||
` (channel: ${this.channelName})`);
|
||||
|
@ -64,7 +65,7 @@ class ReferenceCounter {
|
|||
this.refCount += this.references[caller];
|
||||
}
|
||||
} 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" +
|
||||
` (channel: ${this.channelName})`);
|
||||
this.refCount = this.channel.users.length;
|
||||
|
@ -208,7 +209,7 @@ Channel.prototype.loadState = function () {
|
|||
try {
|
||||
this.modules[m].load(data);
|
||||
} catch (e) {
|
||||
Logger.errlog.log("Failed to load module " + m + " for channel " +
|
||||
LOGGER.error("Failed to load module " + m + " for channel " +
|
||||
this.uniqueName);
|
||||
}
|
||||
});
|
||||
|
@ -219,7 +220,7 @@ Channel.prototype.loadState = function () {
|
|||
"enforced by this server. Please contact an administrator " +
|
||||
"for assistance.";
|
||||
|
||||
Logger.errlog.log(err.stack);
|
||||
LOGGER.error(err.stack);
|
||||
errorLoad(message, false);
|
||||
}).catch(err => {
|
||||
if (err.code === 'ENOENT') {
|
||||
|
@ -233,7 +234,7 @@ Channel.prototype.loadState = function () {
|
|||
"disk. Please contact an administrator for assistance. " +
|
||||
`The error was: ${err}.`;
|
||||
|
||||
Logger.errlog.log(err.stack);
|
||||
LOGGER.error(err.stack);
|
||||
errorLoad(message);
|
||||
}
|
||||
});
|
||||
|
@ -369,7 +370,7 @@ Channel.prototype.acceptUser = function (user) {
|
|||
user.autoAFK();
|
||||
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 (this.modules.options && this.modules.options.get("torbanned")) {
|
||||
user.kick("This channel has banned connections from Tor.");
|
||||
|
@ -420,7 +421,7 @@ Channel.prototype.acceptUser = function (user) {
|
|||
|
||||
Channel.prototype.partUser = function (user) {
|
||||
if (!this.logger) {
|
||||
Logger.errlog.log("partUser called on dead channel");
|
||||
LOGGER.error("partUser called on dead channel");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
var FilterList = require("cytubefilters");
|
||||
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
|
||||
|
@ -76,7 +78,7 @@ ChatFilterModule.prototype.load = function (data) {
|
|||
try {
|
||||
this.filters = new FilterList(filters);
|
||||
} catch (e) {
|
||||
Logger.errlog.log("Filter load failed: " + e + " (channel:" +
|
||||
LOGGER.error("Filter load failed: " + e + " (channel:" +
|
||||
this.channel.name);
|
||||
this.channel.logger.log("Failed to load filters: " + e);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,9 @@ var Vimeo = require("cytube-mediaquery/lib/provider/vimeo");
|
|||
var ChannelModule = require("./module");
|
||||
var Config = require("../config");
|
||||
var InfoGetter = require("../get-info");
|
||||
var Logger = require("../logger");
|
||||
import { LoggerFactory } from '@calzoneman/jsli';
|
||||
|
||||
const LOGGER = LoggerFactory.getLogger('mediarefresher');
|
||||
|
||||
function MediaRefresherModule(channel) {
|
||||
ChannelModule.apply(this, arguments);
|
||||
|
@ -55,7 +57,7 @@ MediaRefresherModule.prototype.unload = function () {
|
|||
clearInterval(this._interval);
|
||||
this._interval = null;
|
||||
} catch (error) {
|
||||
Logger.errlog.log(error.stack);
|
||||
LOGGER.error(error.stack);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -94,7 +96,7 @@ MediaRefresherModule.prototype.initVimeo = function (data, cb) {
|
|||
|
||||
if (cb) cb();
|
||||
}).catch(function (err) {
|
||||
Logger.errlog.log("Unexpected vimeo::extract() fail: " + err.stack);
|
||||
LOGGER.error("Unexpected vimeo::extract() fail: " + err.stack);
|
||||
if (cb) cb();
|
||||
}).finally(() => {
|
||||
self.channel.refCounter.unref("MediaRefresherModule::initVimeo");
|
||||
|
@ -145,7 +147,7 @@ MediaRefresherModule.prototype.refreshGoogleDocs = function (media, cb) {
|
|||
if (err) {
|
||||
self.channel.logger.log("[mediarefresher] Google Docs refresh failed: " +
|
||||
err);
|
||||
Logger.errlog.log("Google Docs refresh failed for ID " + media.id +
|
||||
LOGGER.error("Google Docs refresh failed for ID " + media.id +
|
||||
": " + err);
|
||||
self.channel.refCounter.unref("MediaRefresherModule::refreshGoogleDocs");
|
||||
if (cb) cb();
|
||||
|
@ -204,7 +206,7 @@ MediaRefresherModule.prototype.initGooglePlus = function (media, cb) {
|
|||
if (err) {
|
||||
self.channel.logger.log("[mediarefresher] Google+ refresh failed: " +
|
||||
err);
|
||||
Logger.errlog.log("Google+ refresh failed for ID " + media.id +
|
||||
LOGGER.error("Google+ refresh failed for ID " + media.id +
|
||||
": " + err);
|
||||
self.channel.refCounter.unref("MediaRefresherModule::initGooglePlus");
|
||||
if (cb) cb();
|
||||
|
|
|
@ -6,9 +6,11 @@ var InfoGetter = require("../get-info");
|
|||
var Config = require("../config");
|
||||
var Flags = require("../flags");
|
||||
var db = require("../database");
|
||||
var Logger = require("../logger");
|
||||
var CustomEmbedFilter = require("../customembed").filter;
|
||||
var XSS = require("../xss");
|
||||
import { LoggerFactory } from '@calzoneman/jsli';
|
||||
|
||||
const LOGGER = LoggerFactory.getLogger('playlist');
|
||||
|
||||
const MAX_ITEMS = Config.get("playlist.max-items");
|
||||
// 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 totalDuration = usersItems.map(item => item.media.seconds).reduce((a, b) => a + b, 0) + media.seconds;
|
||||
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)) {
|
||||
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);
|
||||
});
|
||||
} catch (e) {
|
||||
Logger.errlog.log("Loading user playlist failed!");
|
||||
Logger.errlog.log("PL: " + user.getName() + "-" + data.name);
|
||||
Logger.errlog.log(e.stack);
|
||||
LOGGER.error("Loading user playlist failed!");
|
||||
LOGGER.error("PL: " + user.getName() + "-" + data.name);
|
||||
LOGGER.error(e.stack);
|
||||
user.socket.emit("queueFail", {
|
||||
msg: "Internal error occurred when loading playlist.",
|
||||
link: null
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
var Logger = require("./logger");
|
||||
var nodemailer = require("nodemailer");
|
||||
var net = require("net");
|
||||
var YAML = require("yamljs");
|
||||
|
||||
import { LoggerFactory } from '@calzoneman/jsli';
|
||||
|
||||
const LOGGER = LoggerFactory.getLogger('config');
|
||||
|
||||
var defaults = {
|
||||
mysql: {
|
||||
server: "localhost",
|
||||
|
@ -135,7 +138,7 @@ function merge(obj, def, path) {
|
|||
merge(obj[key], def[key], path + "." + key);
|
||||
}
|
||||
} else {
|
||||
Logger.syslog.log("[WARNING] Missing config key " + (path + "." + key) +
|
||||
LOGGER.warn("Missing config key " + (path + "." + key) +
|
||||
"; using default: " + JSON.stringify(def[key]));
|
||||
obj[key] = def[key];
|
||||
}
|
||||
|
@ -152,14 +155,14 @@ exports.load = function (file) {
|
|||
cfg = YAML.load(path.join(__dirname, "..", file));
|
||||
} catch (e) {
|
||||
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;
|
||||
return;
|
||||
} else {
|
||||
Logger.errlog.log("Error loading config file " + file + ": ");
|
||||
Logger.errlog.log(e);
|
||||
LOGGER.error("Error loading config file " + file + ": ");
|
||||
LOGGER.error(e);
|
||||
if (e.stack) {
|
||||
Logger.errlog.log(e.stack);
|
||||
LOGGER.error(e.stack);
|
||||
}
|
||||
cfg = defaults;
|
||||
return;
|
||||
|
@ -167,7 +170,7 @@ exports.load = function (file) {
|
|||
}
|
||||
|
||||
if (cfg == null) {
|
||||
Logger.syslog.log(file + " is an Invalid configuration file, " +
|
||||
LOGGER.info(file + " is an Invalid configuration file, " +
|
||||
"assuming default configuration");
|
||||
cfg = defaults;
|
||||
return;
|
||||
|
@ -182,13 +185,14 @@ exports.load = function (file) {
|
|||
cfg.mail.config = mailconfig;
|
||||
|
||||
preprocessConfig(cfg);
|
||||
Logger.syslog.log("Loaded configuration from " + file);
|
||||
LOGGER.info("Loaded configuration from " + file);
|
||||
};
|
||||
|
||||
// I'm sorry
|
||||
function preprocessConfig(cfg) {
|
||||
/* 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) {
|
||||
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 "+
|
||||
"automatically, but you should read config.template.yaml "+
|
||||
"and change your config.yaml to the new format.");
|
||||
|
@ -304,21 +308,21 @@ function preprocessConfig(cfg) {
|
|||
if (net.isIPv6(srv.ip) || srv.ip === "::") {
|
||||
if (srv.https && !cfg.io["ipv6-ssl"]) {
|
||||
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 " +
|
||||
"because the Socket.IO client cannot connect to " +
|
||||
"a raw IPv6 address.");
|
||||
Logger.errlog.log("(Listener was: " + JSON.stringify(srv) + ")");
|
||||
LOGGER.error("(Listener was: " + JSON.stringify(srv) + ")");
|
||||
} else {
|
||||
cfg.io["ipv6-ssl"] = srv.url;
|
||||
}
|
||||
} else if (!cfg.io["ipv6-nossl"]) {
|
||||
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 " +
|
||||
"because the Socket.IO client cannot connect to " +
|
||||
"a raw IPv6 address.");
|
||||
Logger.errlog.log("(Listener was: " + JSON.stringify(srv) + ")");
|
||||
LOGGER.error("(Listener was: " + JSON.stringify(srv) + ")");
|
||||
} else {
|
||||
cfg.io["ipv6-nossl"] = srv.url;
|
||||
}
|
||||
|
@ -372,7 +376,7 @@ function preprocessConfig(cfg) {
|
|||
require("cytube-mediaquery/lib/provider/youtube").setApiKey(
|
||||
cfg["youtube-v3-key"]);
|
||||
} 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 " +
|
||||
"https://developers.google.com/youtube/registering_an_application for " +
|
||||
"information on registering an API key.");
|
||||
|
@ -382,7 +386,7 @@ function preprocessConfig(cfg) {
|
|||
require("cytube-mediaquery/lib/provider/twitch-vod").setClientID(
|
||||
cfg["twitch-client-id"]);
|
||||
} 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 " +
|
||||
"https://github.com/justintv/Twitch-API/blob/master/authentication.md#developer-setup" +
|
||||
"for more information on registering a client ID");
|
||||
|
|
|
@ -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 Socket from 'socket.io/lib/socket';
|
||||
import * as Metrics from 'cytube-common/lib/metrics/metrics';
|
||||
import { JSONFileMetricsReporter } from 'cytube-common/lib/metrics/jsonfilemetricsreporter';
|
||||
import { LoggerFactory } from '@calzoneman/jsli';
|
||||
|
||||
const LOGGER = LoggerFactory.getLogger('counters');
|
||||
|
||||
var counters = {};
|
||||
var server = null;
|
||||
|
@ -45,7 +44,7 @@ function setChannelCounts(metrics) {
|
|||
metrics.addProperty('channelCount:all', allCount);
|
||||
metrics.addProperty('channelCount:public', publicCount);
|
||||
} catch (error) {
|
||||
Logger.errlog.log(error.stack);
|
||||
LOGGER.error(error.stack);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
var mysql = require("mysql");
|
||||
var bcrypt = require("bcrypt");
|
||||
var $util = require("./utilities");
|
||||
var Logger = require("./logger");
|
||||
var Config = require("./config");
|
||||
var tables = require("./database/tables");
|
||||
var net = require("net");
|
||||
var util = require("./utilities");
|
||||
import * as Metrics from 'cytube-common/lib/metrics/metrics';
|
||||
import { LoggerFactory } from '@calzoneman/jsli';
|
||||
|
||||
const LOGGER = LoggerFactory.getLogger('database');
|
||||
|
||||
var pool = null;
|
||||
var global_ipbans = {};
|
||||
|
@ -26,7 +27,7 @@ module.exports.init = function () {
|
|||
// Test the connection
|
||||
pool.getConnection(function (err, conn) {
|
||||
if (err) {
|
||||
Logger.errlog.log("Initial database connection failed: " + err.stack);
|
||||
LOGGER.error("Initial database connection failed: " + err.stack);
|
||||
process.exit(1);
|
||||
} else {
|
||||
tables.init(module.exports.query, function (err) {
|
||||
|
@ -68,17 +69,17 @@ module.exports.query = function (query, sub, callback) {
|
|||
|
||||
pool.getConnection(function (err, conn) {
|
||||
if (err) {
|
||||
Logger.errlog.log("! DB connection failed: " + err);
|
||||
LOGGER.error("! DB connection failed: " + err);
|
||||
callback("Database failure", null);
|
||||
} else {
|
||||
function cback(err, res) {
|
||||
conn.release();
|
||||
if (err) {
|
||||
Logger.errlog.log("! DB query failed: " + query);
|
||||
LOGGER.error("! DB query failed: " + query);
|
||||
if (sub) {
|
||||
Logger.errlog.log("Substitutions: " + sub);
|
||||
LOGGER.error("Substitutions: " + sub);
|
||||
}
|
||||
Logger.errlog.log(err);
|
||||
LOGGER.error(err);
|
||||
callback("Database failure", null);
|
||||
} else {
|
||||
callback(null, res);
|
||||
|
@ -97,7 +98,7 @@ module.exports.query = function (query, sub, callback) {
|
|||
conn.query(query, cback);
|
||||
}
|
||||
} catch (error) {
|
||||
Logger.errlog.log("Broken query: " + error.stack);
|
||||
LOGGER.error("Broken query: " + error.stack);
|
||||
callback("Broken query", null);
|
||||
conn.release();
|
||||
}
|
||||
|
@ -344,7 +345,7 @@ module.exports.resetUserPassword = function (name, callback) {
|
|||
|
||||
bcrypt.hash(pw, 10, function (err, data) {
|
||||
if(err) {
|
||||
Logger.errlog.log("bcrypt error: " + err);
|
||||
LOGGER.error("bcrypt error: " + err);
|
||||
callback("Password reset failure", null);
|
||||
return;
|
||||
}
|
||||
|
@ -588,7 +589,7 @@ module.exports.loadAnnouncement = function () {
|
|||
try {
|
||||
announcement = JSON.parse(announcement);
|
||||
} catch (e) {
|
||||
Logger.errlog.log("Invalid announcement data in database: " +
|
||||
LOGGER.error("Invalid announcement data in database: " +
|
||||
announcement.value);
|
||||
module.exports.clearAnnouncement();
|
||||
return;
|
||||
|
|
|
@ -2,7 +2,9 @@ var $util = require("../utilities");
|
|||
var bcrypt = require("bcrypt");
|
||||
var db = require("../database");
|
||||
var Config = require("../config");
|
||||
var Logger = require("../logger");
|
||||
import { LoggerFactory } from '@calzoneman/jsli';
|
||||
|
||||
const LOGGER = LoggerFactory.getLogger('database/accounts');
|
||||
|
||||
var registrationLock = {};
|
||||
var blackHole = function () { };
|
||||
|
@ -450,7 +452,7 @@ module.exports = {
|
|||
userprof.text = profile.text || "";
|
||||
callback(null, userprof);
|
||||
} catch (e) {
|
||||
Logger.errlog.log("Corrupt profile: " + rows[0].profile +
|
||||
LOGGER.error("Corrupt profile: " + rows[0].profile +
|
||||
" (user: " + name + ")");
|
||||
callback(null, userprof);
|
||||
}
|
||||
|
|
|
@ -2,10 +2,12 @@ var db = require("../database");
|
|||
var valid = require("../utilities").isValidChannelName;
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
var Logger = require("../logger");
|
||||
var tables = require("./tables");
|
||||
var Flags = require("../flags");
|
||||
var util = require("../utilities");
|
||||
import { LoggerFactory } from '@calzoneman/jsli';
|
||||
|
||||
const LOGGER = LoggerFactory.getLogger('database/channels');
|
||||
|
||||
var blackHole = function () { };
|
||||
|
||||
|
@ -193,27 +195,27 @@ module.exports = {
|
|||
|
||||
module.exports.deleteBans(name, function (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) {
|
||||
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) {
|
||||
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),
|
||||
function (err) {
|
||||
if (err && err.code !== "ENOENT") {
|
||||
Logger.errlog.log("Deleting chandump failed:");
|
||||
Logger.errlog.log(err);
|
||||
LOGGER.error("Deleting chandump failed:");
|
||||
LOGGER.error(err);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -654,7 +656,7 @@ module.exports = {
|
|||
|
||||
db.query("UPDATE channels SET last_loaded = ? WHERE id = ?", [new Date(), channelId], 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 => {
|
||||
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}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
var db = require("../database");
|
||||
var Logger = require("../logger");
|
||||
var Q = require("q");
|
||||
import Promise from 'bluebird';
|
||||
import { LoggerFactory } from '@calzoneman/jsli';
|
||||
|
||||
const LOGGER = LoggerFactory.getLogger('database/update');
|
||||
|
||||
const DB_VERSION = 11;
|
||||
var hasUpdates = [];
|
||||
|
@ -13,7 +15,7 @@ module.exports.checkVersion = function () {
|
|||
}
|
||||
|
||||
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.query("INSERT INTO `meta` (`key`, `value`) VALUES ('db_version', ?)",
|
||||
[DB_VERSION],
|
||||
|
@ -26,7 +28,7 @@ module.exports.checkVersion = function () {
|
|||
}
|
||||
var next = function () {
|
||||
hasUpdates.push(v);
|
||||
Logger.syslog.log("Updated database to version " + v);
|
||||
LOGGER.info("Updated database to version " + v);
|
||||
if (v < DB_VERSION) {
|
||||
update(v++, next);
|
||||
} else {
|
||||
|
@ -48,7 +50,7 @@ function update(version, cb) {
|
|||
Q.nfcall(mergeChannelRanks),
|
||||
Q.nfcall(mergeChannelBans)
|
||||
]).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'" +
|
||||
" into the CyTube process to remove the unused tables.");
|
||||
cb();
|
||||
|
@ -71,7 +73,7 @@ function update(version, 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...");
|
||||
Q.nfcall(db.query, "SHOW TABLES")
|
||||
.then(function (rows) {
|
||||
|
@ -85,14 +87,14 @@ function addMetaColumnToLibraries(cb) {
|
|||
rows.forEach(function (table) {
|
||||
queue.push(Q.nfcall(db.query, "ALTER TABLE `" + table + "` ADD meta TEXT")
|
||||
.then(function () {
|
||||
Logger.syslog.log("Added meta column to " + table);
|
||||
LOGGER.info("Added meta column to " + table);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
return Q.all(queue);
|
||||
}).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);
|
||||
}
|
||||
|
||||
|
@ -112,12 +114,12 @@ function mergeChannelLibraries(cb) {
|
|||
"INSERT INTO `channel_libraries` SELECT id, title, seconds, type, meta, ?" +
|
||||
" AS channel FROM `" + table + "`", [name])
|
||||
.then(function () {
|
||||
Logger.syslog.log("Copied " + table + " to channel_libraries");
|
||||
LOGGER.info("Copied " + table + " to channel_libraries");
|
||||
}).catch(function (err) {
|
||||
Logger.errlog.log("Copying " + table + " to channel_libraries failed: " +
|
||||
LOGGER.error("Copying " + table + " to channel_libraries failed: " +
|
||||
err);
|
||||
if (err.stack) {
|
||||
Logger.errlog.log(err.stack);
|
||||
LOGGER.error(err.stack);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
@ -125,9 +127,9 @@ function mergeChannelLibraries(cb) {
|
|||
|
||||
return Q.all(queue);
|
||||
}).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) {
|
||||
Logger.errlog.log(err.stack);
|
||||
LOGGER.error(err.stack);
|
||||
}
|
||||
}).done(function () { cb(null); });
|
||||
}
|
||||
|
@ -148,12 +150,12 @@ function mergeChannelRanks(cb) {
|
|||
"INSERT INTO `channel_ranks` SELECT name, rank, ?" +
|
||||
" AS channel FROM `" + table + "`", [name])
|
||||
.then(function () {
|
||||
Logger.syslog.log("Copied " + table + " to channel_ranks");
|
||||
LOGGER.info("Copied " + table + " to channel_ranks");
|
||||
}).catch(function (err) {
|
||||
Logger.errlog.log("Copying " + table + " to channel_ranks failed: " +
|
||||
LOGGER.error("Copying " + table + " to channel_ranks failed: " +
|
||||
err);
|
||||
if (err.stack) {
|
||||
Logger.errlog.log(err.stack);
|
||||
LOGGER.error(err.stack);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
@ -161,9 +163,9 @@ function mergeChannelRanks(cb) {
|
|||
|
||||
return Q.all(queue);
|
||||
}).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) {
|
||||
Logger.errlog.log(err.stack);
|
||||
LOGGER.error(err.stack);
|
||||
}
|
||||
}).done(function () { cb(null); });
|
||||
}
|
||||
|
@ -184,12 +186,12 @@ function mergeChannelBans(cb) {
|
|||
"INSERT INTO `channel_bans` SELECT id, ip, name, bannedby, reason, ?" +
|
||||
" AS channel FROM `" + table + "`", [name])
|
||||
.then(function () {
|
||||
Logger.syslog.log("Copied " + table + " to channel_bans");
|
||||
LOGGER.info("Copied " + table + " to channel_bans");
|
||||
}).catch(function (err) {
|
||||
Logger.errlog.log("Copying " + table + " to channel_bans failed: " +
|
||||
LOGGER.error("Copying " + table + " to channel_bans failed: " +
|
||||
err);
|
||||
if (err.stack) {
|
||||
Logger.errlog.log(err.stack);
|
||||
LOGGER.error(err.stack);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
@ -197,9 +199,9 @@ function mergeChannelBans(cb) {
|
|||
|
||||
return Q.all(queue);
|
||||
}).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) {
|
||||
Logger.errlog.log(err.stack);
|
||||
LOGGER.error(err.stack);
|
||||
}
|
||||
}).done(function () { cb(null); });
|
||||
}
|
||||
|
@ -217,11 +219,11 @@ module.exports.deleteOldChannelTables = function (cb) {
|
|||
rows.forEach(function (table) {
|
||||
queue.push(Q.nfcall(db.query, "DROP TABLE `" + table + "`")
|
||||
.then(function () {
|
||||
Logger.syslog.log("Deleted " + table);
|
||||
LOGGER.info("Deleted " + table);
|
||||
}).catch(function (err) {
|
||||
Logger.errlog.log("Deleting " + table + " failed: " + err);
|
||||
LOGGER.error("Deleting " + table + " failed: " + err);
|
||||
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);
|
||||
}).catch(function (err) {
|
||||
Logger.errlog.log("Deleting old tables failed: " + err);
|
||||
LOGGER.error("Deleting old tables failed: " + err);
|
||||
if (err.stack) {
|
||||
Logger.errlog.log(err.stack);
|
||||
LOGGER.error(err.stack);
|
||||
}
|
||||
}).done(cb);
|
||||
};
|
||||
|
@ -247,10 +249,10 @@ function fixUtf8mb4(cb) {
|
|||
Q.allSettled(queries.map(function (query) {
|
||||
return Q.nfcall(db.query, query);
|
||||
})).then(function () {
|
||||
Logger.syslog.log("Fixed utf8mb4");
|
||||
LOGGER.info("Fixed utf8mb4");
|
||||
cb();
|
||||
}).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 () {
|
||||
Logger.syslog.log("Converted custom embeds.");
|
||||
LOGGER.info("Converted custom embeds.");
|
||||
cb();
|
||||
});
|
||||
});
|
||||
|
@ -312,7 +314,7 @@ function fixCustomEmbedsInUserPlaylists(cb) {
|
|||
try {
|
||||
media = CustomEmbedFilter(item.id);
|
||||
} catch (e) {
|
||||
Logger.syslog.log("WARNING: Unable to convert " + item.id);
|
||||
LOGGER.info("WARNING: Unable to convert " + item.id);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -332,19 +334,19 @@ function fixCustomEmbedsInUserPlaylists(cb) {
|
|||
});
|
||||
|
||||
Q.allSettled(all).then(function () {
|
||||
Logger.syslog.log('Fixed custom embeds in user_playlists');
|
||||
LOGGER.info('Fixed custom embeds in user_playlists');
|
||||
cb();
|
||||
});
|
||||
}).catch(function (err) {
|
||||
Logger.errlog.log(err.stack);
|
||||
LOGGER.error(err.stack);
|
||||
});
|
||||
}
|
||||
|
||||
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) => {
|
||||
if (error) {
|
||||
Logger.errlog.log(`Unable to add name_dedupe column: ${error}`);
|
||||
LOGGER.error(`Unable to add name_dedupe column: ${error}`);
|
||||
} else {
|
||||
cb();
|
||||
}
|
||||
|
@ -353,10 +355,10 @@ function addUsernameDedupeColumn(cb) {
|
|||
|
||||
function populateUsernameDedupeColumn(cb) {
|
||||
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) => {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -369,12 +371,12 @@ function populateUsernameDedupeColumn(cb) {
|
|||
}
|
||||
|
||||
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.release();
|
||||
if (error) {
|
||||
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();
|
||||
} else {
|
||||
reject(error);
|
||||
|
@ -388,7 +390,7 @@ function populateUsernameDedupeColumn(cb) {
|
|||
}, { concurrency: 10 }).then(() => {
|
||||
cb();
|
||||
}).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) {
|
||||
db.query("ALTER TABLE channels ADD COLUMN last_loaded TIMESTAMP NOT NULL DEFAULT 0", error => {
|
||||
if (error) {
|
||||
Logger.errlog.log(`Failed to add last_loaded column: ${error}`);
|
||||
LOGGER.error(`Failed to add last_loaded column: ${error}`);
|
||||
return;
|
||||
}
|
||||
|
||||
db.query("ALTER TABLE channels ADD INDEX i_last_loaded (last_loaded)", 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;
|
||||
}
|
||||
|
||||
|
@ -414,13 +416,13 @@ function addChannelLastLoadedColumn(cb) {
|
|||
function addChannelOwnerLastSeenColumn(cb) {
|
||||
db.query("ALTER TABLE channels ADD COLUMN owner_last_seen TIMESTAMP NOT NULL DEFAULT 0", 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;
|
||||
}
|
||||
|
||||
db.query("ALTER TABLE channels ADD INDEX i_owner_last_seen (owner_last_seen)", 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,9 @@ var http = require("http");
|
|||
var urlparse = require("url");
|
||||
var path = require("path");
|
||||
require("status-message-polyfill");
|
||||
import { LoggerFactory } from '@calzoneman/jsli';
|
||||
|
||||
const LOGGER = LoggerFactory.getLogger('ffmpeg');
|
||||
|
||||
var USE_JSON = true;
|
||||
var TIMEOUT = 30000;
|
||||
|
@ -244,7 +247,7 @@ exports.ffprobe = function ffprobe(filename, cb) {
|
|||
var stdout = "";
|
||||
var stderr = "";
|
||||
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");
|
||||
childErr = new Error("File query exceeded time limit of " + (TIMEOUT/1000) +
|
||||
" 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);
|
||||
if (code !== 0) {
|
||||
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.");
|
||||
USE_JSON = false;
|
||||
return ffprobe(filename, cb);
|
||||
|
@ -346,13 +349,13 @@ exports.query = function (filename, cb) {
|
|||
// Ignore ffprobe error messages, they are common and most often
|
||||
// indicate a problem with the remote file, not with this code.
|
||||
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 " +
|
||||
"the link. Contact support for troubleshooting " +
|
||||
"assistance.");
|
||||
} else {
|
||||
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 " +
|
||||
"the link. Contact support for troubleshooting " +
|
||||
"assistance.");
|
||||
|
@ -362,7 +365,7 @@ exports.query = function (filename, cb) {
|
|||
try {
|
||||
data = reformatData(data);
|
||||
} catch (e) {
|
||||
Logger.errlog.log(e.stack || e);
|
||||
LOGGER.error(e.stack || e);
|
||||
return cb("An unexpected error occurred while trying to process " +
|
||||
"the link. Contact support for troubleshooting " +
|
||||
"assistance.");
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
var http = require("http");
|
||||
var https = require("https");
|
||||
var cheerio = require('cheerio');
|
||||
var Logger = require("./logger.js");
|
||||
var Media = require("./media");
|
||||
var CustomEmbedFilter = require("./customembed").filter;
|
||||
var Server = require("./server");
|
||||
var Config = require("./config");
|
||||
var ffmpeg = require("./ffmpeg");
|
||||
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 GoogleDrive = require("cytube-mediaquery/lib/provider/googledrive");
|
||||
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.
|
||||
|
@ -43,7 +44,7 @@ const CONTENT_TYPES = {
|
|||
var urlRetrieve = function (transport, options, callback) {
|
||||
var req = transport.request(options, function (res) {
|
||||
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);
|
||||
callback(503, "");
|
||||
});
|
||||
|
@ -59,7 +60,7 @@ var urlRetrieve = function (transport, options, callback) {
|
|||
});
|
||||
|
||||
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);
|
||||
callback(503, "");
|
||||
});
|
||||
|
@ -512,7 +513,7 @@ var Getters = {
|
|||
if (/invalid embed/i.test(e.message)) {
|
||||
return callback(e.message);
|
||||
} else {
|
||||
Logger.errlog.log(e.stack);
|
||||
LOGGER.error(e.stack);
|
||||
return callback("Unknown error processing embed");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,8 @@ var path = require('path');
|
|||
var querystring = require('querystring');
|
||||
var crypto = require('crypto');
|
||||
|
||||
var Logger = require('./logger');
|
||||
import { LoggerFactory } from '@calzoneman/jsli';
|
||||
const LOGGER = LoggerFactory.getLogger('google2vtt');
|
||||
|
||||
function md5(input) {
|
||||
var hash = crypto.createHash('md5');
|
||||
|
@ -96,7 +97,7 @@ function handleGetSubtitles(req, res) {
|
|||
fetchSubtitles(id, lang, name, vid, fileAbsolute, function (err) {
|
||||
delete subtitleLock[fileAbsolute];
|
||||
if (err) {
|
||||
Logger.errlog.log(err.stack);
|
||||
LOGGER.error(err.stack);
|
||||
return res.sendStatus(500);
|
||||
}
|
||||
|
||||
|
@ -141,7 +142,7 @@ function fetchSubtitles(id, lang, name, vid, file, cb) {
|
|||
if (err) {
|
||||
cb(err);
|
||||
} else {
|
||||
Logger.syslog.log('Saved subtitle file ' + file);
|
||||
LOGGER.info('Saved subtitle file ' + file);
|
||||
cb();
|
||||
}
|
||||
});
|
||||
|
@ -154,19 +155,19 @@ function fetchSubtitles(id, lang, name, vid, file, cb) {
|
|||
function clearOldSubtitles() {
|
||||
fs.readdir(subtitleDir, function (err, files) {
|
||||
if (err) {
|
||||
Logger.errlog.log(err.stack);
|
||||
LOGGER.error(err.stack);
|
||||
return;
|
||||
}
|
||||
|
||||
files.forEach(function (file) {
|
||||
fs.stat(path.join(subtitleDir, file), function (err, stats) {
|
||||
if (err) {
|
||||
Logger.errlog.log(err.stack);
|
||||
LOGGER.error(err.stack);
|
||||
return;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
var sio = require("socket.io");
|
||||
var Logger = require("../logger");
|
||||
var db = require("../database");
|
||||
var User = require("../user");
|
||||
var Server = require("../server");
|
||||
|
@ -16,9 +15,12 @@ var session = require("../session");
|
|||
import counters from '../counters';
|
||||
import { verifyIPSessionCookie } from '../web/middleware/ipsessioncookie';
|
||||
import Promise from 'bluebird';
|
||||
import { LoggerFactory } from '@calzoneman/jsli';
|
||||
const verifySession = Promise.promisify(session.verifySession);
|
||||
const getAliases = Promise.promisify(db.getAliases);
|
||||
|
||||
const LOGGER = LoggerFactory.getLogger('ioserver');
|
||||
|
||||
var CONNECT_RATE = {
|
||||
burst: 5,
|
||||
sustained: 0.1
|
||||
|
@ -93,7 +95,7 @@ function throttleIP(sock) {
|
|||
}
|
||||
|
||||
if (ipThrottle[ip].throttle(CONNECT_RATE)) {
|
||||
Logger.syslog.log("WARN: IP throttled: " + ip);
|
||||
LOGGER.warn("IP throttled: " + ip);
|
||||
sock.emit("kick", {
|
||||
reason: "Your IP address is connecting too quickly. Please "+
|
||||
"wait 10 seconds before joining again."
|
||||
|
@ -225,7 +227,7 @@ function handleConnection(sock) {
|
|||
|
||||
// Check for global ban on the 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.disconnect();
|
||||
return;
|
||||
|
@ -235,7 +237,7 @@ function handleConnection(sock) {
|
|||
return;
|
||||
}
|
||||
|
||||
Logger.syslog.log("Accepted socket from " + ip);
|
||||
LOGGER.info("Accepted socket from " + ip);
|
||||
counters.add("socket.io:accept", 1);
|
||||
|
||||
addTypecheckedFunctions(sock);
|
||||
|
@ -252,7 +254,7 @@ function handleConnection(sock) {
|
|||
user.socket.emit("rank", user.account.effectiveRank);
|
||||
user.setFlag(Flags.U_LOGGED_IN);
|
||||
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);
|
||||
} else {
|
||||
user.socket.emit("rank", -1);
|
||||
|
@ -280,7 +282,7 @@ module.exports = {
|
|||
}
|
||||
var id = bind.ip + ":" + bind.port;
|
||||
if (id in bound) {
|
||||
Logger.syslog.log("[WARN] Ignoring duplicate listen address " + id);
|
||||
LOGGER.warn("Ignoring duplicate listen address " + id);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
// @flow
|
||||
|
||||
var fs = require("graceful-fs");
|
||||
var path = require("path");
|
||||
import { LoggerFactory, Logger as JsliLogger, LogLevel } from '@calzoneman/jsli';
|
||||
import { sprintf } from 'sprintf-js';
|
||||
|
||||
function getTimeString() {
|
||||
var d = new Date();
|
||||
|
@ -59,3 +63,27 @@ exports.Logger = Logger;
|
|||
exports.errlog = errlog;
|
||||
exports.syslog = syslog;
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import Logger from '../logger';
|
||||
import uuid from 'uuid';
|
||||
import { LoggerFactory } from '@calzoneman/jsli';
|
||||
|
||||
const LOGGER = LoggerFactory.getLogger('announcementrefresher');
|
||||
|
||||
var SERVER;
|
||||
const SERVER_ANNOUNCEMENTS = 'serverAnnouncements';
|
||||
|
@ -31,7 +33,7 @@ class AnnouncementRefresher {
|
|||
try {
|
||||
data = JSON.parse(message);
|
||||
} catch (error) {
|
||||
Logger.errlog.log('Unable to unmarshal server announcement: ' + error.stack
|
||||
LOGGER.error('Unable to unmarshal server announcement: ' + error.stack
|
||||
+ '\nMessage was: ' + message);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,9 @@ import Promise from 'bluebird';
|
|||
import uuid from 'uuid';
|
||||
import { runLuaScript } from 'cytube-common/lib/redis/lualoader';
|
||||
import path from 'path';
|
||||
import Logger from '../logger';
|
||||
import { LoggerFactory } from '@calzoneman/jsli';
|
||||
|
||||
const LOGGER = LoggerFactory.getLogger('partitionchannelindex');
|
||||
|
||||
var SERVER = null;
|
||||
const CHANNEL_INDEX = 'publicChannelList';
|
||||
|
@ -16,7 +18,7 @@ class PartitionChannelIndex {
|
|||
this.uid = uuid.v4();
|
||||
this.cachedList = [];
|
||||
this.redisClient.on('error', error => {
|
||||
Logger.errlog.log(`Redis error: ${error}`);
|
||||
LOGGER.error(`Redis error: ${error}`);
|
||||
});
|
||||
|
||||
process.nextTick(() => {
|
||||
|
@ -34,7 +36,7 @@ class PartitionChannelIndex {
|
|||
]).then(result => {
|
||||
this.cachedList = JSON.parse(result);
|
||||
}).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 => {
|
||||
Logger.errlog.log(`Failed to publish local channel list: ${error.stack}`);
|
||||
LOGGER.error(`Failed to publish local channel list: ${error.stack}`);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -4,10 +4,13 @@ var Config = require("./config");
|
|||
var Promise = require("bluebird");
|
||||
import * as ChannelStore from './channel-storage/channelstore';
|
||||
import { EventEmitter } from 'events';
|
||||
import { LoggerFactory } from '@calzoneman/jsli';
|
||||
|
||||
const LOGGER = LoggerFactory.getLogger('server');
|
||||
|
||||
module.exports = {
|
||||
init: function () {
|
||||
Logger.syslog.log("Starting CyTube v" + VERSION);
|
||||
LOGGER.info("Starting CyTube v%s", VERSION);
|
||||
var chanlogpath = path.join(__dirname, "../chanlogs");
|
||||
fs.exists(chanlogpath, function (exists) {
|
||||
exists || fs.mkdirSync(chanlogpath);
|
||||
|
@ -36,10 +39,7 @@ var fs = require("fs");
|
|||
var http = require("http");
|
||||
var https = require("https");
|
||||
var express = require("express");
|
||||
var Logger = require("./logger");
|
||||
var Channel = require("./channel/channel");
|
||||
var User = require("./user");
|
||||
var $util = require("./utilities");
|
||||
var db = require("./database");
|
||||
var Flags = require("./flags");
|
||||
var sio = require("socket.io");
|
||||
|
@ -129,7 +129,7 @@ var Server = function () {
|
|||
Config.get("listen").forEach(function (bind) {
|
||||
var id = bind.ip + ":" + bind.port;
|
||||
if (id in self.servers) {
|
||||
Logger.syslog.log("[WARN] Ignoring duplicate listen address " + id);
|
||||
LOGGER.warn("Ignoring duplicate listen address %s", id);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -234,7 +234,7 @@ Server.prototype.unloadChannel = function (chan, options) {
|
|||
|
||||
if (!options.skipSave) {
|
||||
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) {
|
||||
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);
|
||||
try {
|
||||
clearTimeout(chan.modules[k][prop]);
|
||||
clearInterval(chan.modules[k][prop]);
|
||||
} 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();
|
||||
// Empty all outward references from the channel
|
||||
var keys = Object.keys(chan);
|
||||
|
@ -320,22 +320,22 @@ Server.prototype.setAnnouncement = function (data) {
|
|||
};
|
||||
|
||||
Server.prototype.shutdown = function () {
|
||||
Logger.syslog.log("Unloading channels");
|
||||
LOGGER.info("Unloading channels");
|
||||
Promise.map(this.channels, channel => {
|
||||
try {
|
||||
return channel.saveState().tap(() => {
|
||||
Logger.syslog.log(`Saved /r/${channel.name}`);
|
||||
LOGGER.info(`Saved /r/${channel.name}`);
|
||||
}).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) {
|
||||
Logger.errlog.log(`Failed to save channel: ${error.stack}`);
|
||||
LOGGER.error(`Failed to save channel: ${error.stack}`);
|
||||
}
|
||||
}, { concurrency: 5 }).then(() => {
|
||||
Logger.syslog.log("Goodbye");
|
||||
LOGGER.info("Goodbye");
|
||||
process.exit(0);
|
||||
}).catch(err => {
|
||||
Logger.errlog.log(`Caught error while saving channels: ${err.stack}`);
|
||||
LOGGER.error(`Caught error while saving channels: ${err.stack}`);
|
||||
process.exit(1);
|
||||
});
|
||||
};
|
||||
|
@ -348,7 +348,7 @@ Server.prototype.handlePartitionMapChange = function () {
|
|||
}
|
||||
|
||||
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(() => {
|
||||
channel.broadcastAll("partitionChange",
|
||||
this.partitionDecider.getPartitionForChannel(channel.uniqueName));
|
||||
|
@ -361,12 +361,12 @@ Server.prototype.handlePartitionMapChange = function () {
|
|||
});
|
||||
this.unloadChannel(channel, { skipSave: true });
|
||||
}).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}`);
|
||||
});
|
||||
}
|
||||
}, { concurrency: 5 }).then(() => {
|
||||
Logger.syslog.log("Partition reload complete");
|
||||
LOGGER.info("Partition reload complete");
|
||||
});
|
||||
};
|
||||
|
||||
|
|
12
src/tor.js
12
src/tor.js
|
@ -2,7 +2,9 @@ var https = require("https");
|
|||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
var domain = require("domain");
|
||||
var Logger = require("./logger");
|
||||
import { LoggerFactory } from '@calzoneman/jsli';
|
||||
|
||||
const LOGGER = LoggerFactory.getLogger('tor');
|
||||
|
||||
function retrieveIPs(cb) {
|
||||
var options = {
|
||||
|
@ -25,9 +27,9 @@ function retrieveIPs(cb) {
|
|||
var d = domain.create();
|
||||
d.on("error", function (err) {
|
||||
if (err.stack)
|
||||
Logger.errlog.log(err.stack);
|
||||
LOGGER.error(err.stack);
|
||||
else
|
||||
Logger.errlog.log(err);
|
||||
LOGGER.error(err);
|
||||
});
|
||||
|
||||
d.run(function () {
|
||||
|
@ -66,11 +68,11 @@ function getTorIPs(cb) {
|
|||
var _ipList = [];
|
||||
getTorIPs(function (err, ips) {
|
||||
if (err) {
|
||||
Logger.errlog.log(err);
|
||||
LOGGER.error(err);
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.syslog.log("Loaded Tor IP list");
|
||||
LOGGER.info("Loaded Tor IP list");
|
||||
_ipList = ips;
|
||||
});
|
||||
|
||||
|
|
12
src/user.js
12
src/user.js
|
@ -1,13 +1,15 @@
|
|||
var Logger = require("./logger");
|
||||
var Server = require("./server");
|
||||
var util = require("./utilities");
|
||||
var db = require("./database");
|
||||
var InfoGetter = require("./get-info");
|
||||
var Config = require("./config");
|
||||
var ACP = require("./acp");
|
||||
var Account = require("./account");
|
||||
var Flags = require("./flags");
|
||||
import { EventEmitter } from 'events';
|
||||
import { LoggerFactory } from '@calzoneman/jsli';
|
||||
import Logger from './logger';
|
||||
|
||||
const LOGGER = LoggerFactory.getLogger('user');
|
||||
|
||||
function User(socket) {
|
||||
var self = this;
|
||||
|
@ -314,7 +316,7 @@ User.prototype.login = function (name, pw) {
|
|||
name: user.name
|
||||
});
|
||||
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.clearFlag(Flags.U_LOGGING_IN);
|
||||
self.emit("login", self.account);
|
||||
|
@ -392,7 +394,7 @@ User.prototype.guestLogin = function (name) {
|
|||
guest: true
|
||||
});
|
||||
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.emit("login", self.account);
|
||||
});
|
||||
|
@ -421,7 +423,7 @@ User.prototype.getFirstSeenTime = function getFirstSeenTime() {
|
|||
} else if (this.socket.ipSessionFirstSeen) {
|
||||
return this.socket.ipSessionFirstSeen.getTime();
|
||||
} 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.");
|
||||
return Date.now();
|
||||
}
|
||||
|
|
|
@ -14,6 +14,9 @@ var Server = require("../server");
|
|||
var session = require("../session");
|
||||
var csrf = require("./csrf");
|
||||
const url = require("url");
|
||||
import { LoggerFactory } from '@calzoneman/jsli';
|
||||
|
||||
const LOGGER = LoggerFactory.getLogger('database/accounts');
|
||||
|
||||
/**
|
||||
* Handles a GET request for /account/edit
|
||||
|
@ -581,7 +584,7 @@ function handlePasswordReset(req, res) {
|
|||
|
||||
Config.get("mail.nodemailer").sendMail(mail, function (err, response) {
|
||||
if (err) {
|
||||
Logger.errlog.log("mail fail: " + err);
|
||||
LOGGER.error("mail fail: " + err);
|
||||
sendPug(res, "account-passwordreset", {
|
||||
reset: false,
|
||||
resetEmail: email,
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
var pug = require("pug");
|
||||
var path = require("path");
|
||||
var webserver = require("./webserver");
|
||||
var cookieall = webserver.cookieall;
|
||||
var sendPug = require("./pug").sendPug;
|
||||
var Logger = require("../logger");
|
||||
var $util = require("../utilities");
|
||||
|
@ -16,6 +15,9 @@ var Config = require("../config");
|
|||
var url = require("url");
|
||||
var session = require("../session");
|
||||
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
|
||||
|
@ -37,7 +39,7 @@ function handleLogin(req, res) {
|
|||
var host = req.hostname;
|
||||
if (host.indexOf(Config.get("http.root-domain")) === -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import Config from '../../config';
|
||||
import CyTubeUtil from '../../utilities';
|
||||
import Logger from '../../logger';
|
||||
import * as HTTPStatus from '../httpstatus';
|
||||
import { LoggerFactory } from '@calzoneman/jsli';
|
||||
|
||||
const LOGGER = LoggerFactory.getLogger('web/routes/socketconfig');
|
||||
|
||||
export default function initialize(app, clusterClient) {
|
||||
app.get('/socketconfig/:channel.json', (req, res) => {
|
||||
|
@ -14,7 +15,7 @@ export default function initialize(app, clusterClient) {
|
|||
clusterClient.getSocketConfig(req.params.channel).then(config => {
|
||||
res.json(config);
|
||||
}).catch(err => {
|
||||
Logger.errlog.log(err.stack);
|
||||
LOGGER.error(err.stack);
|
||||
return res.status(500).json({
|
||||
error: err.message
|
||||
});
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import net from 'net';
|
||||
import express from 'express';
|
||||
import { sendPug } from './pug';
|
||||
import Logger from '../logger';
|
||||
import Config from '../config';
|
||||
import bodyParser from 'body-parser';
|
||||
import cookieParser from 'cookie-parser';
|
||||
|
@ -13,6 +11,9 @@ import csrf from './csrf';
|
|||
import * as HTTPStatus from './httpstatus';
|
||||
import { CSRFError, HTTPError } from '../errors';
|
||||
import counters from "../counters";
|
||||
import { LoggerFactory } from '@calzoneman/jsli';
|
||||
|
||||
const LOGGER = LoggerFactory.getLogger('webserver');
|
||||
|
||||
function initializeLog(app) {
|
||||
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
|
||||
if (Math.floor(status / 100) === 5) {
|
||||
Logger.errlog.log(err.stack);
|
||||
LOGGER.error(err.stack);
|
||||
}
|
||||
|
||||
res.status(status);
|
||||
|
@ -141,7 +142,7 @@ module.exports = {
|
|||
limit: '1kb' // No POST data should ever exceed this size under normal usage
|
||||
}));
|
||||
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".');
|
||||
}
|
||||
app.use(cookieParser(webConfig.getCookieSecret()));
|
||||
|
@ -154,7 +155,7 @@ module.exports = {
|
|||
app.use(require('compression')({
|
||||
threshold: webConfig.getGzipThreshold()
|
||||
}));
|
||||
Logger.syslog.log('Enabled gzip compression');
|
||||
LOGGER.info('Enabled gzip compression');
|
||||
}
|
||||
|
||||
if (webConfig.getEnableMinification()) {
|
||||
|
@ -172,7 +173,7 @@ module.exports = {
|
|||
app.use(require('express-minify')({
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue