Product
Socket Now Supports uv.lock Files
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
log4js-node-amqp
Advanced tools
An AMQP appender for log4js-node
npm install log4js-node-amqp
Configure in code:
var log4js = require('log4js');
var amqpAppender = require('log4js-node-amqp');
log4js.addAppender(
amqpAppender.appender({
// more config options available
connection: {
url: "amqp://guest:guest@localhost:5672"
},
// this is a space for you to add custom bits to every log message
additionalInfo: {
machine: require("os").hostname(),
applicationName: 'example application'
}
}),
'amqp-example'
);
or configure via configure()
You could also require()
a config .json or .js file here, any Javascript object will work with log4js.
log4js.configure({
appenders: [
{
type: 'console'
},
{
type: 'log4js-node-amqp',
connection: {
url: "amqp://guest:guest@localhost:5672"
},
// this is a space for you to add custom bits to every log message
additionalInfo: {
machine: require("os").hostname(),
applicationName: 'example application'
}
category: 'amqp-example'
}
]
});
Log things:
var logger = log4js.getLogger('amqp-example');
// strings work
logger.info('a string of log data.');
// so do objects
logger.info({name: 'a string', type: 'a silly example'});
You can also have a look at the example.
This is a log4js appender which uses the awesome node-amqp package and shares a good bit of config with it.
{
// see https://github.com/postwait/node-amqp#connection
connection: {
url: "amqp://guest:guest@localhost:5672",
clientProperties: {
product: 'log4js'
}
},
// see https://github.com/postwait/node-amqp#connectionexchange
exchange: {
name: 'logExchange',
type: 'fanout',
durable: true,
autoDelete: false
},
// see https://github.com/postwait/node-amqp#queue - specifying a queue is optional, if you don't
// specify one, logs will be published to the exchange. If you do specify a queue, it will be
// automatically created and bound to the exchange.
queue: {
name: 'logQ',
durable: true,
autoDelete: false
},
// see https://github.com/postwait/node-amqp#exchangepublishroutingkey-message-options-callback
publish: {
mandatory: true,
deliveryMode: 2, // persistent
routingKey: 'msg'
},
// interval at which to flush messages to the queue, 0 means "immediate"
sendInterval: 0,
// a log4js layout, this is ignored if the logged item is an object
layout: log4js.layouts.messagePassThroughLayout,
// this is a space for you to add custom bits to every log message
additionalInfo: {
//
},
// if you'd like to alter the logEvent before it's sent to the exchange
logEventInterceptor: function(logEvent, additionalInfo) {
//
}
}
// Everything log4js provides, + whatever you added to additionalInfo
// (keys in additionalInfo are added as keys to the log message).
{
timestamp: Fri Dec 20 2013 20:54:22 GMT-0800 (PST),
data: 'test-message',
level: { level: 20000, levelStr: 'INFO' },
category: 'test'
}
// if you specified a logEventInterceptor in options,
// then whatever logEventInterceptor returns will be sent, e.g.:
log4js.configure({
appenders: [
{
type: 'log4js-node-amqp',
// more config here
logEventInterceptor: function(logEvent, additionalInfo) {
return (logEvent.data || {}).message; // send a simple string to the exchange
}
}
]
});
If you want some ideas on how to read things from the log queue, have a look at this simple log reader example.
Copyright (c) 2015 Max Nachlinger
FAQs
An AMQP appender for log4js-node
The npm package log4js-node-amqp receives a total of 2 weekly downloads. As such, log4js-node-amqp popularity was classified as not popular.
We found that log4js-node-amqp 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.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.