Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial import.

  • Loading branch information...
commit 447e46cc748c1f8dfc4be1784f3d656eb0026b97 0 parents
@wolfeidau authored
3  .gitignore
@@ -0,0 +1,3 @@
+node_modules
+.idea
+*.log
1  .npmignore
@@ -0,0 +1 @@
+/node_modules/
22 LICENSE-MIT
@@ -0,0 +1,22 @@
+Copyright (c) 2012 Mark Wolfe
+
+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:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
27 README.md
@@ -0,0 +1,27 @@
+# winston-crashlog
+
+The best project ever.
+
+## Getting Started
+Install the module with: `npm install winston-crashlog`
+
+```javascript
+var winston_crashlog = require('winston-crashlog');
+winston_crashlog.awesome(); // "awesome"
+```
+
+## Documentation
+_(Coming soon)_
+
+## Examples
+_(Coming soon)_
+
+## Contributing
+In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [grunt](https://github.com/gruntjs/grunt).
+
+## Release History
+_(Nothing yet)_
+
+## License
+Copyright (c) 2012 Mark Wolfe
+Licensed under the MIT license.
55 grunt.js
@@ -0,0 +1,55 @@
+module.exports = function (grunt) {
+
+ // Project configuration.
+ grunt.initConfig({
+ pkg:'<json:package.json>',
+ test:{
+ files:['test/**/*.js']
+ },
+ lint:{
+ files:['grunt.js', 'lib/**/*.js', 'test/**/*.js']
+ },
+ watch:{
+ files:'<config:lint.files>',
+ tasks:'default'
+ },
+ jshint:{
+ options:{
+ curly:true,
+ eqeqeq:true,
+ immed:true,
+ latedef:true,
+ newcap:true,
+ noarg:true,
+ sub:true,
+ undef:true,
+ boss:true,
+ eqnull:true,
+ node:true
+ },
+ globals:{
+ exports:true
+ }
+ },
+ simplemocha: {
+ all: {
+ src: 'test/**/*.js',
+ options: {
+ globals: ['should'],
+ timeout: 3000,
+ ignoreLeaks: false,
+ ui: 'bdd',
+ reporter: 'spec'
+ }
+ }
+ }
+ });
+
+ grunt.loadNpmTasks('grunt-simple-mocha');
+
+ // Default task.
+ grunt.registerTask('default', 'simplemocha');
+
+ // override the default test target
+ grunt.registerTask('test', 'simplemocha');
+};
36 httpTestServer.js
@@ -0,0 +1,36 @@
+var http = require('http'),
+ winston = require('winston');
+
+function dateFormat (date, fstr, utc) {
+ utc = utc ? 'getUTC' : 'get';
+ return fstr.replace (/%[YmdHMS]/g, function (m) {
+ switch (m) {
+ case '%Y': return date[utc + 'FullYear'] (); // no leading zeros required
+ case '%m': m = 1 + date[utc + 'Month'] (); break;
+ case '%d': m = date[utc + 'Date'] (); break;
+ case '%H': m = date[utc + 'Hours'] (); break;
+ case '%M': m = date[utc + 'Minutes'] (); break;
+ case '%S': m = date[utc + 'Seconds'] (); break;
+ default: return m.slice (1); // unknown code, remove %
+ }
+ // add leading zero if required
+ return ('0' + m).slice (-2);
+ });
+}
+
+var server = http.createServer(function (request, response) {
+ console.log(dateFormat(new Date (), "%Y-%m-%d %H:%M:%S", true) + ' ' + request.method + ' ' + request.url );
+ console.log(request.headers);
+ request.on('data', function(chunk) {
+ console.log("Received body data:");
+
+ var resultObject = JSON.parse(chunk.toString());
+ console.log(JSON.stringify(resultObject, null, 4));
+ });
+ response.writeHead(200, {"Content-Type": "text/plain"});
+ response.end("Hello World\n");
+});
+
+server.listen(8000);
+
+console.log("Server running at http://127.0.0.1:8000/");
15 httptest.js
@@ -0,0 +1,15 @@
+
+var http = require('http'),
+ winston = require('winston');
+
+
+var logger = new (winston.Logger)({
+ transports: [
+ new (winston.transports.Console)()
+ ]
+});
+
+winston.handleExceptions(new winston.transports.Http({ 'host': 'localhost', 'port': 8000, 'path': '/notify' }));
+
+//logger.log('info', 'Hello webhook log files!', { 'foo': 'bar' });
+throw new Error('Hello, winston!');
54 lib/winston-crashlog.js
@@ -0,0 +1,54 @@
+/*
+ * winston-crashlog
+ * https://github.com/markw/winston-crashlog
+ *
+ * Copyright (c) 2012 Mark Wolfe
+ * Licensed under the MIT license.
+ */
+var util = require('util'),
+ Ofuda = require('ofuda'),
+ winston = require('winston');
+
+var CrashLog = exports.CrashLog = function (options) {
+ options = options || {};
+ options.debug = options.debug || false;
+
+ this.name = 'CrashLog';
+ this.client = new Ofuda(options);
+
+ this.level = options.level || 'error';
+ this.notifierName = options.name || 'nodejsapp';
+ this.notifierVersion = options.name || '0.0.1';
+};
+
+util.inherits(CrashLog, winston.Transport);
+
+//Expose the name of this Transport on the prototype
+CrashLog.prototype.name = 'CrashLog';
+
+CrashLog.prototype.log = function (level, msg, meta, callback) {
+ var self = this,
+ notifierName = this.notifierName,
+ notifierVersion = this.notifierVersion,
+ metac = winston.clone(meta) || {};
+
+ var payload = {};
+
+ payload.notifier = {
+ name: notifierName,
+ version: notifierVersion
+ };
+
+ payload.event = {
+ message: msg,
+ type: "Error",
+ timestamp: Date.now()
+ };
+
+ console.log(msg);
+ console.log(payload);
+
+
+ callback(null, true);
+ self.emit('logged');
+}
41 package.json
@@ -0,0 +1,41 @@
+{
+ "name":"winston-crashlog",
+ "description":"The best project ever.",
+ "version":"0.1.0",
+ "homepage":"https://github.com/markw/winston-crashlog",
+ "author":{
+ "name":"Mark Wolfe",
+ "email":"mark@wolfe.id.au"
+ },
+ "repository":{
+ "type":"git",
+ "url":"git://github.com/markw/winston-crashlog.git"
+ },
+ "bugs":{
+ "url":"https://github.com/markw/winston-crashlog/issues"
+ },
+ "licenses":[
+ {
+ "type":"MIT",
+ "url":"https://github.com/markw/winston-crashlog/blob/master/LICENSE-MIT"
+ }
+ ],
+ "main":"lib/winston-crashlog",
+ "engines":{
+ "node":">= 0.6.0"
+ },
+ "scripts":{
+ "test":"grunt test"
+ },
+ "dependencies":{
+ "winston":"*",
+ "ofuda":"*"
+ },
+ "devDependencies":{
+ "grunt":"~0.3.17",
+ "grunt-simple-mocha": "~0.2.0",
+ "mocha": "~1.6.0",
+ "should": "~1.2.0"
+ },
+ "keywords":[]
+}
34 test/winston-crashlog_test.js
@@ -0,0 +1,34 @@
+var winston_crashlog = require('../lib/winston-crashlog.js');
+
+/*
+ ======== A Handy Little Nodeunit Reference ========
+ https://github.com/caolan/nodeunit
+
+ Test methods:
+ test.expect(numAssertions)
+ test.done()
+ Test assertions:
+ test.ok(value, [message])
+ test.equal(actual, expected, [message])
+ test.notEqual(actual, expected, [message])
+ test.deepEqual(actual, expected, [message])
+ test.notDeepEqual(actual, expected, [message])
+ test.strictEqual(actual, expected, [message])
+ test.notStrictEqual(actual, expected, [message])
+ test.throws(block, [error], [message])
+ test.doesNotThrow(block, [error], [message])
+ test.ifError(value)
+*/
+
+exports['awesome'] = {
+ setUp: function(done) {
+ // setup here
+ done();
+ },
+ 'no args': function(test) {
+ test.expect(1);
+ // tests here
+ test.equal(winston_crashlog.awesome(), 'awesome', 'should be awesome.');
+ test.done();
+ }
+};
Please sign in to comment.
Something went wrong with that request. Please try again.