Skip to content

Commit a528dc2

Browse files
committed
License changed to AGPL, logging and progressbars via own UI package, logging to file, various naming conventions in code changed, performance speedup while merging objects, got rid of BuildDate
1 parent 13924b8 commit a528dc2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2580
-1592
lines changed

Diff for: _go.work

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
go 1.18
2+
3+
use (
4+
.
5+
../stringdedup
6+
)

Diff for: adalanche/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import (
88
_ "github.com/lkarlslund/adalanche/modules/integrations/activedirectory/collect"
99
_ "github.com/lkarlslund/adalanche/modules/integrations/localmachine/analyze"
1010
_ "github.com/lkarlslund/adalanche/modules/quickmode"
11-
"github.com/rs/zerolog/log"
11+
"github.com/lkarlslund/adalanche/modules/ui"
1212
)
1313

1414
func main() {
1515
err := cli.Run()
1616

1717
if err != nil {
18-
log.Error().Msg(err.Error())
18+
ui.Error().Msg(err.Error())
1919
os.Exit(1)
2020
}
2121
}

Diff for: build.cmd

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
@echo off
22

3-
set BUILDDATE=%DATE:~-4%%DATE:~3,2%%DATE:~0,2%
4-
53
for /F "usebackq delims=" %%a in (`git rev-parse --short HEAD`) do set COMMIT=%%a
64
for /F "usebackq delims=" %%a in (`git describe --tags --exclude latest`) do set VERSION=%%a
75
for /F "usebackq delims=" %%a in (`git status --porcelain`) do set dirtyfiles="%%a"
@@ -11,7 +9,7 @@ if not [%dirtyfiles%] == [] (
119
set VERSION=%VERSION%-local-changes
1210
)
1311

14-
set LDFLAGS=-X github.com/lkarlslund/adalanche/modules/version.Program=adalanche -X github.com/lkarlslund/adalanche/modules/version.Builddate=%BUILDDATE% -X github.com/lkarlslund/adalanche/modules/version.Commit=%COMMIT% -X github.com/lkarlslund/adalanche/modules/version.Version=%VERSION%
12+
set LDFLAGS=-X github.com/lkarlslund/adalanche/modules/version.Program=adalanche -X github.com/lkarlslund/adalanche/modules/version.Commit=%COMMIT% -X github.com/lkarlslund/adalanche/modules/version.Version=%VERSION%
1513
set GOARCH=amd64
1614
set GOOS=windows
1715
go build -ldflags "%LDFLAGS%" -o adalanche-windows-x64-%VERSION%.exe ./adalanche
@@ -21,13 +19,14 @@ set GOOS=linux
2119
go build -ldflags "%LDFLAGS%" -o adalanche-linux-x64-%VERSION% ./adalanche
2220

2321
set GOARCH=arm64
22+
set GOOS=windows
23+
go build -ldflags "%LDFLAGS%" -o adalanche-windows-arm64-%VERSION%.exe ./adalanche
2424
set GOOS=linux
2525
go build -ldflags "%LDFLAGS%" -o adalanche-linux-arm64-%VERSION% ./adalanche
2626
set GOOS=darwin
2727
go build -ldflags "%LDFLAGS%" -o adalanche-osx-m1-%VERSION% ./adalanche
2828

29-
set LDFLAGS=-X github.com/lkarlslund/adalanche/modules/version.Program=adalanche-collector -X github.com/lkarlslund/adalanche/modules/version.Builddate=%BUILDDATE% -X github.com/lkarlslund/adalanche/modules/version.Commit=%COMMIT% -X github.com/lkarlslund/adalanche/modules/version.Version=%VERSION%
29+
set LDFLAGS=-X github.com/lkarlslund/adalanche/modules/version.Program=adalanche-collector -X github.com/lkarlslund/adalanche/modules/version.Commit=%COMMIT% -X github.com/lkarlslund/adalanche/modules/version.Version=%VERSION%
3030
set GOARCH=386
3131
set GOOS=windows
3232
go build -ldflags "%LDFLAGS%" -o adalanche-collector-windows-386-%VERSION%.exe ./collector
33-

Diff for: build.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/bin/bash
22

3-
BUILDDATE=`date +%Y%m%d`
43
COMMIT=`git rev-parse --short HEAD`
54
VERSION=`git describe --tags --exclude latest`
65

@@ -10,15 +9,16 @@ fi
109

1110
EXIT_STATUS=0
1211

