Skip to content

Commit

Permalink
fix cli log config issue (#830)
Browse files Browse the repository at this point in the history
  • Loading branch information
dogancanbakir committed Jun 27, 2024
1 parent 0776a79 commit d835f94
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func New(options *types.Options) (*Runner, error) {
}
options.URLs = mapsutil.GetKeys(runnerState.InFlightUrls.GetAll())
}

options.ConfigureOutput()
showBanner()

if options.Version {
Expand Down
20 changes: 1 addition & 19 deletions pkg/types/crawler_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ import (
"time"

"github.com/projectdiscovery/fastdialer/fastdialer"
"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/gologger/levels"
"github.com/projectdiscovery/katana/pkg/output"
"github.com/projectdiscovery/katana/pkg/utils/extensions"
"github.com/projectdiscovery/katana/pkg/utils/filters"
"github.com/projectdiscovery/katana/pkg/utils/scope"
"github.com/projectdiscovery/ratelimit"
errorutil "github.com/projectdiscovery/utils/errors"
logutil "github.com/projectdiscovery/utils/log"
urlutil "github.com/projectdiscovery/utils/url"
wappalyzer "github.com/projectdiscovery/wappalyzergo"
)
Expand Down Expand Up @@ -42,7 +39,7 @@ type CrawlerOptions struct {
// NewCrawlerOptions creates a new crawler options structure
// from user specified options.
func NewCrawlerOptions(options *Options) (*CrawlerOptions, error) {
configureOutput(options)
options.ConfigureOutput()
extensionsValidator := extensions.NewValidator(options.ExtensionsMatch, options.ExtensionFilter)

dialerOpts := fastdialer.DefaultOptions
Expand Down Expand Up @@ -152,18 +149,3 @@ func (c *CrawlerOptions) ValidateScope(absURL, rootHostname string) (bool, error
}
return true, nil
}

// configureOutput configures the output logging levels to be displayed on the screen
func configureOutput(options *Options) {
if options.Silent {
gologger.DefaultLogger.SetMaxLevel(levels.LevelSilent)
} else if options.Verbose {
gologger.DefaultLogger.SetMaxLevel(levels.LevelWarning)
} else if options.Debug {
gologger.DefaultLogger.SetMaxLevel(levels.LevelDebug)
} else {
gologger.DefaultLogger.SetMaxLevel(levels.LevelInfo)
}

logutil.DisableDefaultLogger()
}
18 changes: 18 additions & 0 deletions pkg/types/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import (
"time"

"github.com/projectdiscovery/goflags"
"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/gologger/levels"
"github.com/projectdiscovery/katana/pkg/output"
fileutil "github.com/projectdiscovery/utils/file"
logutil "github.com/projectdiscovery/utils/log"
)

// OnResultCallback (output.Result)
Expand Down Expand Up @@ -194,3 +197,18 @@ func (options *Options) ParseHeadlessOptionalArguments() map[string]string {
func (options *Options) ShouldResume() bool {
return options.Resume != "" && fileutil.FileExists(options.Resume)
}

// ConfigureOutput configures the output logging levels to be displayed on the screen
func (options *Options) ConfigureOutput() {
if options.Silent {
gologger.DefaultLogger.SetMaxLevel(levels.LevelSilent)
} else if options.Verbose {
gologger.DefaultLogger.SetMaxLevel(levels.LevelWarning)
} else if options.Debug {
gologger.DefaultLogger.SetMaxLevel(levels.LevelDebug)
} else {
gologger.DefaultLogger.SetMaxLevel(levels.LevelInfo)
}

logutil.DisableDefaultLogger()
}

0 comments on commit d835f94

Please sign in to comment.