about summary refs log tree commit diff stats
path: root/archive/2025/summer/bsc_karidas/examples/main.cpp
blob: e589e92e0d67ea7f30edda9a5ef92765ceb8d05d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "LoggingManager.hpp"
#include <iostream>
#include <thread>
#include <chrono>
#include <vector>
#include <future>
#include <optional>
#include <filesystem>
#include <numeric>

int main()
{
    // system parameters
    LoggingConfig config;
    config.basePath = "./logs";
    config.baseFilename = "default";
    config.maxSegmentSize = 1 * 1024 * 1024; // 1 MB
    config.maxAttempts = 5;
    config.baseRetryDelay = std::chrono::milliseconds(1);
    config.queueCapacity = 1000;
    config.maxExplicitProducers = 1;
    config.batchSize = 10;
    config.numWriterThreads = 1;
    config.appendTimeout = std::chrono::seconds(5);
    config.useEncryption = true;
    config.compressionLevel = 4;
    config.maxOpenFiles = 32;

    if (std::filesystem::exists(config.basePath))
    {
        std::filesystem::remove_all(config.basePath);
    }

    LoggingManager loggingManager(config);
    loggingManager.start();

    auto producerToken = loggingManager.createProducerToken();

    LogEntry entry1(LogEntry::ActionType::READ,
                   "users/user01",
                   "controller1",
                   "processor1",
                   "user01");

    loggingManager.append(entry1, producerToken);

    LogEntry entry2(LogEntry::ActionType::UPDATE,
                    "users/user02",
                    "controller2",
                    "processor2",
                    "user02");

    LogEntry entry3(LogEntry::ActionType::DELETE,
                    "users/user03",
                    "controller3",
                    "processor3",
                    "user03");

    std::vector<LogEntry> batch{
        LogEntry(LogEntry::ActionType::UPDATE, "users/user02", "controller2", "processor2", "user02"),
        LogEntry(LogEntry::ActionType::DELETE, "users/user03", "controller3", "processor3", "user03")};

    loggingManager.appendBatch(batch, producerToken);

    loggingManager.stop();

    return 0;
}