Skip to content

Commit

Permalink
Merge pull request #825 from projectdiscovery/fix_lib_log_config_issue
Browse files Browse the repository at this point in the history
fix lib log config issue
  • Loading branch information
ehsandeep authored Mar 26, 2024
2 parents 01b708d + 7c42305 commit cf9142b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
17 changes: 0 additions & 17 deletions internal/runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ import (

"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/gologger/formatter"
"github.com/projectdiscovery/gologger/levels"
"github.com/projectdiscovery/katana/pkg/types"
"github.com/projectdiscovery/katana/pkg/utils"
errorutil "github.com/projectdiscovery/utils/errors"
fileutil "github.com/projectdiscovery/utils/file"
logutil "github.com/projectdiscovery/utils/log"
"gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -110,21 +108,6 @@ func normalizeInput(value string) string {
return strings.TrimSpace(value)
}

// configureOutput configures the output logging levels to be displayed on the screen
func configureOutput(options *types.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()
}

func initExampleFormFillConfig() error {
homedir, err := os.UserHomeDir()
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func New(options *types.Options) (*Runner, error) {
options.URLs = mapsutil.GetKeys(runnerState.InFlightUrls.GetAll())
}

configureOutput(options)
showBanner()

if options.Version {
Expand Down
19 changes: 19 additions & 0 deletions pkg/types/crawler_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ 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 @@ -39,6 +42,7 @@ type CrawlerOptions struct {
// NewCrawlerOptions creates a new crawler options structure
// from user specified options.
func NewCrawlerOptions(options *Options) (*CrawlerOptions, error) {
configureOutput(options)
extensionsValidator := extensions.NewValidator(options.ExtensionsMatch, options.ExtensionFilter)

dialerOpts := fastdialer.DefaultOptions
Expand Down Expand Up @@ -147,3 +151,18 @@ 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()
}

0 comments on commit cf9142b

Please sign in to comment.