improve logging
This commit is contained in:
@@ -17,7 +17,7 @@ const announceController = {
|
||||
announcement: req.body.announcement,
|
||||
visible: true
|
||||
}
|
||||
log.debug('Create announcement ', req.body.title)
|
||||
log.info('Create announcement: "%s" ', req.body.title)
|
||||
const announce = await Announcement.create(announcementDetail)
|
||||
res.json(announce)
|
||||
},
|
||||
@@ -34,20 +34,20 @@ const announceController = {
|
||||
announce = await announce.update(announceDetails)
|
||||
res.json(announce)
|
||||
} catch (e) {
|
||||
log.debug('Toggle announcement failed ', e)
|
||||
log.error('Toggle announcement failed: %s ', e)
|
||||
res.sendStatus(404)
|
||||
}
|
||||
},
|
||||
|
||||
async remove (req, res) {
|
||||
log.debug('Remove announcement ', req.params.announce_id)
|
||||
log.info('Remove announcement "%d"', req.params.announce_id)
|
||||
const announce_id = req.params.announce_id
|
||||
try {
|
||||
const announce = await Announcement.findByPk(announce_id)
|
||||
await announce.destroy()
|
||||
res.sendStatus(200)
|
||||
} catch (e) {
|
||||
log.debug('Remove announcement failed ', e)
|
||||
log.error('Remove announcement failed: "%s" ', e)
|
||||
res.sendStatus(404)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,12 +118,12 @@ const eventController = {
|
||||
order: [[Resource, 'id', 'DESC']]
|
||||
})
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
log.error(e)
|
||||
return res.sendStatus(400)
|
||||
}
|
||||
|
||||
if (!event) {
|
||||
return res.sendStatus(400)
|
||||
return res.sendStatus(404)
|
||||
}
|
||||
|
||||
// get prev and next event
|
||||
@@ -147,6 +147,7 @@ const eventController = {
|
||||
order: [['start_datetime', 'DESC']]
|
||||
})
|
||||
|
||||
// TODO: also check if event is mine
|
||||
if (event && (event.is_visible || is_admin)) {
|
||||
event = event.get()
|
||||
event.next = next && (next.slug || next.id)
|
||||
|
||||
@@ -61,7 +61,7 @@ const settingsController = {
|
||||
|
||||
// add pub/priv instance key if needed
|
||||
if (!settingsController.settings.publicKey) {
|
||||
log.debug('Instance priv/pub key not found')
|
||||
log.info('Instance priv/pub key not found, generating....')
|
||||
const { publicKey, privateKey } = await generateKeyPair('rsa', {
|
||||
modulusLength: 4096,
|
||||
publicKeyEncoding: {
|
||||
@@ -92,7 +92,7 @@ const settingsController = {
|
||||
},
|
||||
|
||||
async set (key, value, is_secret = false) {
|
||||
log.debug(`SET ${key} ${value}`)
|
||||
log.info(`SET ${key} ${value}`)
|
||||
try {
|
||||
const [setting, created] = await Setting.findOrCreate({
|
||||
where: { key },
|
||||
@@ -115,7 +115,8 @@ const settingsController = {
|
||||
|
||||
setLogo (req, res) {
|
||||
if (!req.file) {
|
||||
return res.status(400).send('Mmmmm sould not be here!')
|
||||
settingsController.set('logo', false)
|
||||
return res.status(200)
|
||||
}
|
||||
|
||||
const uploadedPath = path.join(req.file.destination, req.file.filename)
|
||||
|
||||
@@ -96,13 +96,14 @@ const userController = {
|
||||
return res.status(404).json('Invalid email')
|
||||
}
|
||||
|
||||
log.debug('Register user ', req.body.email)
|
||||
log.info('Register user ', req.body.email)
|
||||
const user = await User.create(req.body)
|
||||
log.debug(`Sending registration email to ${user.email}`)
|
||||
log.info(`Sending registration email to ${user.email}`)
|
||||
mail.send(user.email, 'register', { user, config }, req.settings.locale)
|
||||
mail.send(config.admin_email, 'admin_register', { user, config })
|
||||
res.sendStatus(200)
|
||||
} catch (e) {
|
||||
log.error('Registration error: "%s"', e)
|
||||
res.status(404).json(e)
|
||||
}
|
||||
},
|
||||
@@ -115,6 +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)
|
||||
res.status(404).json(e)
|
||||
}
|
||||
},
|
||||
@@ -125,6 +127,7 @@ const userController = {
|
||||
user.destroy()
|
||||
res.sendStatus(200)
|
||||
} catch (e) {
|
||||
log.error('User removal error: "%s"', e)
|
||||
res.status(404).json(e)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ const mail = {
|
||||
},
|
||||
|
||||
_send (addresses, template, locals, locale) {
|
||||
log.debug(`Send ${template} email to ${addresses} with locale ${locale}`)
|
||||
log.info(`Send ${template} email to ${addresses} with locale ${locale}`)
|
||||
const email = new Email({
|
||||
views: { root: path.join(__dirname, '..', 'emails') },
|
||||
htmlToText: true,
|
||||
@@ -61,8 +61,7 @@ const mail = {
|
||||
}
|
||||
return email.send(msg)
|
||||
.catch(e => {
|
||||
log.error('Error sending email =>')
|
||||
log.error(e)
|
||||
log.error('Error sending email => %s', e)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ oauth.use((req, res) => res.sendStatus(404))
|
||||
|
||||
oauth.use((err, req, res, next) => {
|
||||
const error_msg = err.toString()
|
||||
log.debug(error_msg)
|
||||
log.error(error_msg)
|
||||
res.status(500).send(error_msg)
|
||||
})
|
||||
|
||||
|
||||
@@ -282,6 +282,8 @@ If this is your first run use 'gancio setup --config <CONFIG_FILE.json>' `)
|
||||
}
|
||||
const config = require('config')
|
||||
await run_migrations(config.db)
|
||||
consola.info(`Logging to ${path.resolve('./logs/gancio.log')} [level: ${config.loglevel}]`)
|
||||
|
||||
require('./index')
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ module.exports = {
|
||||
async boost (req, res) {
|
||||
const match = req.body.object.match(`${config.baseurl}/federation/m/(.*)`)
|
||||
if (!match || match.length < 2) { return res.status(404).send('Event not found!') }
|
||||
log.debug(`boost ${match[1]}`)
|
||||
log.info(`boost ${match[1]}`)
|
||||
const event = await Event.findByPk(Number(match[1]))
|
||||
if (!event) { return res.status(404).send('Event not found!') }
|
||||
// TODO, has to be unique...
|
||||
@@ -17,7 +17,7 @@ module.exports = {
|
||||
async unboost (req, res) {
|
||||
const match = req.body.object.match(`${config.baseurl}/federation/m/(.*)`)
|
||||
if (!match || match.length < 2) { return res.status(404).send('Event not found!') }
|
||||
log.debug(`unboost ${match[1]}`)
|
||||
log.info(`unboost ${match[1]}`)
|
||||
const event = await Event.findByPk(Number(match[1]))
|
||||
if (!event) { return res.status(404).send('Event not found!') }
|
||||
await event.update({ boost: event.boost.filter(actor => actor !== req.body.actor) })
|
||||
@@ -27,7 +27,7 @@ module.exports = {
|
||||
const match = req.body.object.match(`${config.baseurl}/federation/m/(.*)`)
|
||||
if (!match || match.length < 2) { return res.status(404).send('Event not found!') }
|
||||
const event = await Event.findByPk(Number(match[1]))
|
||||
log.debug(`${req.body.actor} bookmark ${event.title} (${event.likes.length})`)
|
||||
log.info(`${req.body.actor} bookmark ${event.title} (${event.likes.length})`)
|
||||
if (!event) { return res.status(404).send('Event not found!') }
|
||||
// TODO: has to be unique
|
||||
await event.update({ likes: [...event.likes, req.body.actor] })
|
||||
@@ -40,7 +40,7 @@ module.exports = {
|
||||
const match = object.object.match(`${config.baseurl}/federation/m/(.*)`)
|
||||
if (!match || match.length < 2) { return res.status(404).send('Event not found!') }
|
||||
const event = await Event.findByPk(Number(match[1]))
|
||||
log.debug(`${body.actor} unbookmark ${event.title} (${event.likes.length})`)
|
||||
log.info(`${body.actor} unbookmark ${event.title} (${event.likes.length})`)
|
||||
if (!event) { return res.status(404).send('Event not found!') }
|
||||
await event.update({ likes: event.likes.filter(actor => actor !== body.actor) })
|
||||
res.sendStatus(201)
|
||||
|
||||
@@ -7,7 +7,6 @@ module.exports = {
|
||||
// follow request from fediverse
|
||||
async follow (req, res) {
|
||||
const body = req.body
|
||||
log.debug('follow')
|
||||
if (typeof body.object !== 'string') { return }
|
||||
const username = body.object.replace(`${config.baseurl}/federation/u/`, '')
|
||||
if (username !== req.settings.instance_name) {
|
||||
@@ -20,7 +19,7 @@ module.exports = {
|
||||
// await user.addFollowers([req.fedi_user.id])
|
||||
// await user.update({ followers: [...user.followers, body.actor] })
|
||||
await req.fedi_user.update({ follower: true })
|
||||
log.debug(`Followed by ${body.actor}`)
|
||||
log.info(`Followed by ${body.actor}`)
|
||||
const guid = crypto.randomBytes(16).toString('hex')
|
||||
const message = {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
@@ -43,11 +42,11 @@ module.exports = {
|
||||
}
|
||||
|
||||
if (body.actor !== body.object.actor || body.actor !== req.fedi_user.ap_id) {
|
||||
log.debug('Unfollow an user created by a different actor !?!?')
|
||||
log.info('Unfollow an user created by a different actor !?!?')
|
||||
return res.status(400).send('Bad things')
|
||||
}
|
||||
await req.fedi_user.update({ follower: false })
|
||||
log.debug(`Unfollowed by ${body.actor}`)
|
||||
log.info(`Unfollowed by ${body.actor}`)
|
||||
res.sendStatus(200)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ const Helpers = {
|
||||
|
||||
async sendEvent (event, type = 'Create') {
|
||||
if (!settingsController.settings.enable_federation) {
|
||||
log.debug('event not send, federation disabled')
|
||||
log.info('event not send, federation disabled')
|
||||
return
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ const Helpers = {
|
||||
})
|
||||
|
||||
if (fedi_user) {
|
||||
log.debug(`Create a new AP User => ${URL}`)
|
||||
log.info(`Create a new AP User => ${URL}`)
|
||||
fedi_user = await APUser.create({ ap_id: URL, object: fedi_user })
|
||||
}
|
||||
return fedi_user
|
||||
@@ -208,13 +208,13 @@ const Helpers = {
|
||||
// signature not valid, try without cache
|
||||
user = await Helpers.getActor(req.body.actor, instance, true)
|
||||
if (!user) {
|
||||
log.debug(`Actor ${req.body.actor} not found`)
|
||||
log.info(`Actor ${req.body.actor} not found`)
|
||||
return res.status(401).send('Actor not found')
|
||||
}
|
||||
if (httpSignature.verifySignature(parsed, user.object.publicKey.publicKeyPem)) { return next() }
|
||||
|
||||
// still not valid
|
||||
log.debug(`Invalid signature from user ${req.body.actor}`)
|
||||
log.info(`Invalid signature from user ${req.body.actor}`)
|
||||
res.send('Request signature could not be verified', 401)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ async function main () {
|
||||
try {
|
||||
await nuxt.listen()
|
||||
} catch (e) {
|
||||
log.err(e)
|
||||
log.error(e)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,35 @@
|
||||
const { createLogger, transports, format } = require('winston')
|
||||
const DailyRotateFile = require('winston-daily-rotate-file')
|
||||
const dayjs = require('dayjs')
|
||||
const config = require('config')
|
||||
|
||||
const gancioFormat = format.printf(({ timestamp, level, message }) => {
|
||||
return `${dayjs(timestamp).format('DD MMM YYYY HH:mm:ss')} ${level}: ${message}`
|
||||
})
|
||||
|
||||
const logger = createLogger({
|
||||
exitOnError: false,
|
||||
transports: process.env.NODE_ENV !== 'production'
|
||||
? [new transports.Console(
|
||||
{ level: 'debug', format: format.combine(format.colorize(), format.simple(), format.errors({ stack: true })) }
|
||||
)]
|
||||
: [new transports.File(
|
||||
{
|
||||
filename: 'gancio.log',
|
||||
format: format.combine(format.simple(), format.errors({ stack: true }))
|
||||
handleExceptions: true,
|
||||
handleRejections: true,
|
||||
level: 'debug',
|
||||
format: format.combine(format.timestamp(), format.splat(), format.colorize(), gancioFormat)
|
||||
}
|
||||
)]
|
||||
: [new DailyRotateFile({
|
||||
handleExceptions: true,
|
||||
handleRejections: true,
|
||||
level: config.loglevel || 'info',
|
||||
filename: './logs/gancio.%DATE%.log',
|
||||
symlinkName: 'gancio.log',
|
||||
createSymlink: true,
|
||||
zippedArchive: true,
|
||||
maxSize: '10m',
|
||||
maxFiles: '14d',
|
||||
format: format.combine(format.timestamp(), format.splat(), gancioFormat)
|
||||
})]
|
||||
})
|
||||
|
||||
module.exports = logger
|
||||
|
||||
@@ -16,7 +16,7 @@ const notifier = {
|
||||
|
||||
sendNotification (notification, event) {
|
||||
const promises = []
|
||||
log.debug(`Send ${notification.type} notification ${notification.action}`)
|
||||
log.info(`Send ${notification.type} notification ${notification.action}`)
|
||||
let p
|
||||
switch (notification.type) {
|
||||
// case 'mail': TODO: locale?
|
||||
|
||||
@@ -28,11 +28,11 @@ class Task {
|
||||
try {
|
||||
const ret = this.method.apply(this, this.args)
|
||||
if (ret && typeof ret.then === 'function') {
|
||||
ret.catch(e => log.error('TASK ERROR ', this.name, e))
|
||||
ret.catch(e => log.error('TASK ERROR [%s]: %s', this.name, e))
|
||||
return ret
|
||||
}
|
||||
} catch (e) {
|
||||
log.error('TASK ERROR ', this.name, e)
|
||||
log.error('TASK ERROR [%s]: %s ', this.name, e)
|
||||
return Promise.resolve(false)
|
||||
}
|
||||
}
|
||||
@@ -62,14 +62,14 @@ class TaskManager {
|
||||
|
||||
stop () {
|
||||
if (this.timeout) {
|
||||
log.debug('STOP TASKMANAGER')
|
||||
log.info('STOP TASKMANAGER')
|
||||
clearTimeout(this.timeout)
|
||||
this.timeout = false
|
||||
}
|
||||
}
|
||||
|
||||
add (task) {
|
||||
log.debug(`[TASK] Add ${task.name} (${task.repeatDelay * this.interval} seconds)`)
|
||||
log.info(`[TASK] Add ${task.name} (${task.repeatDelay * this.interval} seconds)`)
|
||||
this.tasks.push(task)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user