-
Notifications
You must be signed in to change notification settings - Fork 218
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
Add flag to include file's dir in logs #74
Conversation
/assign @DirectXMan12 @liggitt |
klog.go
Outdated
if slash >= 0 { | ||
file = file[slash+1:] | ||
dir := path.Base(path.Dir(file)) | ||
file = path.Base(file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
path.Base(path.Dir(...))
is significantly more expensive than the current code. until we have performance tests in place that tell us whether we are regressing (as several recent functional additions did), I don't think we should merge this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fine. If we can find it useful we can keep it until we have a better solution in place.
klog.go
Outdated
dir := path.Base(path.Dir(file)) | ||
file = path.Base(file) | ||
if l.addDirHeader { | ||
file = path.Join(dir, file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alternatively, use a second strings.LastIndex
call to back up a second segment if the addDirHeader option was true, and skip calling path.Base/path.Dir entirely
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liggitt what happens on windows? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens today? /
is hard-coded
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, this is using path.Base(path.Dir(...))
, not filepath...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah good point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a second LastIndex also sounds good. For windows compatibility question, we should probably open another issue
05e67df
to
d1d548b
Compare
/uncc |
can you add a benchmark that verifies this path does not regress in allocations or CPU when the add dir header option is false? |
BenchmarkHeader
|
Signed-off-by: Vince Prignano <vincepri@vmware.com>
d1d548b
to
b33ae69
Compare
thanks |
@vincepri do you mind doc-ing the |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dims, liggitt, vincepri The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@@ -432,6 +433,7 @@ func InitFlags(flagset *flag.FlagSet) { | |||
flagset.BoolVar(&logging.toStderr, "logtostderr", logging.toStderr, "log to standard error instead of files") | |||
flagset.BoolVar(&logging.alsoToStderr, "alsologtostderr", logging.alsoToStderr, "log to standard error as well as files") | |||
flagset.Var(&logging.verbosity, "v", "number for the log level verbosity") | |||
flagset.BoolVar(&logging.skipHeaders, "add_dir_header", logging.addDirHeader, "If true, adds the file directory to the header") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be &logging.addDirHeader
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it should. cc @dims
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jhahn21 Could you please file a PR to fix it. good catch. thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dims Sure, I will.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signed-off-by: Vince Prignano vincepri@vmware.com
What this PR does / why we need it:
This PR adds a new flag to
klog
calledadd_dir_header
. This flag, when enabled, includes the file's directory in the header.This flag is meant to fix cases (like in Kubebuilder) where the generated files are called the same across different controllers/folders. This would reduce the need of renaming files, e.g.
machine/controller.go
->machine/machine_controller.go
.Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #
Special notes for your reviewer:
Please confirm that if this PR changes any image versions, then that's the sole change this PR makes.
Release note: