improve error logging

This commit is contained in:
les 2021-07-08 20:41:56 +02:00
parent 1cd43f8992
commit 9cf2b41f7c
No known key found for this signature in database
GPG key ID: 352918250B012177
14 changed files with 35 additions and 37 deletions

View file

@ -118,7 +118,7 @@ const eventController = {
order: [[Resource, 'id', 'DESC']]
})
} catch (e) {
log.error(e)
log.error('[EVENT]', e)
return res.sendStatus(400)
}
@ -194,7 +194,7 @@ const eventController = {
const notifier = require('../../notifier')
notifier.notifyEvent('Create', event.id)
} catch (e) {
log.error(e)
log.error('[EVENT]', e)
res.sendStatus(404)
}
},
@ -334,7 +334,7 @@ const eventController = {
notifier.notifyEvent('Create', event.id)
}
} catch (e) {
log.error(e)
log.error('[EVENT ADD]', e)
res.sendStatus(400)
}
},
@ -419,6 +419,7 @@ const eventController = {
}
const notifier = require('../../notifier')
await notifier.notifyEvent('Delete', event.id)
log.debug('[EVENT REMOVED]', event.title)
await event.destroy()
res.sendStatus(200)
} else {
@ -474,7 +475,8 @@ const eventController = {
{ model: Place, required: true, attributes: ['id', 'name', 'address'] }
]
}).catch(e => {
log.error(e)
log.error('[EVENT]', e)
return []
})
return events.map(e => {

View file

@ -42,7 +42,7 @@ const oauthController = {
delete client.id
res.json(client)
} catch (e) {
log.error(e)
log.error('[OAUTH CLIENT]', e)
res.status(400).json(e)
}
},

View file

@ -103,7 +103,7 @@ const settingsController = {
settingsController[is_secret ? 'secretSettings' : 'settings'][key] = value
return true
} catch (e) {
log.error(e)
log.error('[SETTING SET]', e)
return false
}
},
@ -129,7 +129,7 @@ const settingsController = {
.png({ quality: 90 })
.toFile(baseImgPath + '.png', async (err, info) => {
if (err) {
log.error(err)
log.error('[LOGO]', err)
}
const image = await readFile(baseImgPath + '.png')
const favicon = await toIco([image], { sizes: [64], resize: true })

View file

@ -103,7 +103,7 @@ const userController = {
mail.send(config.admin_email, 'admin_register', { user, config })
res.sendStatus(200)
} catch (e) {
log.error('Registration error: "%s"', e)
log.error('Registration error:', e)
res.status(404).json(e)
}
},
@ -116,7 +116,7 @@ const userController = {
mail.send(user.email, 'user_confirm', { user, config }, req.settings.locale)
res.json(user)
} catch (e) {
log.error('User creation error: %s', e)
log.error('User creation error:', e)
res.status(404).json(e)
}
},
@ -127,7 +127,7 @@ const userController = {
user.destroy()
res.sendStatus(200)
} catch (e) {
log.error('User removal error: "%s"', e)
log.error('User removal error:"', e)
res.status(404).json(e)
}
}

View file

@ -145,7 +145,7 @@ api.use((req, res) => res.sendStatus(404))
// Handle 500
api.use((error, req, res, next) => {
log.error(error)
log.error('[API ERROR]', error)
res.status(500).send('500: Internal Server Error')
})

View file

@ -61,7 +61,7 @@ const mail = {
}
return email.send(msg)
.catch(e => {
log.error('Error sending email => %s', e)
log.error('[MAIL]', e)
})
}
}

View file

@ -34,7 +34,7 @@ oauth.use((req, res) => res.sendStatus(404))
oauth.use((err, req, res, next) => {
const error_msg = err.toString()
log.error(error_msg)
log.error('[OAUTH USE]', error_msg)
res.status(500).send(error_msg)
})

View file

