VT100 Terminal App
Circle VT100 module documentation
Loading...
Searching...
No Matches
TFileLog.h
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// Module: CTFileLog
3// Description: Mirrors Circle log output into an SD-card backed log file.
4// Author: R. Zuehlsdorff, ralf.zuehlsdorff@t-online.de
5// Created: 2026-01-24
6// License: MIT License (https://opensource.org/license/mit/)
7//------------------------------------------------------------------------------
8// Change Log:
9// 2026-01-24 R. Zuehlsdorff Initial creation
10//------------------------------------------------------------------------------
11
12#pragma once
13
14#include <circle/device.h>
15#include <circle/string.h>
16#include <circle/types.h>
17#include <fatfs/ff.h>
18
28class CLogger;
29
38class CTFileLog : public CDevice
39{
40public:
43 static CTFileLog *Get();
44
50 bool Initialize(CLogger &logger, const char *fileName, CDevice *fallbackTarget);
53 void SetFallback(CDevice *fallbackTarget);
56 bool Start();
58 void Stop();
59
64 int Write(const void *buffer, size_t count) override;
65
66private:
68 CTFileLog();
70 ~CTFileLog();
71
75 bool OpenFile(const char *fileName);
77 void CloseFile();
79 void WriteHeader();
81 void Flush();
82
83private:
84 static CTFileLog *s_pInstance;
85
86 CLogger *m_pLogger;
87 CDevice *m_pFallback;
88 FIL m_File;
89 bool m_FileOpen;
90 bool m_Initialized;
91 bool m_Active;
92 CString m_FilePath;
93 unsigned m_PendingFlushBytes;
94 unsigned m_PendingFlushLines;
95
96 static constexpr unsigned FlushByteThreshold = 1024;
97 static constexpr unsigned FlushLineThreshold = 8;
98};
Provides file-based persistence for Circle logger messages.
Definition TFileLog.h:39
bool Start()
Attach to the logger and begin capturing output.
Definition TFileLog.cpp:83
void Stop()
Detach from the logger and flush pending output.
Definition TFileLog.cpp:98
int Write(const void *buffer, size_t count) override
Write a chunk of log data and mirror to the fallback if needed.
Definition TFileLog.cpp:114
bool Initialize(CLogger &logger, const char *fileName, CDevice *fallbackTarget)
Prepare the log target with logger, file path, and fallback device.
Definition TFileLog.cpp:49
void SetFallback(CDevice *fallbackTarget)
Change the device used when file logging is unavailable.
Definition TFileLog.cpp:78
static CTFileLog * Get()
Access the singleton file log device.
Definition TFileLog.cpp:22