From 07179d6c83a254e71f10d55e4db726011a6a02c6 Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Sat, 8 Jul 2017 20:11:54 -0700 Subject: [PATCH] Upgrade to jsli 2.0 --- package.json | 2 +- src/bgtask.js | 3 +-- src/camo.js | 3 +-- src/channel-storage/dbstore.js | 4 +--- src/channel/channel.js | 3 +-- src/channel/filters.js | 3 +-- src/channel/mediarefresher.js | 3 +-- src/channel/playlist.js | 3 +-- src/config.js | 3 +-- src/counters.js | 3 +-- src/database.js | 3 +-- src/database/accounts.js | 3 +-- src/database/channels.js | 3 +-- src/database/update.js | 3 +-- src/db/aliases.js | 3 +-- src/db/globalban.js | 3 +-- src/ffmpeg.js | 3 +-- src/get-info.js | 3 +-- src/google2vtt.js | 3 +-- src/io/globalban.js | 3 +-- src/io/ioserver.js | 3 +-- src/logger.js | 22 ++++++++++------------ src/partition/announcementrefresher.js | 3 +-- src/partition/partitionchannelindex.js | 3 +-- src/partition/partitionmodule.js | 3 +-- src/partition/redispartitionmapreloader.js | 3 +-- src/server.js | 3 +-- src/tor.js | 3 +-- src/user.js | 3 +-- src/web/account.js | 3 +-- src/web/auth.js | 3 +-- src/web/routes/socketconfig.js | 3 +-- src/web/webserver.js | 3 +-- 33 files changed, 42 insertions(+), 76 deletions(-) diff --git a/package.json b/package.json index c27326cf..0387969e 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ }, "license": "MIT", "dependencies": { - "@calzoneman/jsli": "^1.0.1", + "@calzoneman/jsli": "^2.0.1", "bcrypt": "^0.8.5", "bluebird": "^2.10.1", "body-parser": "^1.14.0", diff --git a/src/bgtask.js b/src/bgtask.js index c54bbe19..99e922f3 100644 --- a/src/bgtask.js +++ b/src/bgtask.js @@ -8,9 +8,8 @@ var Config = require("./config"); var db = require("./database"); var Promise = require("bluebird"); -import { LoggerFactory } from '@calzoneman/jsli'; -const LOGGER = LoggerFactory.getLogger('bgtask'); +const LOGGER = require('@calzoneman/jsli')('bgtask'); var init = null; diff --git a/src/camo.js b/src/camo.js index 23b1cc59..73fa894c 100644 --- a/src/camo.js +++ b/src/camo.js @@ -1,10 +1,9 @@ // @flow import crypto from 'crypto'; -import { LoggerFactory } from '@calzoneman/jsli'; import * as urlparse from 'url'; import { CamoConfig } from './configuration/camoconfig'; -const LOGGER = LoggerFactory.getLogger('camo'); +const LOGGER = require('@calzoneman/jsli')('camo'); function isWhitelisted(camoConfig: CamoConfig, url: string): boolean { const whitelistedDomains = camoConfig.getWhitelistedDomains(); diff --git a/src/channel-storage/dbstore.js b/src/channel-storage/dbstore.js index 4ba6b263..69f53673 100644 --- a/src/channel-storage/dbstore.js +++ b/src/channel-storage/dbstore.js @@ -1,10 +1,8 @@ import Promise from 'bluebird'; import { ChannelStateSizeError } from '../errors'; import db from '../database'; -import { LoggerFactory } from '@calzoneman/jsli'; - -const LOGGER = LoggerFactory.getLogger('dbstore'); +const LOGGER = require('@calzoneman/jsli')('dbstore'); const SIZE_LIMIT = 1048576; const QUERY_CHANNEL_DATA = 'SELECT `key`, `value` FROM channel_data WHERE channel_id = ?'; diff --git a/src/channel/channel.js b/src/channel/channel.js index a116dbb6..1d5eb35e 100644 --- a/src/channel/channel.js +++ b/src/channel/channel.js @@ -10,9 +10,8 @@ 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 LOGGER = require('@calzoneman/jsli')('channel'); const USERCOUNT_THROTTLE = 10000; diff --git a/src/channel/filters.js b/src/channel/filters.js index 68ab55e6..d11176b6 100644 --- a/src/channel/filters.js +++ b/src/channel/filters.js @@ -1,8 +1,7 @@ var FilterList = require("cytubefilters"); var ChannelModule = require("./module"); -import { LoggerFactory } from '@calzoneman/jsli'; -const LOGGER = LoggerFactory.getLogger('filters'); +const LOGGER = require('@calzoneman/jsli')('filters'); /* * Converts JavaScript-style replacements ($1, $2, etc.) with diff --git a/src/channel/mediarefresher.js b/src/channel/mediarefresher.js index 24ce11ee..aaa82261 100644 --- a/src/channel/mediarefresher.js +++ b/src/channel/mediarefresher.js @@ -2,9 +2,8 @@ var Vimeo = require("cytube-mediaquery/lib/provider/vimeo"); var ChannelModule = require("./module"); var Config = require("../config"); var InfoGetter = require("../get-info"); -import { LoggerFactory } from '@calzoneman/jsli'; -const LOGGER = LoggerFactory.getLogger('mediarefresher'); +const LOGGER = require('@calzoneman/jsli')('mediarefresher'); function MediaRefresherModule(channel) { ChannelModule.apply(this, arguments); diff --git a/src/channel/playlist.js b/src/channel/playlist.js index 2b58780f..68e5e9e8 100644 --- a/src/channel/playlist.js +++ b/src/channel/playlist.js @@ -8,9 +8,8 @@ var Flags = require("../flags"); var db = require("../database"); var CustomEmbedFilter = require("../customembed").filter; var XSS = require("../xss"); -import { LoggerFactory } from '@calzoneman/jsli'; -const LOGGER = LoggerFactory.getLogger('playlist'); +const LOGGER = require('@calzoneman/jsli')('playlist'); const MAX_ITEMS = Config.get("playlist.max-items"); // Limit requestPlaylist to once per 60 seconds diff --git a/src/config.js b/src/config.js index 1003539c..86831025 100644 --- a/src/config.js +++ b/src/config.js @@ -4,11 +4,10 @@ var nodemailer = require("nodemailer"); var net = require("net"); var YAML = require("yamljs"); -import { LoggerFactory } from '@calzoneman/jsli'; import { loadFromToml } from 'cytube-common/lib/configuration/configloader'; import { CamoConfig } from './configuration/camoconfig'; -const LOGGER = LoggerFactory.getLogger('config'); +const LOGGER = require('@calzoneman/jsli')('config'); var defaults = { mysql: { diff --git a/src/counters.js b/src/counters.js index d923b50e..3c780893 100644 --- a/src/counters.js +++ b/src/counters.js @@ -2,9 +2,8 @@ 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'); +const LOGGER = require('@calzoneman/jsli')('counters'); var counters = {}; var server = null; diff --git a/src/database.js b/src/database.js index a42e6b34..f5ec5a00 100644 --- a/src/database.js +++ b/src/database.js @@ -5,11 +5,10 @@ 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'; import knex from 'knex'; import { GlobalBanDB } from './db/globalban'; -const LOGGER = LoggerFactory.getLogger('database'); +const LOGGER = require('@calzoneman/jsli')('database'); let db = null; let globalBanDB = null; diff --git a/src/database/accounts.js b/src/database/accounts.js index bd6b6b3f..6ea1918b 100644 --- a/src/database/accounts.js +++ b/src/database/accounts.js @@ -2,9 +2,8 @@ var $util = require("../utilities"); var bcrypt = require("bcrypt"); var db = require("../database"); var Config = require("../config"); -import { LoggerFactory } from '@calzoneman/jsli'; -const LOGGER = LoggerFactory.getLogger('database/accounts'); +const LOGGER = require('@calzoneman/jsli')('database/accounts'); var registrationLock = {}; var blackHole = function () { }; diff --git a/src/database/channels.js b/src/database/channels.js index 8eb25fe7..f6f1c6ef 100644 --- a/src/database/channels.js +++ b/src/database/channels.js @@ -5,9 +5,8 @@ var path = require("path"); var tables = require("./tables"); var Flags = require("../flags"); var util = require("../utilities"); -import { LoggerFactory } from '@calzoneman/jsli'; -const LOGGER = LoggerFactory.getLogger('database/channels'); +const LOGGER = require('@calzoneman/jsli')('database/channels'); var blackHole = function () { }; diff --git a/src/database/update.js b/src/database/update.js index 04d010bc..ab355308 100644 --- a/src/database/update.js +++ b/src/database/update.js @@ -1,9 +1,8 @@ var db = require("../database"); var Q = require("q"); import Promise from 'bluebird'; -import { LoggerFactory } from '@calzoneman/jsli'; -const LOGGER = LoggerFactory.getLogger('database/update'); +const LOGGER = require('@calzoneman/jsli')('database/update'); const DB_VERSION = 11; var hasUpdates = []; diff --git a/src/db/aliases.js b/src/db/aliases.js index 03eb2eb2..f11db976 100644 --- a/src/db/aliases.js +++ b/src/db/aliases.js @@ -1,10 +1,9 @@ // @flow import { Database } from '../database'; -import { LoggerFactory } from '@calzoneman/jsli'; import net from 'net'; -const LOGGER = LoggerFactory.getLogger('AliasesDB'); +const LOGGER = require('@calzoneman/jsli')('AliasesDB'); class AliasesDB { db: Database; diff --git a/src/db/globalban.js b/src/db/globalban.js index 1605ff95..259f4460 100644 --- a/src/db/globalban.js +++ b/src/db/globalban.js @@ -1,8 +1,7 @@ -import { LoggerFactory } from '@calzoneman/jsli'; import util from '../utilities'; import Promise from 'bluebird'; -const LOGGER = LoggerFactory.getLogger('GlobalBanDB'); +const LOGGER = require('@calzoneman/jsli')('GlobalBanDB'); class GlobalBanDB { constructor(db) { diff --git a/src/ffmpeg.js b/src/ffmpeg.js index b738ba71..b98ac69c 100644 --- a/src/ffmpeg.js +++ b/src/ffmpeg.js @@ -6,9 +6,8 @@ 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'); +const LOGGER = require('@calzoneman/jsli')('ffmpeg'); var USE_JSON = true; var TIMEOUT = 30000; diff --git a/src/get-info.js b/src/get-info.js index e606130a..67acb70d 100644 --- a/src/get-info.js +++ b/src/get-info.js @@ -13,9 +13,8 @@ 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"); var TwitchClip = require("cytube-mediaquery/lib/provider/twitch-clip"); -import { LoggerFactory } from '@calzoneman/jsli'; -const LOGGER = LoggerFactory.getLogger('get-info'); +const LOGGER = require('@calzoneman/jsli')('get-info'); var urlRetrieve = function (transport, options, callback) { var req = transport.request(options, function (res) { diff --git a/src/google2vtt.js b/src/google2vtt.js index fd02ba9e..a081a086 100644 --- a/src/google2vtt.js +++ b/src/google2vtt.js @@ -5,8 +5,7 @@ var path = require('path'); var querystring = require('querystring'); var crypto = require('crypto'); -import { LoggerFactory } from '@calzoneman/jsli'; -const LOGGER = LoggerFactory.getLogger('google2vtt'); +const LOGGER = require('@calzoneman/jsli')('google2vtt'); function md5(input) { var hash = crypto.createHash('md5'); diff --git a/src/io/globalban.js b/src/io/globalban.js index 40738e95..1f38dc60 100644 --- a/src/io/globalban.js +++ b/src/io/globalban.js @@ -1,7 +1,6 @@ -import { LoggerFactory } from '@calzoneman/jsli'; import { getIPRange, getWideIPRange } from '../utilities'; -const LOGGER = LoggerFactory.getLogger('CachingGlobalBanlist'); +const LOGGER = require('@calzoneman/jsli')('CachingGlobalBanlist'); class CachingGlobalBanlist { constructor(globalBanDB) { diff --git a/src/io/ioserver.js b/src/io/ioserver.js index 86809b4b..c93067d1 100644 --- a/src/io/ioserver.js +++ b/src/io/ioserver.js @@ -15,13 +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); import { CachingGlobalBanlist } from './globalban'; import proxyaddr from 'proxy-addr'; -const LOGGER = LoggerFactory.getLogger('ioserver'); +const LOGGER = require('@calzoneman/jsli')('ioserver'); var CONNECT_RATE = { burst: 5, diff --git a/src/logger.js b/src/logger.js index 1a811871..5698e6ca 100644 --- a/src/logger.js +++ b/src/logger.js @@ -2,8 +2,9 @@ var fs = require("graceful-fs"); var path = require("path"); -import { LoggerFactory, Logger as JsliLogger, LogLevel } from '@calzoneman/jsli'; import { sprintf } from 'sprintf-js'; +import { Logger as JsliLogger, LogLevel } from '@calzoneman/jsli'; +import jsli from '@calzoneman/jsli'; function getTimeString() { var d = new Date(); @@ -65,25 +66,22 @@ exports.syslog = syslog; exports.eventlog = eventlog; class LegacyLogger extends JsliLogger { - constructor(level: LogLevel, loggerName: string) { - super(level, loggerName); + constructor(loggerName: string, level: LogLevel) { + super(loggerName, level); } - log(level: LogLevel, ...args: any[]) { - var message: string = "[" + level.name + "] " + this.loggerName + ": "; - message += sprintf(String(args[0]), ...args.slice(1)); + emitMessage(level: LogLevel, message: string) { + var output: string = `[${level.name}] ${this.loggerName}: ${message}`; if (level.shouldLogAtLevel(LogLevel.ERROR)) { - errlog.log(message); + errlog.log(output); } else { - syslog.log(message); + syslog.log(output); } } } const level: LogLevel = !!process.env.DEBUG ? LogLevel.DEBUG : LogLevel.INFO; -LoggerFactory.setLoggerImplFactory({ - getLogger(loggerName: string): LegacyLogger { - return new LegacyLogger(level, loggerName); - } +jsli.setLogBackend((loggerName) => { + return new LegacyLogger(loggerName, level); }); diff --git a/src/partition/announcementrefresher.js b/src/partition/announcementrefresher.js index 8543b3cb..e4aa7a33 100644 --- a/src/partition/announcementrefresher.js +++ b/src/partition/announcementrefresher.js @@ -1,7 +1,6 @@ import uuid from 'uuid'; -import { LoggerFactory } from '@calzoneman/jsli'; -const LOGGER = LoggerFactory.getLogger('announcementrefresher'); +const LOGGER = require('@calzoneman/jsli')('announcementrefresher'); var SERVER; const SERVER_ANNOUNCEMENTS = 'serverAnnouncements'; diff --git a/src/partition/partitionchannelindex.js b/src/partition/partitionchannelindex.js index e01ead0e..d7fa579f 100644 --- a/src/partition/partitionchannelindex.js +++ b/src/partition/partitionchannelindex.js @@ -2,9 +2,8 @@ import Promise from 'bluebird'; import uuid from 'uuid'; import { runLuaScript } from 'cytube-common/lib/redis/lualoader'; import path from 'path'; -import { LoggerFactory } from '@calzoneman/jsli'; -const LOGGER = LoggerFactory.getLogger('partitionchannelindex'); +const LOGGER = require('@calzoneman/jsli')('partitionchannelindex'); var SERVER = null; const CHANNEL_INDEX = 'publicChannelList'; diff --git a/src/partition/partitionmodule.js b/src/partition/partitionmodule.js index ab738088..60cd9019 100644 --- a/src/partition/partitionmodule.js +++ b/src/partition/partitionmodule.js @@ -3,7 +3,6 @@ import { PartitionConfig } from './partitionconfig'; import { PartitionDecider } from './partitiondecider'; import { PartitionClusterClient } from '../io/cluster/partitionclusterclient'; import RedisClientProvider from 'cytube-common/lib/redis/redisclientprovider'; -import { LoggerFactory } from '@calzoneman/jsli'; import LegacyConfig from '../config'; import path from 'path'; import { AnnouncementRefresher } from './announcementrefresher'; @@ -11,7 +10,7 @@ import { RedisPartitionMapReloader } from './redispartitionmapreloader'; const PARTITION_CONFIG_PATH = path.resolve(__dirname, '..', '..', 'conf', 'partitions.toml'); -const logger = LoggerFactory.getLogger('PartitionModule'); +const logger = require('@calzoneman/jsli')('PartitionModule'); class PartitionModule { constructor() { diff --git a/src/partition/redispartitionmapreloader.js b/src/partition/redispartitionmapreloader.js index 6dfa23db..d2b54d8d 100644 --- a/src/partition/redispartitionmapreloader.js +++ b/src/partition/redispartitionmapreloader.js @@ -1,8 +1,7 @@ import { PartitionMap } from './partitionmap'; -import { LoggerFactory } from '@calzoneman/jsli'; import { EventEmitter } from 'events'; -const logger = LoggerFactory.getLogger('RedisPartitionMapReloader'); +const logger = require('@calzoneman/jsli')('RedisPartitionMapReloader'); class RedisPartitionMapReloader extends EventEmitter { constructor(config, redisClient, subClient) { diff --git a/src/server.js b/src/server.js index ef52392a..8b4a2331 100644 --- a/src/server.js +++ b/src/server.js @@ -4,9 +4,8 @@ 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'); +const LOGGER = require('@calzoneman/jsli')('server'); module.exports = { init: function () { diff --git a/src/tor.js b/src/tor.js index 996f86ed..8909d5a0 100644 --- a/src/tor.js +++ b/src/tor.js @@ -1,12 +1,11 @@ import https from 'https'; import path from 'path'; import fs from 'fs'; -import { LoggerFactory } from '@calzoneman/jsli'; import Promise from 'bluebird'; Promise.promisifyAll(fs); -const LOGGER = LoggerFactory.getLogger('torlist'); +const LOGGER = require('@calzoneman/jsli')('torlist'); const TOR_EXIT_LIST_URL = 'https://check.torproject.org/exit-addresses'; const TOR_EXIT_LIST_FILE = path.join(__dirname, '..', 'tor-exit-list.json'); const ONE_DAY = 24 * 3600 * 1000; diff --git a/src/user.js b/src/user.js index efe33ef2..8c146973 100644 --- a/src/user.js +++ b/src/user.js @@ -6,10 +6,9 @@ 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'); +const LOGGER = require('@calzoneman/jsli')('user'); function User(socket) { var self = this; diff --git a/src/web/account.js b/src/web/account.js index d95582e1..a0bc485a 100644 --- a/src/web/account.js +++ b/src/web/account.js @@ -14,9 +14,8 @@ 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'); +const LOGGER = require('@calzoneman/jsli')('database/accounts'); /** * Handles a GET request for /account/edit diff --git a/src/web/auth.js b/src/web/auth.js index 6824efdf..434c23e1 100644 --- a/src/web/auth.js +++ b/src/web/auth.js @@ -15,9 +15,8 @@ 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'); +const LOGGER = require('@calzoneman/jsli')('web/auth'); /** * Processes a login request. Sets a cookie upon successful authentication diff --git a/src/web/routes/socketconfig.js b/src/web/routes/socketconfig.js index 9a0b4c62..8b7e5d12 100644 --- a/src/web/routes/socketconfig.js +++ b/src/web/routes/socketconfig.js @@ -1,8 +1,7 @@ import CyTubeUtil from '../../utilities'; import * as HTTPStatus from '../httpstatus'; -import { LoggerFactory } from '@calzoneman/jsli'; -const LOGGER = LoggerFactory.getLogger('web/routes/socketconfig'); +const LOGGER = require('@calzoneman/jsli')('web/routes/socketconfig'); export default function initialize(app, clusterClient) { app.get('/socketconfig/:channel.json', (req, res) => { diff --git a/src/web/webserver.js b/src/web/webserver.js index 4a6b8f2c..fda1d156 100644 --- a/src/web/webserver.js +++ b/src/web/webserver.js @@ -11,9 +11,8 @@ 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'); +const LOGGER = require('@calzoneman/jsli')('webserver'); function initializeLog(app) { const logFormat = ':real-address - :remote-user [:date] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent"';