From 1cfc3c5b72cde0b12439260345c50a34f5db8fb7 Mon Sep 17 00:00:00 2001 From: tanberry Date: Thu, 15 Apr 2021 21:12:21 -0500 Subject: [PATCH 1/6] new code block with error handling LOG-9481 --- README.md | 50 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index ed85f2f..88111bb 100644 --- a/README.md +++ b/README.md @@ -50,27 +50,47 @@ const options = { // Only add this line in order to track exceptions options.handleExceptions = true; -logger.add(new logdnaWinston(options)); +logger.add(new logdnaWinston(options)) +// Log Examples -// log with meta -logger.log({ - level: 'info' - , message: 'Log from LogDNA-winston' - , indexMeta: true // Optional. If not provided, it will use the default. - , data:'Some information' // Properties besides level, message and indexMeta are considered as "meta" - , error: new Error("It's a trap.") // Transport will parse the error object under property 'error' +// log with meta and human readable message for Live Tail (structure upon logline expansion in-app) +let log_obj_info = { + message: 'USER 101010 SUCCESSFUL LOGIN', + user_id: '101010', + trace_id: '163e169e-a326-4b1b-a8f5-7169dd4eeca8', +} +logger.log({ + message: JSON.stringify(log_obj_info), // Optional. If not provided, the stringified (read JSON) object in it's entirety will be sent as the payload + // If specified, message will be the body/payload while the other parameters are as follows in this case + level: 'info', // Required. + indexMeta: true, // Optional. If not provided, it will use the default. + geoloc: {lat:37.386,lon:-122.084} // Optional. Properties besides level, message and indexMeta are considered as "meta" }) -// log without meta -logger.info('Info: Log from LogDNA-winston'); - -// A payload without 'message' will log the stringified object as the message +// a payload without 'message' will log the stringified (read JSON) object as the message logger.info({ - key: 'value' -, text: 'This is some text to get logged' -, bool: true + key: 'value', + text: 'This is some text to get logged', + bool: true }) + +// log errors with structure and the proper level +try { + throw new Error("It's a trap!"); +} catch(e) { + logger.log({ + level: 'error', + message: { // Quickly break out the important error information into searchable fields within LogDNA via JSON + message:e.message, + error:{code:e.code,stack:e.stack}, + trace_id: 'a077f0ad-ed0f-423b-b8d8-e0f9e3165d9f' + } // no meta included this time + }) +} + +// log with convenience functions +logger.info('Info: Log from LogDNA-winston') ``` From 7947c09e65b4aa631698f291b3f4bf9a4e1da115 Mon Sep 17 00:00:00 2001 From: Tana M Berry Date: Fri, 16 Apr 2021 08:53:17 -0500 Subject: [PATCH 2/6] Update README.md Co-authored-by: Darin Spivey --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 88111bb..906bc78 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ logger.add(new logdnaWinston(options)) // Log Examples -// log with meta and human readable message for Live Tail (structure upon logline expansion in-app) +// log with meta and human-readable message for Live Tail (structure upon logline expansion in-app) let log_obj_info = { message: 'USER 101010 SUCCESSFUL LOGIN', user_id: '101010', From 95ca11b9acce86b8c5ca36147e234d85d9714074 Mon Sep 17 00:00:00 2001 From: Tana M Berry Date: Fri, 16 Apr 2021 08:54:09 -0500 Subject: [PATCH 3/6] Update README.md Co-authored-by: Darin Spivey --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 906bc78..9290f78 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ let log_obj_info = { trace_id: '163e169e-a326-4b1b-a8f5-7169dd4eeca8', } logger.log({ - message: JSON.stringify(log_obj_info), // Optional. If not provided, the stringified (read JSON) object in it's entirety will be sent as the payload + message: JSON.stringify(log_obj_info), // Optional. If not provided, the stringified (read JSON) object in its entirety will be sent as the payload // If specified, message will be the body/payload while the other parameters are as follows in this case level: 'info', // Required. indexMeta: true, // Optional. If not provided, it will use the default. From 4aeca7cc65bcca95f6c3ccde3ea53e251ca32567 Mon Sep 17 00:00:00 2001 From: tanberry Date: Fri, 16 Apr 2021 10:55:05 -0500 Subject: [PATCH 4/6] fixed issues that the commit suggestion function in UI did not fix --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 88111bb..a664e9f 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ instantiation options to passthrough to LogDNA's logger client. ## Winston Transport -This module also provides a transport object, which can be added to winston using: +This module also provides a transport object, which can be added to Winston using: ```javascript const logdnaWinston = require('logdna-winston'); @@ -54,14 +54,14 @@ logger.add(new logdnaWinston(options)) // Log Examples -// log with meta and human readable message for Live Tail (structure upon logline expansion in-app) +// log with meta and human-readable message for Live Tail (structure upon logline expansion in-app) let log_obj_info = { message: 'USER 101010 SUCCESSFUL LOGIN', user_id: '101010', trace_id: '163e169e-a326-4b1b-a8f5-7169dd4eeca8', } logger.log({ - message: JSON.stringify(log_obj_info), // Optional. If not provided, the stringified (read JSON) object in it's entirety will be sent as the payload + message: JSON.stringify(log_obj_info), // Optional. If not provided, the stringified (read JSON) object in its entirety will be sent as the payload // If specified, message will be the body/payload while the other parameters are as follows in this case level: 'info', // Required. indexMeta: true, // Optional. If not provided, it will use the default. From 4ed20e130e43f4b9507e7fb026a9886368ea1ea9 Mon Sep 17 00:00:00 2001 From: tanberry Date: Fri, 16 Apr 2021 13:43:53 -0500 Subject: [PATCH 5/6] swapped out entire code block because Braxton updated it in several areas --- README.md | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index a664e9f..9feb4c0 100644 --- a/README.md +++ b/README.md @@ -46,35 +46,23 @@ const options = { level: level, // Default to debug, maximum level of log, doc: https://github.com/winstonjs/winston#logging-levels indexMeta: true // Defaults to false, when true ensures meta object will be searchable } - // Only add this line in order to track exceptions options.handleExceptions = true; - logger.add(new logdnaWinston(options)) - // Log Examples - -// log with meta and human-readable message for Live Tail (structure upon logline expansion in-app) +// log with meta and human readable message for Live Tail (structure upon log line expansion in-app) let log_obj_info = { message: 'USER 101010 SUCCESSFUL LOGIN', user_id: '101010', trace_id: '163e169e-a326-4b1b-a8f5-7169dd4eeca8', } -logger.log({ - message: JSON.stringify(log_obj_info), // Optional. If not provided, the stringified (read JSON) object in its entirety will be sent as the payload - // If specified, message will be the body/payload while the other parameters are as follows in this case - level: 'info', // Required. - indexMeta: true, // Optional. If not provided, it will use the default. - geoloc: {lat:37.386,lon:-122.084} // Optional. Properties besides level, message and indexMeta are considered as "meta" +logger.log({ + level: 'info', // Required. + message: JSON.stringify(log_obj_info), // Optional. If not provided, the stringified (read JSON) object (minus level) will be sent as the payload + // If specified, message will be the body/payload while the other parameters are then + indexMeta: true, // Optional. If not provided, it will use the default. + geoloc: {lat:37.386,lon:-122.084} // Optional. Properties besides level, message and indexMeta are up to you and considered "meta" }) - -// a payload without 'message' will log the stringified (read JSON) object as the message -logger.info({ - key: 'value', - text: 'This is some text to get logged', - bool: true -}) - // log errors with structure and the proper level try { throw new Error("It's a trap!"); @@ -88,9 +76,14 @@ try { } // no meta included this time }) } - // log with convenience functions logger.info('Info: Log from LogDNA-winston') +// a payload without 'message' will log the stringified (read JSON) object as the message. Same functionality as logger.log minus the level bit +logger.warn({ + key: 'value', + text: 'This is some text to get logged', + bool: true +}) ``` From f879e318b2869be7a6e5553c03ea61d661e2c532 Mon Sep 17 00:00:00 2001 From: tanberry Date: Fri, 16 Apr 2021 13:49:37 -0500 Subject: [PATCH 6/6] re-added hyphen in human-readable --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9feb4c0..3c4267f 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ const options = { options.handleExceptions = true; logger.add(new logdnaWinston(options)) // Log Examples -// log with meta and human readable message for Live Tail (structure upon log line expansion in-app) +// log with meta and human-readable message for Live Tail (structure upon log line expansion in-app) let log_obj_info = { message: 'USER 101010 SUCCESSFUL LOGIN', user_id: '101010',