Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
winston-axios
Advanced tools
Readme
An axios transport for winston which allows for sending REST requests to an external API.
const { AxiosTransport } = require('winston-axios');
or
import { AxiosTransport } from 'winston-axios';
const winston = require('winston');
const { AxiosTransport } = require('winston-axios');
const logger = winston.createLogger({
level: 'info',
format: winston.format.json(),
transports: [
new AxiosTransport({
url: 'http://localhost:9999',
path: '/log',
auth: 'abc123',
}),
],
});
const { AxiosTransport } = require('winston-axios');
logger.add(
new AxiosTransport({
host: 'http://localhost:9999/log'
})
);
You can simply use logger.info(request.body);
to log the request in the external API as Winston can resolve the body.
More information on body formatting is to come.
A production example of using this transport is available here: photoprism-helper logger.ts
Here is the relevant code, omitting anything not relevant to the transport:
import { createLogger, transports } from 'winston';
import { AxiosTransport } from 'winston-axios';
const config = {
levelConsole: 'info',
url: 'http://apiurl.com'
key: 'abc123'
}
//.code here.//
// Create a logger instance with custom settings
export const logger = createLogger({
transports: [
new transports.Console({ level: config.levelConsole }),
//.code here.//
],
//.code here.//
});
//.code here.//
// Add an Axios transport to the logger instance
logger.add(
new AxiosTransport({
url: config.url,
path: '/log',
auth: config.key,
})
);
Options for Axios Transport.
Transport for Winston that sends log messages to a remote server using Axios.
Options for Axios Transport.
Param | Type | Description |
---|---|---|
url | string | The url to send the logs to. |
path | string | The path to send the logs to. The destination url will resolve to url + path. |
auth | string | The authentication token to send with the logs. Will override any auth headers provided in headers. |
authType | TransportAuthType | The type of authentication to use. |
method | TransportMethod | The method to use when sending the logs. |
headers | AxiosRequestHeaders | The headers to send with the logs. |
Transport for Winston that sends log messages to a remote server using Axios.
Param | Type | Description |
---|---|---|
options | AxiosTransportOptions | The options for the transport. |
Example
const logger = createLogger({
transports: [
new AxiosTransport({
url: 'http://localhost:3000',
path: '/logs',
}),
],
});
logger.log({ level: 'info', message: 'Hello World' });
FAQs
An axios transport for winston which allows for sending REST requests to an external API
The npm package winston-axios receives a total of 12 weekly downloads. As such, winston-axios popularity was classified as not popular.
We found that winston-axios demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.