mirror of
https://github.com/C9Glax/tranga.git
synced 2025-02-23 07:40:13 +01:00
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 .
|
COPY --from=build-env /publish .
|
||||||
USER 0
|
USER 0
|
||||||
RUN chown 1000:1000 /publish
|
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":
|
case "Ping":
|
||||||
SendResponse(HttpStatusCode.OK, response, "Pong");
|
SendResponse(HttpStatusCode.OK, response, "Pong");
|
||||||
break;
|
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:
|
default:
|
||||||
SendResponse(HttpStatusCode.BadRequest, response);
|
SendResponse(HttpStatusCode.BadRequest, response);
|
||||||
break;
|
break;
|
||||||
@ -482,40 +516,6 @@ public class Server : GlobalBase
|
|||||||
SendResponse(HttpStatusCode.BadRequest, response);
|
SendResponse(HttpStatusCode.BadRequest, response);
|
||||||
}
|
}
|
||||||
break;
|
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:
|
default:
|
||||||
SendResponse(HttpStatusCode.BadRequest, response);
|
SendResponse(HttpStatusCode.BadRequest, response);
|
||||||
break;
|
break;
|
||||||
|
@ -16,7 +16,9 @@ public partial class Tranga : GlobalBase
|
|||||||
|
|
||||||
string[]? consoleLogger = GetArg(args, ArgEnum.ConsoleLogger);
|
string[]? consoleLogger = GetArg(args, ArgEnum.ConsoleLogger);
|
||||||
string[]? fileLogger = GetArg(args, ArgEnum.FileLogger);
|
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();
|
List<Logger.LoggerType> enabledLoggers = new();
|
||||||
if(consoleLogger is not null)
|
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.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.WorkingDirectory, new(new []{"-w", "--workingDirectory"}, 1, "Directory in which application-data is saved") },
|
||||||
{ ArgEnum.ConsoleLogger, new(new []{"-c", "--consoleLogger"}, 0, "Enables the consoleLogger") },
|
{ 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.Help, new(new []{"-h", "--help"}, 0, "Print this") }
|
||||||
//{ ArgEnum., new(new []{""}, 1, "") }
|
//{ ArgEnum., new(new []{""}, 1, "") }
|
||||||
};
|
};
|
||||||
@ -117,6 +120,7 @@ public partial class Tranga : GlobalBase
|
|||||||
WorkingDirectory,
|
WorkingDirectory,
|
||||||
ConsoleLogger,
|
ConsoleLogger,
|
||||||
FileLogger,
|
FileLogger,
|
||||||
|
FileLoggerPath,
|
||||||
Help
|
Help
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user