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

logrusr logger #2

Merged
merged 3 commits into from
Jun 10, 2020
Merged

logrusr logger #2

merged 3 commits into from
Jun 10, 2020

Conversation

JeremyMarshall
Copy link
Contributor

I put together a logrus logger, just in case. kubebuilder uses logr, which may not be everyones ideal logger

@activeshadow
Copy link
Owner

@JeremyMarshall hey, thanks for the pull request! I just saw this, sorry for the delay. I'll try to take a look ASAP and get it merged in. More to come.

Copy link
Owner

@activeshadow activeshadow left a comment

Choose a reason for hiding this comment

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

Hi @JeremyMarshall, thanks again for the pull request! Sorry it's taken me almost a year to get around to this. I'd love to get your Logrus implementation merged in. Can you take a look at my requested changes when you get a chance?

README.md Outdated
[logfmt](http://godoc.org/github.com/kr/logfmt).
| Implementation | Notes |
|---|---|
|[stdlogr](stdlogr)| A *standard* implementation () using `fmt` that prints logs to `STDOUT` in [logfmt](http://godoc.org/github.com/kr/logfmt)|
Copy link
Owner

Choose a reason for hiding this comment

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

Please remove the () after "implementation".

go.mod Outdated
@@ -1,3 +1,7 @@
module github.com/activeshadow/logr
module github.com/JeremyMarshall/logr
Copy link
Owner

Choose a reason for hiding this comment

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

This file (go.mod) needs to be reverted back so the module name remains "github.com/activeshadow/logr". You can use your version w/ Logrus until this is merged by using the replace directive in go.mod.

"request": &logrus.Fields{
"name": this.name,
"kvs": kvs,
"this_kvs": this.kvs,
Copy link
Owner

Choose a reason for hiding this comment

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

Would it make sense to merge key/value pairs? You combine them in the WithValues function below, so why not here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you're right here. From memory, I think this.kvs is added when you create the logger and kvs for this particular call but they can be merged.

What about cases where the maps share keys?

Copy link
Owner

Choose a reason for hiding this comment

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

In cases where the maps share keys, I would think the most recent key should win. So here, the key passed to the Info function would overwrite the key created when the logger was created.

"error": err,
"name": this.name,
"kvs": kvs,
"this_kvs": this.kvs,
Copy link
Owner

Choose a reason for hiding this comment

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

Would it make sense to merge key/value pairs? You combine them in the WithValues function below, so why not here too?

},
})

if logger != nil {
Copy link
Owner

Choose a reason for hiding this comment

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

I don't see a path in the Logrus code where this would ever be nil.

},
})

if logger != nil {
Copy link
Owner

Choose a reason for hiding this comment

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

I don't see a path in the Logrus code where this would ever be nil.

vLogger := logger.V(1)
vLogger.(*LogrusInfoLogr).clock = &clock{mock: mock}
vLogger.Info("test verbose log", "hello", "crazy world")
}
Copy link
Owner

Choose a reason for hiding this comment

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

Can you either validate the result of each test function above with t.Fail calls or turn them into examples (instead of tests) with expected output comments?

@JeremyMarshall
Copy link
Contributor Author

@activeshadow Let me take a look. It's been a while. I am using my fork in a kubebuilder pet project though

remove time property
@JeremyMarshall
Copy link
Contributor Author

Hopefully better now. I converted the tests to gomega/ginkgo

Copy link
Owner

@activeshadow activeshadow left a comment

Choose a reason for hiding this comment

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

@JeremyMarshall looks good! Just a few more small requests and I'll be comfortable merging. Thanks!

@@ -5,7 +5,7 @@ import (
"github.com/activeshadow/logr/util"
"github.com/go-logr/logr"
"github.com/sirupsen/logrus"
"time"
// "time"
Copy link
Owner

Choose a reason for hiding this comment

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

Can you remove this commented require directive?

ret[extra[i].(string)] = extra[i+1]
}
return ret
}
Copy link
Owner

Choose a reason for hiding this comment

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

I think this function could be simplified, and a range operation could be avoided.

	for i := 0; i < len(extra); i += 2 {
		kv[extra[i].(string)] = extra[i+1]
	}
	
	return kv

Copy link
Owner

@activeshadow activeshadow left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks @JeremyMarshall!

@activeshadow activeshadow merged commit 9ed7d8e into activeshadow:master Jun 10, 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.

2 participants