Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
@adonisjs/logger
Advanced tools
Extremely fast JSON logger built on top of pino. The module does handful of modifications to the config of pino and also exposes a fake logger to be used during tests.
Install the package from npm as follows:
npm i @adonisjs/logger
# yarn
yarn add @adonisjs/logger
and then use it as follows
import { Logger } from '@adonisjs/logger/build/standalone'
const logger = new Logger({
enabled: true,
name: 'adonis-logger',
level: 'debug',
})
logger.debug('received new request %s', request.url())
The @adonisjs/core
module includes this module by default. However, here's how you can set it up manually.
const providers = [
'@adonisjs/logger'
]
And then also register the typings file inside tsconfig.json
file.
{
"files": ["./node_modules/@adonisjs/logger/build/adonis-typings/logger.d.ts"]
}
We have changed handful of config options to make things more explicit. The modifications are based on our own opinions.
All config variables are optional in pino, however, we want to make following config options required, so that the user of the logger always knows, where the values are coming from.
Making it clear, that logger can be disabled (if required).
Seeing logs without knowing their origin isn't really helpful. We force to define the name of the application.
The level at which you want to report must be decided upfront
changeLevelName -> levelKey
Just like the messageKey
, you can define the key for showing the level number inside the logs. For some reasons pino call this option changeLevelName
, which sounds more like an action over a configuration. We have renamed the option to levelKey
.
Instead of passing the stream as the 2nd argument, you can define the custom stream within the config.
import { Logger } from '@adonisjs/logger/build/standalone'
new Logger({
stream: process.stdout,
})
Many times you would want to test whether your code is logging certain messages or not. One way is to hijack the stdout
stream and read the rows text from it.
Instead, we ship with a proper FakeLogger
that you can use during tests.
export class MyApp {
constructor (logger) {
this.logger = logger
}
perform () {
this.logger.debug('created app')
}
}
Inside your tests
import { FakeLogger } from '@adonisjs/logger/build/standalone'
import { MyApp } from './MyApp'
const logger = new FakeLogger({
// config
})
const app = new MyApp(logger)
app.perform()
assert.equal(logger.logs[0].msg, 'created app')
assert.equal(logger.logs[0].level, 20)
// Exists on fake logger only
logger.clear()
The fake logger works seamless with the child logger as well. The root logger will collect all the logs from nested child loggers.
Following are the autogenerated files via Typedoc
FAQs
Logger built on top of pino to be used by AdonisJs
The npm package @adonisjs/logger receives a total of 14,297 weekly downloads. As such, @adonisjs/logger popularity was classified as popular.
We found that @adonisjs/logger demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.