Skip to content

Commit

Permalink
* log-exporter: tweak logging
Browse files Browse the repository at this point in the history
Signed-off-by: neo <[email protected]>
  • Loading branch information
neowu committed Dec 9, 2024
1 parent 5fcc52d commit 8a0fb3a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import core.framework.inject.Inject;
import core.framework.util.Network;
import core.framework.util.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
Expand All @@ -16,6 +18,7 @@
* @author neo
*/
public class ArchiveService {
private final Logger logger = LoggerFactory.getLogger(ArchiveService.class);
private final String hash = Hash.md5Hex(Network.LOCAL_HOST_NAME).substring(0, 5); // generally there only need one log-exporter, this is to avoid file name collision with multiple log-exporter
private final Shell shell = new Shell();

Expand All @@ -25,6 +28,8 @@ public class ArchiveService {
UploadService uploadService;

public void uploadArchive(LocalDate date) {
logger.info("uploading begin, date={}", date);

String actionLogPath = actionLogPath(date);
Path actionLogFilePath = Path.of(logDir.toString(), actionLogPath);
if (Files.exists(actionLogFilePath)) {
Expand All @@ -50,9 +55,13 @@ public void uploadArchive(LocalDate date) {
}
}
}

logger.info("uploading end, date={}", date);
}

public void cleanupArchive(LocalDate date) {
logger.info("cleaning up archives, date={}", date);

Path actionLogFilePath = Path.of(logDir.toString(), actionLogPath(date));
shell.execute("rm", "-f", actionLogFilePath.toString());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
import core.framework.web.Request;
import core.framework.web.Response;
import core.log.service.ArchiveService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* @author neo
*/
public class UploadController implements Controller {
private final Logger logger = LoggerFactory.getLogger(UploadController.class);

@Inject
ArchiveService archiveService;
@Inject
Expand All @@ -19,6 +23,7 @@ public class UploadController implements Controller {
@Override
public Response execute(Request request) {
UploadRequest uploadRequest = request.bean(UploadRequest.class);
logger.info("manually upload, date={}", uploadRequest.date);
executor.submit("upload", () -> archiveService.uploadArchive(uploadRequest.date));
return Response.empty();
}
Expand Down

0 comments on commit 8a0fb3a

Please sign in to comment.