Mail yourself a message with LOGMAIL()
LOGMAIL(email, [subject], body, [callback]) sends a message made for the developer, not for a customer: no view, no layout. The body is a text. The text goes inside a pre, in a small HTML page, so line breaks and spaces survive; it is put as it is, so do not send untrusted HTML. Without a subject the subject is the name of the application (name in the config).
Pass the body as a text. For an object use JSON.stringify(object, null, 2), as the second route below does.
It uses the same SMTP server, sender and queue as MAIL() (mail_smtp, mail_smtp_options, mail_from in the config). It is meant for things like "the import failed" with the data that you need to see.
name : Log mail example
mail_smtp : 127.0.0.1
mail_smtp_options : { port: 2527 }
mail_from : hello@example.com
mail_from_name : Exampleexports.install = function() {
ROUTE('POST /alert/ @json', alert);
ROUTE('POST /alert-object/ @json', alert_object);
ROUTE('POST /alert-raw/ @json', alert_raw);
};
function alert($) {
LOGMAIL('ops@example.com', 'Import failed', 'Line 1\nLine 2', function(err) {
$.json({ sent: !err, error: err ? err.toString() : null });
});
}
function alert_object($) {
// without a subject: the subject is the name of the application; the object is written by us
LOGMAIL('ops@example.com', JSON.stringify({ rows: 12, failed: ['a', 'b'] }, null, 2), function(err) {
$.json({ sent: !err, error: err ? err.toString() : null });
});
}
function alert_raw($) {
// the object itself: it throws in total5 0.0.19
try {
LOGMAIL('ops@example.com', { rows: 12 }, NOOP);
$.json({ thrown: false });
} catch (e) {
$.json({ thrown: true, error: e.message });
}
}