Skip to content

Commit

Permalink
add logger to join & split workers
Browse files Browse the repository at this point in the history
  • Loading branch information
tarunKoyalwar committed Jul 13, 2023
1 parent 572812a commit 7923ba7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
11 changes: 8 additions & 3 deletions channelutil/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package channelutil

import (
"context"
"log"
"sync"

"github.com/projectdiscovery/gologger"
errorutil "github.com/projectdiscovery/utils/errors"
)

Expand All @@ -18,6 +18,7 @@ type CloneOptions struct {
type CloneChannels[T any] struct {
// Options
opts *CloneOptions
Log *log.Logger

// Internal
wg sync.WaitGroup
Expand Down Expand Up @@ -125,11 +126,15 @@ func (s *CloneChannels[T]) cloneChanWorker(ctx context.Context, src chan T, sink
s.wg.Done()
}()
if src == nil {
gologger.Error().Msgf("source channel is nil")
if s.Log != nil {
s.Log.Println("Error: source channel is nil")
}
return
}
if len(sinkchans) != 5 {
gologger.Error().Msgf("expected total sinks 5 but got %v", len(sinkchans))
if s.Log != nil {
s.Log.Printf("Error: expected total sinks 5 but got %v", len(sinkchans))
}
return
}

Expand Down
14 changes: 10 additions & 4 deletions channelutil/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package channelutil

import (
"context"
"log"
"sync"

"github.com/projectdiscovery/gologger"
errorutil "github.com/projectdiscovery/utils/errors"
)

Expand All @@ -13,7 +13,8 @@ import (
// this is useful when you have multiple sources and you want to send data to one channel
type JoinChannels[T any] struct {
// internal
wg sync.WaitGroup
wg sync.WaitGroup
Log *log.Logger
}

// JoinChannels Joins Many Channels to Create One
Expand Down Expand Up @@ -97,11 +98,16 @@ func (j *JoinChannels[T]) joinWorker(ctx context.Context, sink chan T, sources .
j.wg.Done()
}()
if len(sources) != 5 {
gologger.Error().Msgf("worker only supports 5 sources got %v", len(sources))
if j.Log != nil {
j.Log.Printf("Error: worker only supports 5 sources got %v", len(sources))
}
return
}
if sink == nil {
gologger.Error().Msgf("sink cannot be nil")
if j.Log != nil {
j.Log.Printf("Error: sink cannot be nil")
}
return
}

// recieve only channels
Expand Down

0 comments on commit 7923ba7

Please sign in to comment.