@ -8,9 +8,7 @@ const config = require('config')
try {
mkdirp.sync(config.upload_path + '/thumb')
} catch (e) {
log.error(e)
}
} catch (e) {}
const DiskStorage = {
_handleFile (req, file, cb) {
@ -25,11 +23,11 @@ const DiskStorage = {
let onError = false
const err = e => {
if (onError) {
log.error(err)
log.error('[UPLOAD]', err)
return
}
onError = true
log.error(e)
log.error('[UPLOAD]', e)
req.err = e
cb(null)
}

View file

@ -126,7 +126,7 @@ const Helpers = {
return res.data
})
.catch(e => {
log.error(`${URL}: ${e}`)
log.error(`get Actor ${URL}`, e)
return false
})

View file

@ -140,7 +140,7 @@ router.use((req, res) => {
// Handle 500
router.use((error, req, res, next) => {
log.error(error)
log.error('[WEBFINGER]', error)
res.status(500).send('500: Internal Server Error')
})

View file

@ -163,8 +163,8 @@ module.exports = {
}))
}
} catch (e) {
log.error(e)
res.status(400).json(e.toString)
log.error('[Import URL]', e)
res.status(400).json(e.toString())
}
},

View file

@ -1,10 +1,14 @@
const { createLogger, transports, format } = require('winston')
const DailyRotateFile = require('winston-daily-rotate-file')
const dayjs = require('dayjs')
// const dayjs = require('dayjs')
const config = require('config')
const gancioFormat = format.printf(({ timestamp, level, message, error }) => {
return `${dayjs(timestamp).format('DD MMM YYYY HH:mm:ss')} ${level}: ${message}`
const gancioFormat = format.printf(info => {
if (info.stack) {
return `${info.timestamp} ${info.level}: ${info.message} \r\n${info.stack}`
} else {
return `${info.timestamp} ${info.level}: ${info.message}`
}
})
const logger = createLogger({
@ -12,15 +16,11 @@ const logger = createLogger({
transports: process.env.NODE_ENV !== 'production'
? [new transports.Console(
{
handleExceptions: true,
handleRejections: true,
level: 'debug',
format: format.combine(format.errors({ stack: true }), format.timestamp(), format.colorize(), format.splat(), gancioFormat)
format: format.combine(format.splat(), format.timestamp(), format.colorize(), gancioFormat)
}
)]
: [new DailyRotateFile({
handleExceptions: true,
handleRejections: true,
level: config.log_level || 'info',
filename: config.log_path + '/gancio.%DATE%.log',
symlinkName: 'gancio.log',
@ -28,14 +28,12 @@ const logger = createLogger({
zippedArchive: true,
maxSize: '10m',
maxFiles: '10d',
format: format.combine(format.timestamp(), format.splat(), gancioFormat)
format: format.combine(format.timestamp(), gancioFormat)
}),
new transports.Console(
{
handleExceptions: true,
handleRejections: true,
level: config.log_level || 'info',
format: format.combine(format.timestamp(), format.splat(), format.colorize(), gancioFormat)
format: format.combine(format.timestamp(), format.colorize(), gancioFormat)
}
)]
})

View file

@ -51,7 +51,7 @@ const notifier = {
await notifier.sendNotification(notification, event)
notification.event_notification.status = 'sent'
} catch (err) {
log.error(err)
log.error('[NOTIFY EVENT]', err)
notification.event_notification.status = 'error'
}
return notification.event_notification.save()
@ -71,7 +71,7 @@ const notifier = {
e.status = 'sent'
return e.save()
} catch (err) {
log.error(err)
log.error('[NOTIFY]', err)
e.status = 'error'
e.error = err
return e.save()

View file

@ -61,7 +61,7 @@ app.use('/oauth', oauth)
// // Handle 500
app.use((error, req, res, next) => {
log.error(error)
log.error('[ERROR]', error)
res.status(500).send('500: Internal Server Error')
})