0.1.0 • Published 6 years ago

@xtrinity/simple-cluster-logger v0.1.0

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
6 years ago

simple-cluster-logger

A simple module for handling cluster logging. There are two Logger configurations: Master and Worker process loggers.

Master process loggers will print STDOUT and also save STDOUT to log files.
Worker process loggers will only save STDOUT to log files.

Logger comes ready to use with pre-defined defaults. Error reporting by SMTP does not work without a defined smtp client.

Features

  • Cluster logging
  • Saving log buffers to file
  • Alert to email (SMTP)
  • Reporting errors by email (SMTP)

Usage

Logger can be used like the following:

require Logger = require("@xtrinity/simple-cluster-logger");
logger = Logger.createLogger({
  "isMaster": true|false,
  ... logger options ...
});

// Normal logging
logger.log();
// Error logging
logger.error();

Logger Options

  • isMaster - whether or not current node process is the cluster master process. When set to true, logger.log outputs to STDOUT.

  • logger.version - the current logger package's version.

  • process.label - the process label. Defaults to "Unknown Process Label".

  • process.version - the process version. Defaults to "Unknown Process Version".

  • process.pid - the process pid on the running system. Defaults to null.

  • process.developing - if true logger.error will print to STDOUT regardless if process is a cluster master or cluster worker process.

  • logging.logFilePath - the absolute filepath to the log file.

  • logging.fileSaveInterval - the milliseconds between logBuffer saves. Logger synchronously saves buffer on errors.

  • email.smtp - the SMTP client. See below for SMTP signatures.

  • email.subjectPrefix - a prefix to include in the subject if an e-mail is sent.

  • email.reportToAddress - the e-mail address to report issues to.

SMTP

Different SMTP client modules can be supported through passing to smtp, a wrapper interface.

The wrapper interface must include the following function signature:

Example:
send([object] {
  {string} [from]: "Your Name <username@example.com>",
  {string} [to]: "Someone <someone@example.com>, Another <another@example.com>",
  {string} [cc]: "Carbon copied recipients (same format as above)",
  {string} [bcc]: "Blind carbon copied recipients (same format as above)",
  {string} [subject]: "Subject of the email",
  {string} [content-type]: "Content-type/MIME-type",
  {Array} [attachment]:    [
    {data: "<html>i <i>hope</i> this works! here is an image: <img src='cid:my-image' width='100' height ='50'> </html>"},
    {path:"path/to/file.zip", type:"application/zip", name:"renamed.zip"},
    {path:"path/to/image.jpg", type:"image/jpg", headers:{"Content-ID":"<my-image>"}}
  ]
}, {function} callback);

Available attachment options (see the emailjs module):

options = {
  {string} [path]: "Where the file is located",
  {string} [data]: "The data you want to attach",
  {Stream} [stream]: "Binary stream that will provide attachment data (must be in paused state). Better performance for binary streams if buffer.length % (76*6) == 0. Current max size of the buffer must be no larger than (76*24*7)",
  {string} [type]: "File mime-type",
  {string} [name]: "Name to give the file as perceived by the recipient",
  {string} [charset]: "Charset to encode attachment in",
  {string} [method]: "Method to send attachment as (used by calendar invites)",
  {boolean} [alternative]: "If true, will be attached inline as an alternative (defaults to type='text/html')",
  {boolean} [inline]: "If true, will be attached inline",
  {boolean} [encoded]: "Set this to true if the data is already base64 encoded, (avoid this if possible)",
  {object} [headers]: "Object containing header=>value pairs for inclusion in this attachment's header",
  {Array} {related}: "An array of attachments that you want to be related to the parent attachment"
}

Log Rotation

Log rotation can be managed by on Linux.

License

Licensed under the MIT License

0.1.0

6 years ago

0.0.1

6 years ago