~aleteoryx/muditaos

ref: sign_test muditaos/module-utils/log/LoggerWorker.cpp -rw-r--r-- 1.4 KiB
a217eeb3 — Dawid Wojtas [BH-2024] Fix lack of alarm directory after updating software 1 year, 5 months ago
                                                                                
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
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "LoggerWorker.hpp"
#include "Logger.hpp"
#include <log/log.hpp>
#include <magic_enum.hpp>
#include <purefs/filesystem_paths.hpp>

namespace Log
{
    LoggerWorker::LoggerWorker(const std::string &name) : Worker(name, priority)
    {}

    void LoggerWorker::notify(Signal command)
    {
        if (auto queue = getQueueByName(SignalQueueName); !queue->Overwrite(&command)) {
            LOG_ERROR("Unable to overwrite the command in the commands queue.");
        }
    }

    bool LoggerWorker::handleMessage(std::uint32_t queueID)
    {
        if (const auto queue = queues[queueID]; queue->GetQueueName() == SignalQueueName) {
            if (sys::WorkerCommand command; queue->Dequeue(&command, 0)) {
                handleCommand(static_cast<Signal>(command.command));
            }
        }
        return true;
    }

    void LoggerWorker::handleCommand(Signal command)
    {
        switch (command) {
        case Signal::DumpFilledBuffer:
        case Signal::DumpIntervalBuffer:
        case Signal::DumpDiagnostic:
            LOG_INFO("Received signal: %s", magic_enum::enum_name(command).data());
            Log::Logger::get().dumpToFile(purefs::dir::getLogsPath());
            break;
        default:
            LOG_ERROR("Command not valid: %d", static_cast<int>(command));
        }
    }

} // namespace Log