https://github.com/C9Glax/tranga-website/pull/41 LogFile Enable LogFiles
This commit is contained in:
parent
e801cc4cbf
commit
ca95460218
@ -26,4 +26,4 @@ WORKDIR /publish
|
||||
COPY --from=build-env /publish .
|
||||
USER 0
|
||||
RUN chown 1000:1000 /publish
|
||||
ENTRYPOINT ["dotnet", "/publish/Tranga.dll", "-c"]
|
||||
ENTRYPOINT ["dotnet", "/publish/Tranga.dll", "-f -c"]
|
||||
|
@ -223,6 +223,40 @@ public class Server : GlobalBase
|
||||
case "Ping":
|
||||
SendResponse(HttpStatusCode.OK, response, "Pong");
|
||||
break;
|
||||
case "LogMessages":
|
||||
if (logger is null || !File.Exists(logger?.logFilePath))
|
||||
{
|
||||
SendResponse(HttpStatusCode.NotFound, response);
|
||||
break;
|
||||
}
|
||||
|
||||
if (requestVariables.TryGetValue("count", out string? count))
|
||||
{
|
||||
try
|
||||
{
|
||||
uint messageCount = uint.Parse(count);
|
||||
SendResponse(HttpStatusCode.OK, response, logger.Tail(messageCount));
|
||||
}
|
||||
catch (FormatException f)
|
||||
{
|
||||
SendResponse(HttpStatusCode.InternalServerError, response, f);
|
||||
}
|
||||
}else
|
||||
SendResponse(HttpStatusCode.OK, response, logger.GetLog());
|
||||
break;
|
||||
case "LogFile":
|
||||
if (logger is null || !File.Exists(logger?.logFilePath))
|
||||
{
|
||||
SendResponse(HttpStatusCode.NotFound, response);
|
||||
break;
|
||||
}
|
||||
|
||||
string logDir = new FileInfo(logger.logFilePath).DirectoryName!;
|
||||
string tmpFilePath = Path.Join(logDir, "Tranga.log");
|
||||
File.Copy(logger.logFilePath, tmpFilePath);
|
||||
SendResponse(HttpStatusCode.OK, response, new FileStream(tmpFilePath, FileMode.Open));
|
||||
File.Delete(tmpFilePath);
|
||||
break;
|
||||
default:
|
||||
SendResponse(HttpStatusCode.BadRequest, response);
|
||||
break;
|
||||
@ -482,40 +516,6 @@ public class Server : GlobalBase
|
||||
SendResponse(HttpStatusCode.BadRequest, response);
|
||||
}
|
||||
break;
|
||||
case "LogMessages":
|
||||
if (logger is null || !File.Exists(logger?.logFilePath))
|
||||
{
|
||||
SendResponse(HttpStatusCode.NotFound, response);
|
||||
break;
|
||||
}
|
||||
|
||||
if (requestVariables.TryGetValue("count", out string? count))
|
||||
{
|
||||
try
|
||||
{
|
||||
uint messageCount = uint.Parse(count);
|
||||
SendResponse(HttpStatusCode.OK, response, logger.Tail(messageCount));
|
||||
}
|
||||
catch (FormatException f)
|
||||
{
|
||||
SendResponse(HttpStatusCode.InternalServerError, response, f);
|
||||
}
|
||||
}else
|
||||
SendResponse(HttpStatusCode.OK, response, logger.GetLog());
|
||||
break;
|
||||
case "LogFile":
|
||||
if (logger is null || !File.Exists(logger?.logFilePath))
|
||||
{
|
||||
SendResponse(HttpStatusCode.NotFound, response);
|
||||
break;
|
||||
}
|
||||
|
||||
string logDir = new FileInfo(logger.logFilePath).DirectoryName!;
|
||||
string tmpFilePath = Path.Join(logDir, "Tranga.log");
|
||||
File.Copy(logger.logFilePath, tmpFilePath);
|
||||
SendResponse(HttpStatusCode.OK, response, new FileStream(tmpFilePath, FileMode.Open));
|
||||
File.Delete(tmpFilePath);
|
||||
break;
|
||||
default:
|
||||
SendResponse(HttpStatusCode.BadRequest, response);
|
||||
break;
|
||||
|
@ -16,7 +16,9 @@ public partial class Tranga : GlobalBase
|
||||
|
||||
string[]? consoleLogger = GetArg(args, ArgEnum.ConsoleLogger);
|
||||
string[]? fileLogger = GetArg(args, ArgEnum.FileLogger);
|
||||
string? filePath = fileLogger?[0];//TODO validate path
|
||||
string? filePath = GetArg(args, ArgEnum.FileLoggerPath)?[0];
|
||||
if (filePath is not null && !Directory.Exists(new FileInfo(filePath).DirectoryName))
|
||||
Directory.CreateDirectory(new FileInfo(filePath).DirectoryName!);
|
||||
|
||||
List<Logger.LoggerType> enabledLoggers = new();
|
||||
if(consoleLogger is not null)
|
||||
@ -105,7 +107,8 @@ public partial class Tranga : GlobalBase
|
||||
{ ArgEnum.DownloadLocation, new(new []{"-d", "--downloadLocation"}, 1, "Directory to which downloaded Manga are saved") },
|
||||
{ ArgEnum.WorkingDirectory, new(new []{"-w", "--workingDirectory"}, 1, "Directory in which application-data is saved") },
|
||||
{ ArgEnum.ConsoleLogger, new(new []{"-c", "--consoleLogger"}, 0, "Enables the consoleLogger") },
|
||||
{ ArgEnum.FileLogger, new(new []{"-f", "--fileLogger"}, 1, "Enables the fileLogger, Directory where logfiles are saved") },
|
||||
{ ArgEnum.FileLogger, new(new []{"-f", "--fileLogger"}, 0, "Enables the fileLogger") },
|
||||
{ ArgEnum.FileLoggerPath, new (new []{"-l", "--fPath"}, 1, "LogFilePath" ) },
|
||||
{ ArgEnum.Help, new(new []{"-h", "--help"}, 0, "Print this") }
|
||||
//{ ArgEnum., new(new []{""}, 1, "") }
|
||||
};
|
||||
@ -117,6 +120,7 @@ public partial class Tranga : GlobalBase
|
||||
WorkingDirectory,
|
||||
ConsoleLogger,
|
||||
FileLogger,
|
||||
FileLoggerPath,
|
||||
Help
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user