Skip to content

#31: updates logging module to allow multiple arguments and data type… #38

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

Merged
merged 13 commits into from
Apr 30, 2020

Conversation

hoiekim
Copy link
Collaborator

@hoiekim hoiekim commented Apr 24, 2020

#31: updates logging module to allow multiple arguments and data types that are not string

This update allows followings:

  • Logging module now takes in multiple arguments and it logs each of them in each line.
  • Also it takes in data types like object, array, etc. as well as string.

lib/log.js Outdated
const obj = {
info: (...args) => {
args.forEach((e) => {
logger.info(JSON.stringify(e))
Copy link
Contributor

Choose a reason for hiding this comment

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

If I pass in 5 arguments, I wouldn't want to log 5 times. I think its better to log 1 time as a long string.

  1. Helper function that maps through args. If the element type is Error, then return e.toString(). Otherwise, return the element
  2. The helper function returns the string generated from util.format('%j', newArray). I use util.format because I think JSON.stringify puts too many quotes, makes it hard to see.
  3. Then I will just log once: logger.info( processArgs(args) )

})
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should add some test to your logger.

lib/log.js Outdated

const obj = {
info: (...args) => {
const mappedArgs = args.map((e) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

make this a helper function:

const processArgs = (args) => {
  return args.map....
}

Copy link
Contributor

@songz songz left a comment

Choose a reason for hiding this comment

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

  1. Fix tests to have 100% code coverage
  2. Filename only, not the full path. log.js should only be logging the filename.

@songz songz merged commit 80462fd into garageScript:master Apr 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants