diff --git a/server/api/controller/event.js b/server/api/controller/event.js index d9fb5986..096a020e 100644 --- a/server/api/controller/event.js +++ b/server/api/controller/event.js @@ -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 => { diff --git a/server/api/controller/oauth.js b/server/api/controller/oauth.js index c792ae81..0822e66f 100644 --- a/server/api/controller/oauth.js +++ b/server/api/controller/oauth.js @@ -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) } }, diff --git a/server/api/controller/settings.js b/server/api/controller/settings.js index 7a80a24e..0f15d797 100644 --- a/server/api/controller/settings.js +++ b/server/api/controller/settings.js @@ -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 }) diff --git a/server/api/controller/user.js b/server/api/controller/user.js index a8d1ada0..dd5d3107 100644 --- a/server/api/controller/user.js +++ b/server/api/controller/user.js @@ -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) } } diff --git a/server/api/index.js b/server/api/index.js index f971a01c..1e64001e 100644 --- a/server/api/index.js +++ b/server/api/index.js @@ -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') }) diff --git a/server/api/mail.js b/server/api/mail.js index 5e1302aa..105e68ca 100644 --- a/server/api/mail.js +++ b/server/api/mail.js @@ -61,7 +61,7 @@ const mail = { } return email.send(msg) .catch(e => { - log.error('Error sending email => %s', e) + log.error('[MAIL]', e) }) } } diff --git a/server/api/oauth.js b/server/api/oauth.js index 9a4dbc28..0f1dd709 100644 --- a/server/api/oauth.js +++ b/server/api/oauth.js @@ -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) }) diff --git a/server/api/storage.js b/server/api/storage.js index 34aa1f29..e44f7d8f 100644 --- a/server/api/storage.js +++ b/server/api/storage.js @@ -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) } diff --git a/server/federation/helpers.js b/server/federation/helpers.js index 5c9f7931..a08463fb 100644 --- a/server/federation/helpers.js +++ b/server/federation/helpers.js @@ -126,7 +126,7 @@ const Helpers = { return res.data }) .catch(e => { - log.error(`${URL}: ${e}`) + log.error(`get Actor ${URL}`, e) return false }) diff --git a/server/federation/webfinger.js b/server/federation/webfinger.js index d833995f..8390aed6 100644 --- a/server/federation/webfinger.js +++ b/server/federation/webfinger.js @@ -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') }) diff --git a/server/helpers.js b/server/helpers.js index 3666ffe5..a9675809 100644 --- a/server/helpers.js +++ b/server/helpers.js @@ -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()) } }, diff --git a/server/log.js b/server/log.js index 4a4dd824..b4aaf0be 100644 --- a/server/log.js +++ b/server/log.js @@ -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) } )] }) diff --git a/server/notifier.js b/server/notifier.js index ac105aab..6405a797 100644 --- a/server/notifier.js +++ b/server/notifier.js @@ -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() diff --git a/server/routes.js b/server/routes.js index 20ab4eee..4bfa6f4e 100644 --- a/server/routes.js +++ b/server/routes.js @@ -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') })