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

[WIP] Log marker #24

Merged
merged 12 commits into from
Oct 26, 2019
Merged

[WIP] Log marker #24

merged 12 commits into from
Oct 26, 2019

Conversation

cyucelen
Copy link
Owner

@cyucelen cyucelen commented Oct 14, 2019

It stands to reason that one of the strongest use cases would be for users to colorize their logs for easy reading.

  • Build a abstraction structure upon Golang's logger to colorize. (We can experiment here!)
  • Implement io.Writer
  • Add Mark Rules (Mark Rule name can change)
    • Builder way
    • Passing Rule slice
  • README documentation

We can add further features to the checklist!

Closes #17

@cyucelen cyucelen added enhancement New feature or request Hacktoberfest Festival of open source community! labels Oct 14, 2019
@cyucelen cyucelen self-assigned this Oct 14, 2019
@codecov-io
Copy link

codecov-io commented Oct 14, 2019

Codecov Report

Merging #24 into master will decrease coverage by 1.62%.
The diff coverage is 88.23%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #24      +/-   ##
==========================================
- Coverage     100%   98.37%   -1.63%     
==========================================
  Files           3        4       +1     
  Lines         106      123      +17     
==========================================
+ Hits          106      121      +15     
- Misses          0        1       +1     
- Partials        0        1       +1
Impacted Files Coverage Δ
log.go 88.23% <88.23%> (ø)
matcher.go 100% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 03dc5bf...70b11f8. Read the comment docs.

log.go Outdated Show resolved Hide resolved
@cyucelen
Copy link
Owner Author

Do we need to create a variadic AddRule method?
What do you think about its usefulness?

@Darkclainer
Copy link
Contributor

I think it should be another PR. See issue #27.

@cyucelen
Copy link
Owner Author

What should be another PR?
Buffering writer output until \n?

@jnatalzia
Copy link
Collaborator

Re: Variadic method

For the first pass I feel like the slice approach is good enough but if it's not a huge ordeal we might as well put it in this PR. What do you think the LoE is?

Copy link
Collaborator

@jnatalzia jnatalzia left a comment

Choose a reason for hiding this comment

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

looking so good 👍 few questions/suggestions!

log.go Show resolved Hide resolved
log_test.go Outdated Show resolved Hide resolved
log_test.go Outdated Show resolved Hide resolved
@cyucelen
Copy link
Owner Author

Oh, we need to test the rule apply order by the way. Since we are applying the rules sequentially, some matches can overlap - later order matcher will override the previous ones if there is an overlap.

Users need to be aware of it and add their mark rules according to the order too. We need to document this and give an example for it too.

@cyucelen
Copy link
Owner Author

Re: Variadic method

For the first pass I feel like the slice approach is good enough but if it's not a huge ordeal we might as well put it in this PR. What do you think the LoE is?

I don't know what LoE is 😄 but we can skip it for now, less is more!

@cyucelen
Copy link
Owner Author

Implemented some helper functionality for our assertions in assert.go and tested mark rules with it. Can you check it out? Then we can resolve the corresponding reviews.

@Darkclainer
Copy link
Contributor

@cyucelen
Copy link
Owner Author

You can not compare function. See https://stackoverflow.com/questions/42140758/collection-of-unique-functions-in-go/42147285#42147285

This approach actually looks like working. I tested it for our MatcherFunc type and it fails when MatcherFuncs actually not equal.

@Darkclainer
Copy link
Contributor

This behaviour is implementation defined.

@cyucelen
Copy link
Owner Author

This behaviour is implementation defined.

You mean undefined?

@Darkclainer
Copy link
Contributor

No. Current standard says that functions are incomparable, see https://golang.org/ref/spec#Comparison_operators .
Using reflect in that particular case, with current go implementation you got desired behavior.

@cyucelen
Copy link
Owner Author

I get it.

This behavior is not specified and so, can vary between different compiler implementations.
Here is the question; is it really a big problem for us?

  • If it is, then, is there any other option for directly testing the AddRules behaviour via asserting MarkRule equality. (You said something about wrapping it with interface?)
  • Or, we can test it indirectly in Write functions' tests, this is fine too. (I mean just testing the behavior of Write can cover AddRules logic too)

I prefer the second way if the tests for the first option will impact the implementation and make it more complex.

@Darkclainer
Copy link
Contributor

I think second option is fine, but you should come up with test that cover order of rules too.

@cyucelen
Copy link
Owner Author

Aye aye, captain!


expectedLog = fmt.Sprintf("best %s %s is %s\n", red("data"), red("company"), red(blue("skydome")))
logger.Print("best data company is skydome")
assert.Equal(t, expectedLog, mockOut.actualLog)
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice, this is so cool

@jnatalzia
Copy link
Collaborator

@cyucelen is it just the readme docs that remain for this feature? super excited to integrate it into some projects

@cyucelen
Copy link
Owner Author

@jnatalzia yes, can you help about docs?

@jnatalzia
Copy link
Collaborator

Can do!

log.go Outdated
}

// NewWriteMarker creates a Marker that writes out to the given io.Writer
func NewWriteMarker(writer io.Writer, options ...StdoutMarkerOption) *StdoutMarker {
Copy link
Collaborator

Choose a reason for hiding this comment

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

hey @cyucelen in writing the docs, I refactored the way that we deal with custom outs. instead of having to replace stdout on the created marker, i flipped it so both cases (stdout and custom) require a single function call and no more than that.

let me know what you think, happy to discuss changing it back but it felt more natural when making the example file for this writer type so i thought it might be a good change

@jnatalzia
Copy link
Collaborator

Docs added! Also refactored a small portion of the code, added a comment explaining what and why to the PR

@cyucelen
Copy link
Owner Author

We merged the @Darkclainer s unified image PR to master. Can you integrate it to this branch? I will review your last commit about Writer asap!

@jnatalzia
Copy link
Collaborator

Yes I can! Also seems like I need to add some code coverage, gotta love CI. Will fix it up today at some point

@codecov-io
Copy link

codecov-io commented Oct 25, 2019

Codecov Report

Merging #24 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #24   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           3      4    +1     
  Lines         106    121   +15     
=====================================
+ Hits          106    121   +15
Impacted Files Coverage Δ
log.go 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 03dc5bf...71e4d90. Read the comment docs.

@jnatalzia
Copy link
Collaborator

Hmmm @Darkclainer can we make an issue/PR to update the docs for using the image generator? It requires a pip install (maybe foreign for a go repo) as well as two separate terminal dependencies but no indication of where to get them. I can guess but given I'm installing them in the shell, I'd prefer to have sanctioned sources

cc @cyucelen

@cyucelen
Copy link
Owner Author

Awesome PR @jnatalzia!

I just added some docs for image_generator, also updated the images of log feature in readme.

Maybe we can get rid of functional options in WriteMarker since we are not using it anymore ?

Looks like we are getting ready for the deployment! 😎

Also, what do you think about #29 ? @jnatalzia @Darkclainer

@jnatalzia
Copy link
Collaborator

Maybe we can get rid of functional options in WriteMarker since we are not using it anymore ?

Sounds like a plan! Will push an update with those removed and then I think we're good to merge. Will mark as no longer draft.

Will comment on #29 on the issue!

@jnatalzia jnatalzia marked this pull request as ready for review October 25, 2019 23:31
@cyucelen
Copy link
Owner Author

Looks like we are good to go! Do the final touch, merge it!

@jnatalzia jnatalzia merged commit 76d12a1 into master Oct 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Hacktoberfest Festival of open source community!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create logger functionality
4 participants