Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new code block with error handling LOG-9481 #29

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 35 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
tanberry marked this conversation as resolved.
Show resolved Hide resolved
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gracious thank you for catching that. I literally just swapped out the code block and didn't look at rest of doc.

// 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')
```


Expand Down