Skip to content

Commit

Permalink
implement stream reading
Browse files Browse the repository at this point in the history
  • Loading branch information
solnicki committed Nov 18, 2024
1 parent 487c905 commit 28c5c53
Show file tree
Hide file tree
Showing 33 changed files with 528 additions and 1,015 deletions.
66 changes: 66 additions & 0 deletions cmd/logveil/logveil.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package logveil

import (
"bufio"
"log/slog"
"os"

"github.com/logmanager-oss/logveil/internal/anonymizer"
"github.com/logmanager-oss/logveil/internal/config"
"github.com/logmanager-oss/logveil/internal/loader"
"github.com/logmanager-oss/logveil/internal/runner"
)

func Run() {
slog.Info("Anonymization process started...")

config := &config.Config{}
config.LoadAndValidate()

if *config.IsVerbose {
slog.SetLogLoggerLevel(slog.LevelDebug)
}

inputReader, err := os.Open(config.InputPath)
if err != nil {
return
}
defer inputReader.Close()

var outputFile *os.File
if config.OutputPath != "" {
outputFile, err := os.Create(config.OutputPath)
if err != nil {
return
}
defer outputFile.Close()
} else {
outputFile = os.Stdout
}

outputWriter := bufio.NewWriter(outputFile)
defer outputWriter.Flush()

anonymizingData, err := loader.Load(config.AnonymizationDataPath)
if err != nil {
slog.Error("loading anonymizing data from dir %s: %v", config.AnonymizationDataPath, err)
return
}
anonymizer := anonymizer.New(anonymizingData)

if *config.IsLmExport {
err := runner.AnonymizeLmExport(inputReader, outputWriter, anonymizer)
if err != nil {
slog.Error("reading lm export input file %s: %v", inputReader.Name(), err)
return
}
} else {
err := runner.AnonymizeLmBackup(inputReader, outputWriter, anonymizer)
if err != nil {
slog.Error("reading lm backup input file %s: %v", inputReader.Name(), err)
return
}
}

slog.Info("All done. Exiting...")
}
4 changes: 2 additions & 2 deletions cmd/main.go
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.Run()
}
Binary file added examples/.DS_Store
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 28c5c53

Please sign in to comment.