feat(xo-server): use object to configure log transports
Follow-up of 756d2fe4e
This commit is contained in:
@@ -140,6 +140,8 @@ port = 80
|
||||
# Display all logs with level >=, regardless of their namespace
|
||||
level = 'info'
|
||||
|
||||
[logs.transport.console]
|
||||
|
||||
[plugins]
|
||||
|
||||
[remoteOptions]
|
||||
|
||||
@@ -145,6 +145,12 @@ port = 80
|
||||
|
||||
#=====================================================================
|
||||
|
||||
# Uncomment this section to export the logs to an external syslog
|
||||
#[log.transport.syslog]
|
||||
#target = 'tcp://syslog.company.lan:514'
|
||||
|
||||
#=====================================================================
|
||||
|
||||
# Connection to the Redis server.
|
||||
[redis]
|
||||
# Unix sockets can be used
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import transportConsole from '@xen-orchestra/log/transports/console.js'
|
||||
import { configure } from '@xen-orchestra/log/configure.js'
|
||||
import { defer, fromEvent } from 'promise-toolbox'
|
||||
|
||||
@@ -10,15 +9,20 @@ export default class Logs {
|
||||
|
||||
app.hooks.on('clean', () => this._gc())
|
||||
|
||||
const defaultTransport = transportConsole()
|
||||
app.config.watch('logs', ({ filter, level, transport = defaultTransport }) => {
|
||||
configure([
|
||||
{
|
||||
filter: [process.env.DEBUG, filter],
|
||||
level,
|
||||
transport,
|
||||
},
|
||||
])
|
||||
app.config.watch('logs', ({ filter, level, transport: transportsObject }) => {
|
||||
const transports = []
|
||||
for (const id of Object.keys(transportsObject)) {
|
||||
const { disabled = false, ...transport } = transportsObject[id]
|
||||
if (!disabled) {
|
||||
transports.push({ type: id, ...transport })
|
||||
}
|
||||
}
|
||||
|
||||
configure({
|
||||
filter: [process.env.DEBUG, filter],
|
||||
level,
|
||||
transport: transports,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user