13-
LDFLAGS="-X github.com/lkarlslund/adalanche/modules/version.Program=adalanche -X github.com/lkarlslund/adalanche/modules/version.Builddate=$BUILDDATE -X github.com/lkarlslund/adalanche/modules/version.Commit=$COMMIT -X github.com/lkarlslund/adalanche/modules/version.Version=$VERSION"
12+
LDFLAGS="-X github.com/lkarlslund/adalanche/modules/version.Program=adalanche -X github.com/lkarlslund/adalanche/modules/version.Commit=$COMMIT -X github.com/lkarlslund/adalanche/modules/version.Version=$VERSION"
1413

1514
GOOS=windows GOARCH=amd64 go build -ldflags "$LDFLAGS" -o adalanche-windows-x64-$VERSION.exe ./adalanche || EXIT_STATUS=$?
15+
GOOS=windows GOARCH=arm64 go build -ldflags "$LDFLAGS" -o adalanche-windows-arm64-$VERSION.exe ./adalanche || EXIT_STATUS=$?
1616
GOOS=darwin GOARCH=amd64 go build -ldflags "$LDFLAGS" -o adalanche-osx-x64-$VERSION ./adalanche || EXIT_STATUS=$?
1717
GOOS=darwin GOARCH=arm64 go build -ldflags "$LDFLAGS" -o adalanche-osx-m1-$VERSION ./adalanche || EXIT_STATUS=$?
1818
GOOS=linux GOARCH=amd64 go build -ldflags "$LDFLAGS" -o adalanche-linux-x64-$VERSION ./adalanche || EXIT_STATUS=$?
1919
GOOS=linux GOARCH=arm64 go build -ldflags "$LDFLAGS" -o adalanche-linux-arm64-$VERSION ./adalanche || EXIT_STATUS=$?
2020

21-
LDFLAGS="-X github.com/lkarlslund/adalanche/modules/version.Program=adalanche-collector -X github.com/lkarlslund/adalanche/modules/version.Builddate=$BUILDDATE -X github.com/lkarlslund/adalanche/modules/version.Commit=$COMMIT -X github.com/lkarlslund/adalanche/modules/version.Version=$VERSION"
21+
LDFLAGS="-X github.com/lkarlslund/adalanche/modules/version.Program=adalanche-collector -X github.com/lkarlslund/adalanche/modules/version.Commit=$COMMIT -X github.com/lkarlslund/adalanche/modules/version.Version=$VERSION"
2222

2323
GOOS=windows GOARCH=386 go build -ldflags "$LDFLAGS" -o adalanche-collector-windows-386-$VERSION.exe ./collector || EXIT_STATUS=$?
2424

Diff for: collector/main.go

+19-15
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ import (
55
"os"
66

77
"github.com/lkarlslund/adalanche/modules/integrations/localmachine/collect"
8+
"github.com/lkarlslund/adalanche/modules/ui"
89
"github.com/lkarlslund/adalanche/modules/version"
9-
"github.com/mattn/go-colorable"
10-
"github.com/rs/zerolog"
11-
"github.com/rs/zerolog/log"
1210
"github.com/spf13/cobra"
1311
)
1412

