-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from logmanager-oss/code_refactor/make_anonymiz…
…er_work_with_streams implement stream reading
- Loading branch information
Showing
35 changed files
with
693 additions
and
1,005 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package logveil | ||
|
||
import ( | ||
"bufio" | ||
"errors" | ||
"fmt" | ||
"io" | ||
"log/slog" | ||
|
||
"github.com/logmanager-oss/logveil/internal/anonymizer" | ||
"github.com/logmanager-oss/logveil/internal/config" | ||
"github.com/logmanager-oss/logveil/internal/files" | ||
"github.com/logmanager-oss/logveil/internal/reader" | ||
"github.com/logmanager-oss/logveil/internal/writer" | ||
) | ||
|
||
func Start() { | ||
slog.Info("Anonymization process started...") | ||
|
||
config := &config.Config{} | ||
config.LoadAndValidate() | ||
|
||
if *config.IsVerbose { | ||
slog.SetLogLoggerLevel(slog.LevelDebug) | ||
} | ||
|
||
filesHandler := &files.FilesHandler{} | ||
defer filesHandler.Close() | ||
|
||
inputReader, err := reader.CreateInputReader(config, filesHandler) | ||
if err != nil { | ||
return | ||
} | ||
outputWriter, err := writer.CreateOutputWriter(config, filesHandler) | ||
if err != nil { | ||
return | ||
} | ||
anonymizerDoer, err := anonymizer.CreateAnonymizer(config) | ||
if err != nil { | ||
return | ||
} | ||
|
||
err = RunAnonymizationLoop(inputReader, outputWriter, anonymizerDoer) | ||
if err != nil { | ||
slog.Error("running anonymisation loop", "error", err) | ||
return | ||
} | ||
|
||
slog.Info("All done. Exiting...") | ||
} | ||
|
||
func RunAnonymizationLoop(inputReader reader.InputReader, outputWriter *bufio.Writer, anonymizerDoer *anonymizer.Anonymizer) error { | ||
defer outputWriter.Flush() | ||
|
||
for { | ||
logLine, err := inputReader.ReadLine() | ||
if err != nil { | ||
if errors.Is(err, io.EOF) { | ||
return nil | ||
} | ||
return fmt.Errorf("reading line: %v", err) | ||
} | ||
|
||
anonymizedLogLine := anonymizerDoer.Anonymize(logLine) | ||
|
||
_, err = fmt.Fprintln(outputWriter, anonymizedLogLine) | ||
if err != nil { | ||
return fmt.Errorf("writing log line to buffer: %v", err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package main | ||
|
||
import "github.com/logmanager-oss/logveil/internal/anonymizer" | ||
import "github.com/logmanager-oss/logveil/cmd/logveil" | ||
|
||
func main() { | ||
anonymizer.Run() | ||
logveil.Start() | ||
} |
Oops, something went wrong.