Easy to use logging
npm i --save agathias
- Simple Case
const logger = require('agathias')
logger.info('Hello')
logger.debug('World')
- Simple Case w/ config
const logger = require('agathias')
const config = {
appName: 'Simple App'
}
logger
.init(config)
.then(() => logger.debug('Hello'))
.catch(console.error)
- File Case
const logger = require('agathias')
const config = {
file: true,
fileName: 'my-app-file-case.log',
logDir: '/tmp', // Path must have an absolute value, you can use __dirname
}
logger
.init(config)
.then(() => logger.debug('Hello'))
.catch(console.error)
- Middleware Case (ExpressJS)
const http = require('http')
const express = require('express')
const logger = require('agathias')
const app = express()
logger
.init({
logDir: '/tmp'
})
.then(() => {
app.use(logger.getMiddleware(true))
app.get('/', (req, res) => res.send('Hello World'))
let server = app.listen(process.env.PORT || 5000)
http.get('http://0.0.0.0:5000/no', (res) => {
let data = ''
res.on('data', (chunk) => data += chunk)
res.on('end', () => server.close())
})
})
.catch(console.error)
- Group logs by 'children'
const logger = require('agathias')
logger
.init()
.then(() => {
logger.debug('Hello')
const childNode1 = logger.getChild('testing')
childNode1.debug('Hello')
const childNode2 = logger.getChild('this is real')
childNode2.debug('World')
})
.catch(console.error)
- Seamless integration with log rotate
- Optional express logging