Skip to content
This repository was archived by the owner on Jun 29, 2022. It is now read-only.

Commit 25a8ff8

Browse files
committed
Taking shape, message formating is working
1 parent 447e46c commit 25a8ff8

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

httptest.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
var http = require('http'),
3-
winston = require('winston');
3+
winston = require('winston'),
4+
winstonCrashLog = require('./lib/winston-crashlog');
45

56

67
var logger = new (winston.Logger)({
@@ -9,7 +10,8 @@ var logger = new (winston.Logger)({
910
]
1011
});
1112

12-
winston.handleExceptions(new winston.transports.Http({ 'host': 'localhost', 'port': 8000, 'path': '/notify' }));
13+
//winston.handleExceptions(new winston.transports.Http({ 'host': 'localhost', 'port': 8000, 'path': '/notify' }));
14+
winston.handleExceptions(new winston.transports.CrashLog({ 'host': 'localhost', 'port': 8000, 'path': '/notify' }));
1315

14-
//logger.log('info', 'Hello webhook log files!', { 'foo': 'bar' });
16+
//logger.log('error', 'Hello webhook log files!', { 'foo': 'bar' });
1517
throw new Error('Hello, winston!');

lib/winston-crashlog.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ var CrashLog = exports.CrashLog = function (options) {
1919
this.level = options.level || 'error';
2020
this.notifierName = options.name || 'nodejsapp';
2121
this.notifierVersion = options.name || '0.0.1';
22+
this.handleExceptions = options.handleExceptions || true;
2223
};
2324

2425
util.inherits(CrashLog, winston.Transport);
2526

27+
winston.transports.CrashLog = CrashLog;
28+
2629
//Expose the name of this Transport on the prototype
2730
CrashLog.prototype.name = 'CrashLog';
2831

@@ -40,15 +43,26 @@ CrashLog.prototype.log = function (level, msg, meta, callback) {
4043
};
4144

4245
payload.event = {
43-
message: msg,
44-
type: "Error",
45-
timestamp: Date.now()
46+
message:msg,
47+
type:"Error",
48+
timestamp:metac.date
49+
};
50+
51+
payload.backtrace = [];
52+
53+
metac.trace.forEach(function (frame) {
54+
payload.backtrace.push({ file:frame.file, number:frame.line, method: frame.method});
55+
});
56+
57+
payload.environment = {
58+
platform: metac.process.version
4659
};
4760

48-
console.log(msg);
49-
console.log(payload);
61+
// console.log(msg);
62+
// console.log(payload);
63+
//console.log(metac);
5064

5165

5266
callback(null, true);
5367
self.emit('logged');
54-
}
68+
};

0 commit comments

Comments
 (0)