winston-mail
Advanced tools
Comparing version 1.4.0 to 1.5.0
@@ -0,1 +1,6 @@ | ||
# 1.5.0 / 2018-03-07 | ||
- Support for Winston 3.0 [bcosma] | ||
# 1.4.0 / 2018-01-26 | ||
@@ -2,0 +7,0 @@ |
@@ -21,2 +21,4 @@ /* | ||
winston.Transport.call(this, options); | ||
if (!options.to) { | ||
@@ -63,9 +65,34 @@ throw new Error("winston-mail requires 'to' property") | ||
* @member Mail | ||
* @param level {string} Level at which to log the message. | ||
* @param msg {string} Message to log. | ||
* @param meta {?Object} Additional metadata to attach. | ||
* @param callback {function} Continuation to respond to when complete. | ||
* @param arg0 winston < 3 {string} Level at which to log the message. | ||
winston >= 3 {Object} {level, message, meta} Info about log | ||
* @param arg1 winston < 3 {string} Message to log. | ||
winston >= 3 {function} Continuation to respond to when complete. | ||
* @param arg2 winston < 3 {?Object} Additional metadata to attach. | ||
winston >= 3 undefined | ||
* @param arg3 winston < 3 {function} Continuation to respond to when complete. | ||
winston >= 3 undefined | ||
*/ | ||
Mail.prototype.log = function(level, msg, meta, callback) { | ||
var self = this | ||
Mail.prototype.log = function(arg0, arg1, arg2, arg3) { | ||
// get winston version to create tests accordingly | ||
var winstonVersion = winston.version, | ||
majorWVersion = winstonVersion.split('.')[0], | ||
self = this; | ||
var callback, level, msg, meta; | ||
if (majorWVersion >= 3 ) { | ||
// in version above 3 we have only 2 parameters: info and callback; | ||
var info = arg0; | ||
callback = arg1; | ||
level = info.level; | ||
msg = info.message || ''; | ||
meta = info.meta; | ||
} else { | ||
level = arg0; | ||
msg = arg1; | ||
meta = arg2; | ||
callback = arg3; | ||
} | ||
if (this.silent) return callback(null, true) | ||
@@ -72,0 +99,0 @@ if (this.unique && this.level != level) return callback(null, true) |
{ | ||
"name": "winston-mail", | ||
"description": "A mail transport for winston", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"author": "Marc Harter <wavded@gmail.com>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -54,3 +54,3 @@ ![NPM](https://img.shields.io/npm/v/winston-mail.svg) [![Build Status](https://travis-ci.org/wavded/winston-mail.svg?branch=master)](https://travis-ci.org/wavded/winston-mail) ![Downloads](https://img.shields.io/npm/dt/winston-mail.svg) | ||
Copyright (C) 2016 Marc Harter | ||
Copyright (C) 2016-2018 Marc Harter | ||
@@ -57,0 +57,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
@@ -25,9 +25,12 @@ var test = require('tape') | ||
test('winston-mail', function(t) { | ||
// get winston version to create tests accordingly | ||
var winstonVersion = winston.version, | ||
majorWVersion = winstonVersion.split('.')[0]; | ||
var table = [ | ||
{level: 'info', subject: '{{level}}', test: 'info'}, | ||
{msg: 'goodbye', level: 'error', test: 'goodbye'}, | ||
{msg: 'hello', level: 'info', subject: '{{msg}}', test: 'hello'}, | ||
{level: 'warn', formatter: function(d) { return '!' + d.level + '!' }, test: '!warn!'}, | ||
] | ||
{level: 'info', subject: '{{level}}', test: 'info'}, | ||
{message: 'goodbye', level: 'error', test: 'goodbye'}, | ||
{message: 'hello', level: 'info', subject: '{{message}}', test: 'hello'}, | ||
{level: 'warn', formatter: function(d) { return '!' + d.level + '!' }, test: '!warn!'}, | ||
]; | ||
t.plan(table.length) | ||
@@ -38,3 +41,3 @@ | ||
var transport = new (Mail)({ | ||
var transport = new Mail({ | ||
to: 'dev@server.com', | ||
@@ -46,4 +49,12 @@ from: 'dev@server.com', | ||
}) | ||
var logger = new winston.Logger({transports: [transport]}) | ||
var logger; | ||
if (majorWVersion >= 3) { | ||
logger = new winston.createLogger({ | ||
transports: [transport]}); | ||
} else { | ||
logger = new winston.Logger({ | ||
transports: [transport]}); | ||
} | ||
testFn = function(data) { | ||
@@ -53,3 +64,9 @@ t.ok(RegExp(tt.test).test(data)) | ||
} | ||
logger[tt.level](tt.msg) | ||
if (majorWVersion >= 3) { | ||
// for version 3 and above use the new log function with info object as a parameter | ||
logger.log({level:tt.level, message:tt.message}); | ||
} else { | ||
// for version bellow 3 use the old log function with 3 parameters: level, message, meta | ||
logger[tt.level](tt.message); | ||
} | ||
} | ||
@@ -56,0 +73,0 @@ run(table.shift()) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12792
187