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