WIP : Elektron Logging library #16
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
fix
good first issue
help wanted
invalid
major
question
testing
wontfix
No milestone
No project
No assignees
1 participant
Due date
No due date set.
Dependencies
No dependencies set.
Reference: spdf/elektron#16
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "master"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@ridv this PR corresponds to retrofitting code to use logrus for logging and get rid of the built-in logging library.
@balandi1 please also make a PR to elektron-vendor with the updated dependencies to make sure that dependencies are kept up to date.
Run code all modified code through goimports
@ -18,3 +17,4 @@
//
package def
Format error, fix spacing or run through goimports
Let's pick a better alias, this doesn't really say much about what this package holds.
@ -105,7 +107,7 @@ func clusterSizeAvgMMMPU(tasks []Task, taskObservation func(task Task) []float64
} else {
Is Logf an option here instead of sprinting?
Formatting
Formatting
Use strings.join instead. You should create the slice and append the message if necessary.
This seems really inefficient. Wouldn't value already have to be a string for this to succeed? In which case, I don't think we gain anything here by suing a sprintf.
Use struct literals instead of new as it's more descriptive:
&ClsfnTaskDistOverheadLogger{}
Where is log dir coming from? Shouldn't be a global
Why not use
string.join([]string{...}, "")
?If the code isn't needed it shouldn't be left here. If the commented out code is still needed there should be some justification for it still being here.
@ -18,3 +17,4 @@
//
package def
Yes, I will fix all the formatting errors
@ -18,3 +17,4 @@
//
package def
Okay. Will changing it to
elekLogTypes
orlogTypes
simply work ?Okay. Sure
Okay, will do the changes
It is defined in
createLogDir.go
. Since all these files belong to same package, I accessed it in this way.Yeah, thats right
Okay. Will remove the unnecessary code
value is not a string here, it is of type interface{}. But to avoid using sprintf, would it be fine to use type assertion? For eg :
value.(string)
Just checked the code and made a test run.
-logPrefix
commandline option is not used when creating the log directory.ESC[32;1m[INFO]:ESC[0m
prefix on each line in the logs.ESC[32;1m[INFO]:ESC[0m
prefix on each line. PCP logs should not have this prefix and should just have the timestamp and the message. One way of making this generic is by supporting overriding of log config for each element in the chain. For example, PCP logs are to be persisted in a different format than the universal format specified for all others.enabled: false
in the logConfig yaml file), then the corresponding log file should not be created. This would result in no log file being empty.I would alias this to elekLog as you seem to be using that prefix when aliasing imports of sub-packages.
This is very confusing. In fact, now that we are using logrus, we can get rid of the following types in
types.go
.Instead, we should just mention that we are logging to the console. The log level is anyway specified as the second argument.
@ -105,7 +107,7 @@ func clusterSizeAvgMMMPU(tasks []Task, taskObservation func(task Task) []float64
} else {
Replace
elekLogT.ERROR
withelekLogT.CONSOLE
.@ -105,7 +107,7 @@ func clusterSizeAvgMMMPU(tasks []Task, taskObservation func(task Task) []float64
} else {
err.Error()
returns the string representation.I think it will be better if it is encapsulated.
Something like
Maybe refactor to
ClsfnTaskDistrOverheadLogger
so that it is clear that we are intending "Distribution" and now "Distance"?You should use filepath.Join(...) to keep it generic.
You can possible rewrite this function to something like the one shown below.
Extend the comment to show how the format of the log directory name is going to look.
I see why you are directly assigning
true
. However, to allow disabling console logs to stdout retrofit this tocLog.AllowOnConsole = config.ConsoleConfig.AllowOnConsole
.Keep the alias for logrus import consistent. So, refactor this to "log".
Logger and Log are synonyms and therefore should not be used interchangeably.
Comments should start with capital letters and should end with a full stop.
The second argument to GetLogDir() is a prefix. How is "_" a prefix? This is probably why the log directory name is not ending up prefixed with the one specified with the
-logPrefix
flag.Why the pointer receiver? Technically, this function should not lead to change of state.
What is the rationale behind having a dummy node as the head of the chain?
As fields are optional, it is better to either have them as the last argument or not have them in the argument list at all.
I would in fact also maintain an internal data structure to store Fields that is cleared only after the log operation passes through the entire chain. You can then add a
WithFields(...)
method that wraps aroundlogrus.WithFields(...)
.I have created this sample code for reference. The sample code also shows how formatted strings are corresponding args can be passed and we can wrap around
logrus.Logf(...)
for that.Are column headers being added if enabled?
Refactor to TaskDistrConfig for semantics.
ditto.
The error message does not do justice in indicating the reason for the error.
ditto.
Refactor to
LogFile
as it is a pointer to os.File and not string.Refactor to
PCPLogger
.Why not just do this?
Where
func CreateLogFile(prefix string) string
replacesfunc SetLogFile(prefix string)
.This file is intended to only store environment variables.
Inconsistent spacing.
unnecessary comment.
@ -129,14 +131,6 @@ func WithPCPLog(pcpLog chan struct{}) SchedulerOptions {
}
}
Remove commented code if not required.
@ -105,7 +107,7 @@ func clusterSizeAvgMMMPU(tasks []Task, taskObservation func(task Task) []float64
} else {
Yes. I will work on implementing Logf()
Done
Done
Done
Okay. Done
Yeah, that's right.
@ -105,7 +107,7 @@ func clusterSizeAvgMMMPU(tasks []Task, taskObservation func(task Task) []float64
} else {
Done
@ -105,7 +107,7 @@ func clusterSizeAvgMMMPU(tasks []Task, taskObservation func(task Task) []float64
} else {
Okay. Will do the change
Done
Okay. Sure
Line 43 and 44 can fit in one line. We currently do not have any style linting setup.
refactor variable name to
logMsgType
. In fact, you don't need to have this variable at all. Instead, you can just useelekLogTypes.CONSOLE
directly.Make the changes in subsequent occurrences too.
type mismatch. You might want to use either %v or you can use masterInfo.GetHostname().
Will fit on a single line.
@ -20,24 +20,26 @@ package schedulers
import (
"fmt"
Here,
task
would be the index.As
host
is a string, you don't need to usefmt.Sprintf
.ditto for
host
andclass
.Sure
Done
Yeah, thats right. I will change it
Peeked at how logrus serializes values and seems like fmt.Sprint is used if type assertion fails.
@ -18,3 +17,4 @@
//
package def
logTypes would be fine
ahh alright, I thought it was a string coming in. Alright, if it's been sanity checked then i'm good with it.
looks good now thanks!
Thanks @balandi1 .This was a big undertaking and I really appreciate the effort you're putting towards getting it merged. Looks good to me as soon as all of @pradykaushik 's concerns are addressed. Very excited to have you be part of the list of contributors once this is merged.
That was for future purpose. But I have removed it now
Done
Done
Done
Done
Changed the error message
Done
Done
Done
Removed it from here. Added a flag in scheduler.go
Done
Removed
@ -129,14 +131,6 @@ func WithPCPLog(pcpLog chan struct{}) SchedulerOptions {
}
}
Done
Okay
Okay. Done
Done
Done
@ -20,24 +20,26 @@ package schedulers
import (
"fmt"
Okay
Done
Done
Nothing specific. I had kept
ElektronLog
asLoggerImpl
type. But I have changed toConsoleLogger
rather. Works fine nowDone
Changed
ElektronLog
toElektronLogger
Done
Done
disable schedWindow logging in the log config file that is kept within the repository.
ditto
@ -0,0 +30,4 @@
TimestampFormat string
}
func (f elektronFormatter) Format(entry *log.Entry) ([]byte, error) {
Does the formatter adhere to the format specified in the config provided?
isEnabled()
does not have to be part of the interface.ditto
ditto
does this need to be exported outside the package?
change the shorthand to
logCfg
In the future, we can have the log prefix to be part of the log config.
can fit in two lines.
Overall, LGTM.
I have mentioned a few nit picks plus a formatting related fix.
Once those are fixed, I think this is ready to be merged in.
Thank you for undertaking a non-trivial task. This was an important addition to elektron.
Done
Done
@ -0,0 +30,4 @@
TimestampFormat string
}
func (f elektronFormatter) Format(entry *log.Entry) ([]byte, error) {
No, actually as per our discussion earlier you had suggested to implement a decorator pattern for using the format specified in config. So currently, it has a fixed format and there is technically no use of the format specified in config file.
Yes. Removed it from there
Done
Done
Done
Oh, okay.
Done
No, not needed. Changed it to
getConfig
.