Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion backend/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"github.com/HyperloopUPV-H8/h9-backend/internal/server"
"github.com/HyperloopUPV-H8/h9-backend/internal/vehicle"
"github.com/HyperloopUPV-H8/h9-backend/pkg/logger"
)

type App struct {
Expand Down Expand Up @@ -46,7 +47,8 @@ type TCP struct {
}

type Logging struct {
TimeUnit string `toml:"time_unit"`
TimeUnit logger.TimeUnit `toml:"time_unit"`
LoggingPath string `toml:"logging_path"`
}

type Config struct {
Expand Down
2 changes: 2 additions & 0 deletions backend/cmd/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ backoff_factor = 2 # Backoff multiplier for retry delays
enable_progress = true # Enable progress callbacks during transfers

# Logger Configuration
[logging]
time_unit = "us" # Time unit for log timestamps (ns, us, ms, s) Default: ns
logging_path = "." # Absolute path of the logger

# <-- DO NOT TOUCH BELOW THIS LINE -->

Expand Down
3 changes: 2 additions & 1 deletion backend/cmd/dev-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,5 @@ file = "backend.log" # Log file path (empty to disable file logging)
max_size_mb = 100 # Maximum log file size in MB
max_backups = 3 # Number of backup files to keep
max_age_days = 7 # Maximum age of log files in days
time_unit = "us" # Time unit for log timestamps (ns, us, ms, s)
time_unit = "us" # Time unit for log timestamps (ns, us, ms, s)
logging_path = "."
2 changes: 1 addition & 1 deletion backend/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func main() {
order_logger.Name: order_logger.NewLogger(),
}

logger.SetFormatTimestamp(logger.TimeUnit(config.Logging.TimeUnit)) // MUST be before creating subloggers
logger.ConfigureLogger(config.Logging.TimeUnit, config.Logging.LoggingPath)
loggerHandler := logger.NewLogger(subloggers, trace.Logger)

// <--- order transfer --->
Expand Down
9 changes: 6 additions & 3 deletions backend/pkg/logger/base/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,19 @@ func (sublogger *BaseLogger) Start() error {

func (sublogger *BaseLogger) CreateFile(filename string) (*os.File, error) {

err := os.MkdirAll(path.Dir(filename), os.ModePerm)
// Includes the direcory specified by the user
baseFilename := path.Join(loggerHandler.BasePath, filename)

err := os.MkdirAll(path.Dir(baseFilename), os.ModePerm)
if err != nil {
return nil, loggerHandler.ErrCreatingAllDir{
Name: sublogger.Name,
Timestamp: time.Now(),
Path: filename,
Path: baseFilename,
}
}

return os.Create(path.Join(filename))
return os.Create(path.Join(baseFilename))
}

// Create a base Logger with default values
Expand Down
12 changes: 12 additions & 0 deletions backend/pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ var _ abstraction.Logger = &Logger{}
// Used on subloggers to get the current timestamp for folder or file names
var Timestamp = time.Now()

var BasePath = "."

func (Logger) HandlerName() string { return HandlerName }

func NewLogger(keys map[abstraction.LoggerName]abstraction.Logger, baseLogger zerolog.Logger) *Logger {
Expand Down Expand Up @@ -154,3 +156,13 @@ func (logger *Logger) Stop() error {
logger.trace.Info().Msg("stopped")
return nil
}

// Configures the logger atributes before inicialicing it
func ConfigureLogger(unit TimeUnit, basePath string) {

// Start the sublogger
SetFormatTimestamp(unit)

// Update base Path
BasePath = basePath
}
Empty file modified electron-app/build-electron.sh
100644 → 100755
Empty file.
2 changes: 2 additions & 0 deletions packet-sender/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use crate::network::PacketSender;
#[command(name = "packet-sender")]
#[command(about = "Hyperloop packet sender for testing backend and frontend", long_about = None)]
struct Cli {

/// TODO: TO CHANGE = GO'S os.UserCacheDir()
/// Path to ADJ directory (defaults to ../backend/cmd/adj)
#[arg(short, long, default_value = "../backend/cmd/adj")]
adj_path: PathBuf,
Expand Down