forked from projectdiscovery/nuclei
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
44 lines (38 loc) · 1.14 KB
/
log.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package templates
import (
"fmt"
"strings"
"github.com/logrusorgru/aurora"
"github.com/projectdiscovery/nuclei/v2/pkg/model/types/severity"
)
var (
Colorizer aurora.Aurora
SeverityColorizer func(severity.Severity) string
)
// TemplateLogMessage returns a beautified log string for a template
func TemplateLogMessage(id, name string, authors []string, templateSeverity severity.Severity) string {
if Colorizer == nil || SeverityColorizer == nil {
return ""
}
// Display the message for the template
return fmt.Sprintf("[%s] %s (%s) [%s]",
Colorizer.BrightBlue(id).String(),
Colorizer.Bold(name).String(),
Colorizer.BrightYellow(appendAtSignToAuthors(authors)).String(),
SeverityColorizer(templateSeverity))
}
// appendAtSignToAuthors appends @ before each author and returns the final string
func appendAtSignToAuthors(authors []string) string {
if len(authors) == 0 {
return "@none"
}
values := make([]string, 0, len(authors))
for _, k := range authors {
if !strings.HasPrefix(k, "@") {
values = append(values, fmt.Sprintf("@%s", k))
} else {
values = append(values, k)
}
}
return strings.Join(values, ",")
}