Skip to content

Commit

Permalink
fix pipename generator on mac/linux+ log errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mdaneri committed Nov 28, 2024
1 parent d2b5b49 commit ac4cbb9
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/PodeMonitor/PipeNameGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static string GeneratePipeName()
{
// Use Unix domain socket format with a shorter temp directory
//string pipePath = Path.Combine(UnixTempDir, $"PodePipe_{uniqueId}");
string pipePath = "PodePipe_{uniqueId}";
string pipePath = $"PodePipe_{uniqueId}";

// Ensure the path is within the allowed length for Unix domain sockets
if (pipePath.Length > MaxUnixPathLength)
Expand Down
4 changes: 2 additions & 2 deletions src/PodeMonitor/PodeMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public PodeMonitor(PodeMonitorWorkerOptions options)

// Generate a unique pipe name
_pipeName = PipeNameGenerator.GeneratePipeName();
PodeMonitorLogger.Log(PodeLogLevel.INFO, "PodeMonitor", Environment.ProcessId, $"Initialized PodeMonitor with pipe name: {_pipeName}");

// Define the state file path only for Linux/macOS
if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
{
Expand Down Expand Up @@ -100,7 +100,7 @@ public PodeMonitor(PodeMonitorWorkerOptions options)
_stateFilePath = Path.Combine(stateDirectory, $"{Environment.ProcessId}.state");


PodeMonitorLogger.Log(PodeLogLevel.INFO, "PodeMonitor", Environment.ProcessId, $"Initialized PodeMonitor with pipe name: {_pipeName} and state file: {_stateFilePath}");
PodeMonitorLogger.Log(PodeLogLevel.INFO, "PodeMonitor", Environment.ProcessId, "Initialized PodeMonitor with pipe name: {0} and state file: {1}",_pipeName,_stateFilePath);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/PodeMonitor/PodeMonitorLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ public static void Log(PodeLogLevel level, string context, int pid, string messa
}
catch (Exception ex)
{
Console.WriteLine($"Failed to log to file: {ex.Message}");
Console.WriteLine($"Failed to log to file:");
Console.WriteLine($"{context} - {message}");
Console.WriteLine($"Error: {ex.Message}");
}
}

Expand Down
9 changes: 6 additions & 3 deletions src/PodeMonitor/PodeMonitorMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,17 @@ public static void Main(string[] args)
string logFilePath = config.GetSection("PodeMonitorWorker:logFilePath").Value ?? "PodeMonitorService.log";

// Parse log level
string logLevelString = config.GetSection("PodeMonitorWorker:PodeLogLevel").Value;
string logLevelString = config.GetSection("PodeMonitorWorker:LogLevel").Value;

if (!Enum.TryParse(logLevelString, true, out PodeLogLevel logLevel))
{
Console.WriteLine($"Invalid or missing log level '{logLevelString}'. Defaulting to INFO.");
logLevel = PodeLogLevel.INFO; // Default log level
}
else
{
Console.WriteLine($"Log level set to '{logLevelString}'.");
}

// Parse log max file size
string logMaxFileSizeString = config.GetSection("PodeMonitorWorker:LogMaxFileSize").Value;
Expand All @@ -72,11 +77,9 @@ public static void Main(string[] args)
Console.WriteLine($"Invalid or missing log max file size '{logMaxFileSizeString}'. Defaulting to 10 MB.");
logMaxFileSize = 10 * 1024 * 1024; // Default to 10 MB
}

// Initialize logger
PodeMonitorLogger.Initialize(logFilePath, logLevel, logMaxFileSize);


// Configure host builder
var builder = CreateHostBuilder(args, customConfigFile);

Expand Down
1 change: 1 addition & 0 deletions src/Public/Core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ function Start-PodeServer {
Quiet = $PodeService.Quiet
PipeName = $PodeService.PipeName
}
write-podehost $PodeService -Explode -Force
}
}

Expand Down

0 comments on commit ac4cbb9

Please sign in to comment.