@@ -19,19 +17,30 @@ import (
1917
var (
2018
wrapcollector = &cobra.Command{}
2119
datapath = wrapcollector.Flags().String("outputpath", "", "Dump output JSON file in this folder")
22-
debuglogging = wrapcollector.Flags().Bool("debug", false, "Debug logging")
20+
loglevel = wrapcollector.Flags().String("loglevel", "info", "Console log level")
21+
logfile = wrapcollector.Flags().String("logfile", "", "Log file")
22+
logfilelevel = wrapcollector.Flags().String("logfilelevel", "info", "Log file log level")
2323
)
2424

2525
func init() {
2626
wrapcollector.RunE = Execute
2727
}
2828

2929
func Execute(cmd *cobra.Command, args []string) error {
30-
if !*debuglogging {
31-
zerolog.SetGlobalLevel(zerolog.InfoLevel)
30+
ll, err := ui.LogLevelString(*loglevel)
31+
if err != nil {
32+
ui.Error().Msgf("Invalid log level: %v - use one of: %v", *loglevel, ui.LogLevelStrings())
3233
} else {
33-
zerolog.SetGlobalLevel(zerolog.DebugLevel)
34-
log.Info().Msg("Debug logging enabled")
34+
ui.SetDefaultLoglevel(ll)
35+
}
36+
37+
if *logfile != "" {
38+
ll, err = ui.LogLevelString(*logfilelevel)
39+
if err != nil {
40+
ui.Error().Msgf("Invalid log file log level: %v - use one of: %v", *logfilelevel, ui.LogLevelStrings())
41+
} else {
42+
ui.SetLogFile(*logfile, ll)
43+
}
3544
}
3645

3746
// Ensure the data folder is available
@@ -46,15 +55,10 @@ func Execute(cmd *cobra.Command, args []string) error {
4655
}
4756

4857
func main() {
49-
log.Logger = log.Output(zerolog.ConsoleWriter{
50-
Out: colorable.NewColorableStdout(),
51-
TimeFormat: "15:04:05.06",
52-
})
53-
54-
log.Info().Msg(version.VersionString())
58+
ui.Info().Msg(version.VersionString())
5559

5660
err := wrapcollector.Execute()
5761
if err != nil {
58-
log.Error().Err(err).Msg("Failed to execute")
62+
ui.Error().Err(err).Msg("Failed to execute")
5963
}
6064
}

Diff for: go.mod

+9-2
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,22 @@ require (
3636
github.com/shirou/gopsutil/v3 v3.22.2
3737
github.com/spf13/cobra v1.3.0
3838
github.com/tinylib/msgp v1.1.6
39-
golang.org/x/sys v0.0.0-20220307203707-22a9840ba4d7
39+
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8
4040
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
4141
golang.org/x/text v0.3.7
4242
)
4343

4444
require (
45+
atomicgo.dev/cursor v0.1.1 // indirect
46+
atomicgo.dev/keyboard v0.2.8 // indirect
4547
github.com/Azure/go-ntlmssp v0.0.0-20211209120228-48547f28849e // indirect
4648
github.com/absfs/absfs v0.0.0-20200602175035-e49edc9fef15 // indirect
4749
github.com/alexbrainman/sspi v0.0.0-20210105120005-909beea2cc74 // indirect
4850
github.com/antchfx/xpath v1.2.0 // indirect
4951
github.com/asergeyev/nradix v0.0.0-20170505151046-3872ab85bb56 // indirect
5052
github.com/buger/jsonparser v1.1.1 // indirect
5153
github.com/cloudflare/buffer v0.0.0-20190408164202-7cab898e1166 // indirect
54+
github.com/containerd/console v1.0.3 // indirect
5255
github.com/crewjam/rfc5424 v0.1.0 // indirect
5356
github.com/dmarkham/enumer v1.5.5 // indirect
5457
github.com/elastic/beats v7.6.2+incompatible // indirect
@@ -66,13 +69,15 @@ require (
6669
github.com/google/go-write v0.0.0-20181107114627-56629a6b2542 // indirect
6770
github.com/google/renameio v0.1.0 // indirect; DONT CHANGE FROM v0.1.0
6871
github.com/google/uuid v1.3.0 // indirect
72+
github.com/gookit/color v1.5.0 // indirect
6973
github.com/gravwell/gcfg v1.2.9-0.20210818172109-3d05a45a2665 // indirect
7074
github.com/inconshreveable/mousetrap v1.0.0 // indirect
7175
github.com/inhies/go-bytesize v0.0.0-20210819104631-275770b98743 // indirect
7276
github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 // indirect
7377
github.com/josharian/intern v1.0.0 // indirect
7478
github.com/klauspost/compress v1.15.0 // indirect
7579
github.com/leodido/go-urn v1.2.1 // indirect
80+
github.com/lithammer/fuzzysearch v1.1.5 // indirect
7681
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
7782
github.com/mattn/go-isatty v0.0.14 // indirect
7883
github.com/mattn/go-runewidth v0.0.13 // indirect
@@ -84,15 +89,17 @@ require (
8489
github.com/pascaldekloe/name v1.0.0 // indirect
8590
github.com/philhofer/fwd v1.1.1 // indirect
8691
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
92+
github.com/pterm/pterm v0.12.45 // indirect
8793
github.com/rickb777/plural v1.2.2 // indirect
8894
github.com/rivo/uniseg v0.2.0 // indirect
8995
github.com/scjalliance/comshim v0.0.0-20190308082608-cf06d2532c4e // indirect
9096
github.com/spf13/pflag v1.0.5 // indirect
9197
github.com/tklauser/go-sysconf v0.3.10 // indirect
9298
github.com/tklauser/numcpus v0.4.0 // indirect
9399
github.com/ugorji/go/codec v1.2.7 // indirect
100+
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
94101
github.com/yusufpapurcu/wmi v1.2.2 // indirect
95-
go4.org/unsafe/assume-no-moving-gc v0.0.0-20211027215541-db492cf91b37 // indirect
102+
go4.org/unsafe/assume-no-moving-gc v0.0.0-20220617031537-928513b29760 // indirect
96103
golang.org/x/crypto v0.0.0-20220307211146-efcb8507fb70 // indirect
97104
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
98105
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect

0 commit comments

Comments
 (0)