1.0.1 • Published 8 years ago
pino-mq v1.0.1
pino-mq
Pino-mq will take all messages received on process.stdin and send them over a message bus using JSON serialization;
Installation
npm install -g pino-mqQuick Example
node app.js | pino-mq -u "amqp://guest:guest@localhost/" -q "pino-logs"Command line switches
--type(-t): MQ type of transport to be used (default 'RABBITMQ')--uri(-u): uri for connecting to MQ broker--queue(-q): queue to be used for sending messages--queuePattern(-qp): queuePattern to be used for sending messages--fields(-f): comma separated fields for filtering messages before sending--exchange(-e): exchange name to be used in case of rabbitmq transport--config(-c): path to config file (JSON); switches take precedence--generateConfig(-g): create pino-mq.json config file with default options--help(-h): display help--version(-v): display version
Configuration JSON File
by using --generateConfig it will create pino-mq.json file with all available configuration
options; queueMap option is available only in configuration json file;
{
"type": "RABBITMQ",
"uri": "amqp://guest:guest@localhost/",
"exchange": "",
"queue": "pino-mq",
"queuePattern": null,
"queueMap": null,
"fields": []
}Broker connection
urioption will follow URI specification for defining connection to a host:<protocol>://[user[:password]@]host[:port][/path][?query]where
protocol,pathandfragmentwill be specific for each type of broker
Queues configuration
queue configuration has a priority in defining behaviour for pino-mq; if more than one is specified, configuration will take this precedence:
queueall messages will be sent on this queuequeuePatternall messages will be sent on queue based on their message level; corespondig queue will be<queuePattern><messageLevel>:- ex:
message:queuePattern: 'pino-mq-
will be routed to{"pid":25793,"hostname":"localhost.localdomain","level":50,"time":1503252634289,"msg":"msg3","v":1}pino-mq-50queue;
- ex:
queueMapoption allows you to specify specific queues based on their message level:
all info messages will be sent onqueueMap: { default: 'pino-mq-default', '30': 'infoMessages', '40': 'warnMessages', '50': 'errorMessages', }infoMessagesqueue, warn onwarnMessagesand errors onerrorMessages;defaultoption will match any other messages where their level will not match anything in the map; this key is mandatory;
RabbitMQ specific options
For RabbitMQ type there is an extra option:
--exchange: if you want to use a specific exchange for your queues or you want to use topics instead of queues than you have to pass it to pino-mq configuration; topics are a more powerful distribution mechanism than queues and explaining it is beyond the scope of this module (RabbitMQ Topics tutorial)
Fields filtering
in case is needed to filter log messages fields you can use fields option:
- from command line:
--fields "time,level,msg"
- from configuration json file:
"fields":["time","level","msg"]
TODO
- add Redis transport
- add NATS transport
- add documentation on how to use this module as dependency
LICENSE
1.0.1
8 years ago