REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
Loading...
Searching...
No Matches
json_logging.cpp
Go to the documentation of this file.
1// Copyright (c) 2023 anabrid GmbH
2// Contact: https://www.anabrid.com/licensing/
3// SPDX-License-Identifier: MIT OR GPL-2.0-or-later
4
5#include "protocol/jsonl_logging.h"
6
7FLASHMEM size_t msg::StreamLogger::write(uint8_t b) {
8 // size_t write(const uint8_t *buffer, size_t size) override {
9 if (new_line) {
10 target.begin_dict();
11 target.kv("type", "log");
12 target.kv("count", line_count++);
13 target.kv("time", millis());
14 target.key("msg");
15 target.begin_str();
16 new_line = false;
17 }
18 if (b == '\r')
19 return 1; // ignore CR in CR NL line endings.
20 if (b == '\n') {
21 target.end_str();
22 target.end_dict();
23 target.output.println("");
24 target.output.flush();
25 new_line = true;
26 return 1;
27 } else {
28 return target.output.write(b);
29 }
30}
31
32FLASHMEM void msg::StartupLog::stream_to_json(utils::StreamingJson &s) {
33 s.begin_dict();
34 s.kv("is_active", is_active());
35 s.kv("max_size", static_cast<unsigned>(buf.max_size));
36 s.key("entries");
37 s.begin_list();
38 for (auto const &line : buf.data()) {
39 s.json(line.c_str());
40 }
41 s.end_list();
42 s.end_dict();
43}
44
45void msg::activate_serial_log() { msg::Log::get().sinks.add_Serial(); }