summaryrefslogtreecommitdiff
path: root/lib/web
diff options
context:
space:
mode:
authorSheogorath2019-06-09 13:47:32 +0200
committerGitHub2019-06-09 13:47:32 +0200
commit02929cd4bf6da3596dde33ebfd8369e0914929a5 (patch)
treed221b850be9f961f357b7592636cd35868675383 /lib/web
parent6462968e84e8d92292dd23764a9e558d7800147d (diff)
parentb5fc6db75db61d9765da38e0f085dd737380f9f4 (diff)
Merge pull request #103 from SISheogorath/feature/improve-logging
Rework debug logging
Diffstat (limited to '')
-rw-r--r--lib/web/auth/ldap/index.js4
-rw-r--r--lib/web/auth/openid/index.js4
-rw-r--r--lib/web/auth/saml/index.js4
-rw-r--r--lib/web/auth/utils.js5
-rw-r--r--lib/web/imageRouter/azure.js8
-rw-r--r--lib/web/imageRouter/filesystem.js8
-rw-r--r--lib/web/imageRouter/imgur.js12
-rw-r--r--lib/web/imageRouter/index.js7
-rw-r--r--lib/web/imageRouter/lutim.js13
-rw-r--r--lib/web/imageRouter/s3.js1
-rw-r--r--lib/web/statusRouter.js4
11 files changed, 33 insertions, 37 deletions
diff --git a/lib/web/auth/ldap/index.js b/lib/web/auth/ldap/index.js
index 77790db3..96143664 100644
--- a/lib/web/auth/ldap/index.js
+++ b/lib/web/auth/ldap/index.js
@@ -66,11 +66,11 @@ passport.use(new LDAPStrategy({
}
if (needSave) {
user.save().then(function () {
- if (config.debug) { logger.debug('user login: ' + user.id) }
+ logger.debug(`user login: ${user.id}`)
return done(null, user)
})
} else {
- if (config.debug) { logger.debug('user login: ' + user.id) }
+ logger.debug(`user login: ${user.id}`)
return done(null, user)
}
}
diff --git a/lib/web/auth/openid/index.js b/lib/web/auth/openid/index.js
index 8d271a7a..b0a28bec 100644
--- a/lib/web/auth/openid/index.js
+++ b/lib/web/auth/openid/index.js
@@ -33,11 +33,11 @@ passport.use(new OpenIDStrategy({
}
if (needSave) {
user.save().then(function () {
- if (config.debug) { logger.info('user login: ' + user.id) }
+ logger.debug(`user login: ${user.id}`)
return done(null, user)
})
} else {
- if (config.debug) { logger.info('user login: ' + user.id) }
+ logger.debug(`user login: ${user.id}`)
return done(null, user)
}
}
diff --git a/lib/web/auth/saml/index.js b/lib/web/auth/saml/index.js
index 2289b010..40a6f8b3 100644
--- a/lib/web/auth/saml/index.js
+++ b/lib/web/auth/saml/index.js
@@ -62,11 +62,11 @@ passport.use(new SamlStrategy({
}
if (needSave) {
user.save().then(function () {
- if (config.debug) { logger.debug('user login: ' + user.id) }
+ logger.debug(`user login: ${user.id}`)
return done(null, user)
})
} else {
- if (config.debug) { logger.debug('user login: ' + user.id) }
+ logger.debug(`user login: ${user.id}`)
return done(null, user)
}
}
diff --git a/lib/web/auth/utils.js b/lib/web/auth/utils.js
index ff7a1237..141a0d6f 100644
--- a/lib/web/auth/utils.js
+++ b/lib/web/auth/utils.js
@@ -1,7 +1,6 @@
'use strict'
const models = require('../../models')
-const config = require('../../config')
const logger = require('../../logger')
exports.setReturnToFromReferer = function setReturnToFromReferer (req) {
@@ -38,11 +37,11 @@ exports.passportGeneralCallback = function callback (accessToken, refreshToken,
}
if (needSave) {
user.save().then(function () {
- if (config.debug) { logger.info('user login: ' + user.id) }
+ logger.debug(`user login: ${user.id}`)
return done(null, user)
})
} else {
- if (config.debug) { logger.info('user login: ' + user.id) }
+ logger.debug(`user login: ${user.id}`)
return done(null, user)
}
}
diff --git a/lib/web/imageRouter/azure.js b/lib/web/imageRouter/azure.js
index cc98e5fc..22ee5585 100644
--- a/lib/web/imageRouter/azure.js
+++ b/lib/web/imageRouter/azure.js
@@ -7,13 +7,13 @@ const logger = require('../../logger')
const azure = require('azure-storage')
exports.uploadImage = function (imagePath, callback) {
- if (!imagePath || typeof imagePath !== 'string') {
- callback(new Error('Image path is missing or wrong'), null)
+ if (!callback || typeof callback !== 'function') {
+ logger.error('Callback has to be a function')
return
}
- if (!callback || typeof callback !== 'function') {
- logger.error('Callback has to be a function')
+ if (!imagePath || typeof imagePath !== 'string') {
+ callback(new Error('Image path is missing or wrong'), null)
return
}
diff --git a/lib/web/imageRouter/filesystem.js b/lib/web/imageRouter/filesystem.js
index 7c876d66..3ba09e88 100644
--- a/lib/web/imageRouter/filesystem.js
+++ b/lib/web/imageRouter/filesystem.js
@@ -6,13 +6,13 @@ const config = require('../../config')
const logger = require('../../logger')
exports.uploadImage = function (imagePath, callback) {
- if (!imagePath || typeof imagePath !== 'string') {
- callback(new Error('Image path is missing or wrong'), null)
+ if (!callback || typeof callback !== 'function') {
+ logger.error('Callback has to be a function')
return
}
- if (!callback || typeof callback !== 'function') {
- logger.error('Callback has to be a function')
+ if (!imagePath || typeof imagePath !== 'string') {
+ callback(new Error('Image path is missing or wrong'), null)
return
}
diff --git a/lib/web/imageRouter/imgur.js b/lib/web/imageRouter/imgur.js
index eee349f9..dcb03a7a 100644
--- a/lib/web/imageRouter/imgur.js
+++ b/lib/web/imageRouter/imgur.js
@@ -5,22 +5,20 @@ const logger = require('../../logger')
const imgur = require('imgur')
exports.uploadImage = function (imagePath, callback) {
- if (!imagePath || typeof imagePath !== 'string') {
- callback(new Error('Image path is missing or wrong'), null)
+ if (!callback || typeof callback !== 'function') {
+ logger.error('Callback has to be a function')
return
}
- if (!callback || typeof callback !== 'function') {
- logger.error('Callback has to be a function')
+ if (!imagePath || typeof imagePath !== 'string') {
+ callback(new Error('Image path is missing or wrong'), null)
return
}
imgur.setClientId(config.imgur.clientID)
imgur.uploadFile(imagePath)
.then(function (json) {
- if (config.debug) {
- logger.info('SERVER uploadimage success: ' + JSON.stringify(json))
- }
+ logger.debug(`SERVER uploadimage success: ${JSON.stringify(json)}`)
callback(null, json.data.link.replace(/^http:\/\//i, 'https://'))
}).catch(function (err) {
callback(new Error(err), null)
diff --git a/lib/web/imageRouter/index.js b/lib/web/imageRouter/index.js
index f3c2decf..0b59218b 100644
--- a/lib/web/imageRouter/index.js
+++ b/lib/web/imageRouter/index.js
@@ -21,18 +21,19 @@ imageRouter.post('/uploadimage', function (req, res) {
form.parse(req, function (err, fields, files) {
if (err || !files.image || !files.image.path) {
+ logger.error(`formidable error: ${err}`)
response.errorForbidden(res)
} else {
- if (config.debug) {
- logger.info('SERVER received uploadimage: ' + JSON.stringify(files.image))
- }
+ logger.debug(`SERVER received uploadimage: ${JSON.stringify(files.image)}`)
const uploadProvider = require('./' + config.imageUploadType)
+ logger.debug(`imageRouter: Uploading ${files.image.path} using ${config.imageUploadType}`)
uploadProvider.uploadImage(files.image.path, function (err, url) {
if (err !== null) {
logger.error(err)
return res.status(500).end('upload image error')
}
+ logger.debug(`SERVER sending ${url} to client`)
res.send({
link: url
})
diff --git a/lib/web/imageRouter/lutim.js b/lib/web/imageRouter/lutim.js
index 78b856c9..61930ad6 100644
--- a/lib/web/imageRouter/lutim.js
+++ b/lib/web/imageRouter/lutim.js
@@ -5,25 +5,24 @@ const logger = require('../../logger')
const lutim = require('lutim')
exports.uploadImage = function (imagePath, callback) {
- if (!imagePath || typeof imagePath !== 'string') {
- callback(new Error('Image path is missing or wrong'), null)
+ if (!callback || typeof callback !== 'function') {
+ logger.error('Callback has to be a function')
return
}
- if (!callback || typeof callback !== 'function') {
- logger.error('Callback has to be a function')
+ if (!imagePath || typeof imagePath !== 'string') {
+ callback(new Error('Image path is missing or wrong'), null)
return
}
if (config.lutim && config.lutim.url) {
lutim.setAPIUrl(config.lutim.url)
+ logger.debug(`Set lutim URL to ${lutim.getApiUrl()}`)
}
lutim.uploadImage(imagePath)
.then(function (json) {
- if (config.debug) {
- logger.info('SERVER uploadimage success: ' + JSON.stringify(json))
- }
+ logger.debug(`SERVER uploadimage success: ${JSON.stringify(json)}`)
callback(null, lutim.getAPIUrl() + json.msg.short)
}).catch(function (err) {
callback(new Error(err), null)
diff --git a/lib/web/imageRouter/s3.js b/lib/web/imageRouter/s3.js
index b0eca7b5..4effea04 100644
--- a/lib/web/imageRouter/s3.js
+++ b/lib/web/imageRouter/s3.js
@@ -35,6 +35,7 @@ exports.uploadImage = function (imagePath, callback) {
const mimeType = getImageMimeType(imagePath)
if (mimeType) { params.ContentType = mimeType }
+ logger.debug(`S3 object parameters: ${JSON.stringify(params)}`)
s3.putObject(params, function (err, data) {
if (err) {
callback(new Error(err), null)
diff --git a/lib/web/statusRouter.js b/lib/web/statusRouter.js
index 6f797f84..da69e62c 100644
--- a/lib/web/statusRouter.js
+++ b/lib/web/statusRouter.js
@@ -68,9 +68,7 @@ statusRouter.post('/temp', urlencodedParser, function (req, res) {
if (!data) {
response.errorForbidden(res)
} else {
- if (config.debug) {
- logger.info('SERVER received temp from [' + host + ']: ' + req.body.data)
- }
+ logger.debug(`SERVER received temp from [${host}]: ${req.body.data}`)
models.Temp.create({
data: data
}).then(function (temp) {