daemon/logger/copier.go
Method Copier.copySrc
has a Cognitive Complexity of 75 (exceeds 20 allowed). Consider refactoring. Open
Open
func (c *Copier) copySrc(name string, src io.Reader) {
defer c.copyJobs.Done()
bufSize := defaultBufSize
if sizedLogger, ok := c.dst.(SizedLogger); ok {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method Copier.copySrc
has 101 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (c *Copier) copySrc(name string, src io.Reader) {
defer c.copyJobs.Done()
bufSize := defaultBufSize
if sizedLogger, ok := c.dst.(SizedLogger); ok {
Avoid deeply nested control flow statements. Open
Open
if logErr := c.dst.Log(msg); logErr != nil {
logDriverError(c.dst.Name(), string(msg.Line), logErr)
}
Avoid deeply nested control flow statements. Open
Open
if logErr := c.dst.Log(msg); logErr != nil {
logDriverError(c.dst.Name(), string(msg.Line), logErr)
}
Avoid deeply nested control flow statements. Open
Open
if msg.PLogMetaData == nil {
msg.Timestamp = time.Now().UTC()
} else {
msg.Timestamp = partialTS
}
Avoid deeply nested control flow statements. Open
Open
if firstPartial {
msg.Timestamp = time.Now().UTC()
partialTS = msg.Timestamp
partialid = stringid.GenerateRandomID()
ordinal = 1
Avoid deeply nested control flow statements. Open
Open
if hasMorePartial {
msg.PLogMetaData = &types.PartialLogMetaData{ID: partialid, Ordinal: ordinal, Last: true}
// reset
partialid = ""
Avoid deeply nested control flow statements. Open
Open
if err != io.EOF {
logReadsFailedCount.Inc(1)
log.G(context.TODO()).Errorf("Error scanning log stream: %s", err)
return
}
Method Copier.copySrc
has 5 return statements (exceeds 4 allowed). Open
Open
func (c *Copier) copySrc(name string, src io.Reader) {
defer c.copyJobs.Done()
bufSize := defaultBufSize
if sizedLogger, ok := c.dst.(SizedLogger); ok {