refactor: deprecate debugLogger

This commit is contained in:
Ifedapo Olarewaju 2018-12-02 22:26:52 +01:00
parent 3e6226bc15
commit 8f99463469
7 changed files with 19 additions and 42 deletions

View file

@ -400,7 +400,6 @@ class Uploader {
}
Uploader.FILE_NAME_PREFIX = 'uppy-file'
// @todo do a proper migration to change this name
Uploader.STORAGE_PREFIX = 'companion'
module.exports = Uploader

View file

@ -6,6 +6,7 @@ const tokenService = require('../helpers/jwt')
const parseUrl = require('url').parse
const { hasMatch } = require('../helpers/utils')
const oAuthState = require('../helpers/oauth-state')
const logger = require('../logger')
/**
*
@ -22,7 +23,7 @@ module.exports = function callback (req, res, next) {
// TODO see if the access_token can be transported in a different way that url query params
req.uppy.providerTokens[providerName] = req.query.access_token
req.uppy.debugLog(`Generating auth token for provider ${providerName}.`)
logger.debug(`Generating auth token for provider ${providerName}.`)
const uppyAuthToken = tokenService.generateToken(req.uppy.providerTokens, req.uppy.options.secret)
// add the token to cookies for thumbnail/image requests
tokenService.addToCookies(res, uppyAuthToken, req.uppy.options)

View file

@ -17,7 +17,7 @@ function get (req, res) {
return res.status(400).json({error: 'unable to determine file size'})
}
req.uppy.debugLog('Instantiating uploader.')
logger.debug('Instantiating uploader.')
const uploader = new Uploader({
uppyOptions: req.uppy.options,
endpoint: body.endpoint,
@ -37,10 +37,10 @@ function get (req, res) {
// wait till the client has connected to the socket, before starting
// the download, so that the client can receive all download/upload progress.
req.uppy.debugLog('Waiting for socket connection before beginning remote download.')
logger.debug('Waiting for socket connection before beginning remote download.')
// waiting for socketReady.
uploader.onSocketReady(() => {
req.uppy.debugLog('Socket connection received. Starting remote download.')
logger.debug('Socket connection received. Starting remote download.')
provider.download({ id, token, query: req.query }, uploader.handleChunk.bind(uploader))
})
const response = uploader.getResponse()

View file

@ -19,10 +19,10 @@ module.exports = () => {
* @param {object} res expressJS response object
*/
const meta = (req, res) => {
req.uppy.debugLog('URL file import handler running')
logger.debug('URL file import handler running')
if (!validator.isURL(req.body.url, { require_protocol: true, require_tld: !req.uppy.options.debug })) {
req.uppy.debugLog('Invalid request body detected. Exiting url meta handler.')
logger.debug('Invalid request body detected. Exiting url meta handler.')
return res.status(400).json({error: 'Invalid request body'})
}
@ -42,13 +42,13 @@ const meta = (req, res) => {
* @param {object} res expressJS response object
*/
const get = (req, res) => {
req.uppy.debugLog('URL file import handler running')
logger.debug('URL file import handler running')
utils.getURLMeta(req.body.url)
.then(({ size }) => {
// @ts-ignore
const { filePath } = req.uppy.options
req.uppy.debugLog('Instantiating uploader.')
logger.debug('Instantiating uploader.')
const uploader = new Uploader({
uppyOptions: req.uppy.options,
endpoint: req.body.endpoint,
@ -61,9 +61,9 @@ const get = (req, res) => {
headers: req.body.headers
})
req.uppy.debugLog('Waiting for socket connection before beginning remote download.')
logger.debug('Waiting for socket connection before beginning remote download.')
uploader.onSocketReady(() => {
req.uppy.debugLog('Socket connection received. Starting remote download.')
logger.debug('Socket connection received. Starting remote download.')
downloadURL(req.body.url, uploader.handleChunk.bind(uploader))
})

View file

@ -1,7 +1,7 @@
/**
* INFO level log
* @param {string} msg the message to log
* @param {string} tag a unique tag to easily search for this message
* @param {string=} tag a unique tag to easily search for this message
*/
exports.info = (msg, tag) => {
log(msg, tag, 'info')
@ -10,7 +10,7 @@ exports.info = (msg, tag) => {
/**
* WARN level log
* @param {string} msg the message to log
* @param {string} tag a unique tag to easily search for this message
* @param {string=} tag a unique tag to easily search for this message
*/
exports.warn = (msg, tag) => {
log(msg, tag, 'warn')
@ -19,7 +19,7 @@ exports.warn = (msg, tag) => {
/**
* ERROR level log
* @param {string | Error} msg the message to log
* @param {string} tag a unique tag to easily search for this message
* @param {string=} tag a unique tag to easily search for this message
*/
exports.error = (msg, tag) => {
log(msg, tag, 'error')
@ -28,7 +28,7 @@ exports.error = (msg, tag) => {
/**
* DEBUG level log
* @param {string} msg the message to log
* @param {string} tag a unique tag to easily search for this message
* @param {string=} tag a unique tag to easily search for this message
*/
exports.debug = (msg, tag) => {
if (process.env.NODE_ENV !== 'production') {
@ -45,5 +45,5 @@ exports.debug = (msg, tag) => {
const log = (msg, tag, level) => {
// @TODO add some colors based on log level
const time = new Date().toISOString()
console.log(`uppy: ${time} [${level}] ${tag} ${msg}`)
console.log(`uppy: ${time} [${level}] ${tag || ''} ${msg}`)
}

View file

@ -1,13 +1,14 @@
const tokenService = require('./helpers/jwt')
const logger = require('./logger')
exports.hasSessionAndProvider = (req, res, next) => {
if (!req.session || !req.body) {
req.uppy.debugLog('No session/body attached to req object. Exiting dispatcher.')
logger.debug('No session/body attached to req object. Exiting dispatcher.')
return res.sendStatus(400)
}
if (!req.uppy.provider) {
req.uppy.debugLog('No provider/provider-handler found. Exiting dispatcher.')
logger.debug('No provider/provider-handler found. Exiting dispatcher.')
return res.sendStatus(400)
}

View file

@ -182,29 +182,6 @@ const interceptGrantErrorResponse = interceptor((req, res) => {
}
})
/**
* returns a logger function, that would log a message only if
* the debug option is set to true
*
* @param {{debug: boolean}} options
* @returns {function}
*/
const getDebugLogger = (options) => {
// TODO: deprecate this.
// TODO: add line number and originating file
/**
*
* @param {string} message
*/
const conditonalLogger = (message) => {
if (options.debug) {
logger.debug(message, 'debugLog')
}
}
return conditonalLogger
}
/**
*
* @param {object} options
@ -241,7 +218,6 @@ const getOptionsMiddleware = (options) => {
options,
s3Client,
authToken: req.header('uppy-auth-token'),
debugLog: getDebugLogger(options),
buildURL: getURLBuilder(options)
}
next()