Skip to content

Commit 3ccabd9

Browse files
committed
Refactor plugin logging
1 parent 3d0fa51 commit 3ccabd9

File tree

10 files changed

+47
-90
lines changed

10 files changed

+47
-90
lines changed

Plugins/ArduinoOutput/ArduinoOutput.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
#ifndef __ARDUINOOUTPUT_H_F7BDA585__
2525
#define __ARDUINOOUTPUT_H_F7BDA585__
2626

27-
#define PROCESSOR_NAME "Arduino Output"
28-
2927
#include <ProcessorHeaders.h>
3028

3129
#include <SerialLib.h>

Plugins/BandpassFilter/BandpassFilter.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
#ifndef __BANDPASSFILTER_H_CED428E__
2525
#define __BANDPASSFILTER_H_CED428E__
2626

27-
#define PROCESSOR_NAME "Bandpass Filter"
28-
2927
#include <ProcessorHeaders.h>
3028
#include <DspLib.h>
3129

Plugins/ChannelMap/ChannelMap.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
#ifndef __CHANNELMAP_H_330E50E0__
2525
#define __CHANNELMAP_H_330E50E0__
2626

27-
#define PROCESSOR_NAME "Channel Map"
28-
2927
#include <ProcessorHeaders.h>
3028

3129
/** Holds channel map settings for one data stream*/

Plugins/CommonAvgRef/CommonAvgRef.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
#ifndef CAR_H_INCLUDED
2525
#define CAR_H_INCLUDED
2626

27-
#define PROCESSOR_NAME "Common Avg Ref"
28-
2927
#include <ProcessorHeaders.h>
3028

3129
/** Holds settings for one stream's CAR*/

Plugins/Headers/Logging.h

Lines changed: 0 additions & 59 deletions
This file was deleted.

Plugins/Headers/ProcessorHeaders.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,4 @@ Should be included in the source files which declare a processor class.
3232
#include "../../Source/Processors/GenericProcessor/GenericProcessor.h"
3333
#include "../../Source/TestableExport.h"
3434
#include "../../Source/Utils/BroadcastParser.h"
35-
#include "DspLib.h"
36-
#include "Logging.h"
35+
#include "DspLib.h"

Plugins/PhaseDetector/PhaseDetector.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
#ifndef __PHASEDETECTOR_H_F411F29D__
2525
#define __PHASEDETECTOR_H_F411F29D__
2626

27-
#define PROCESSOR_NAME "Phase Detector"
28-
2927
#include <ProcessorHeaders.h>
3028

3129
enum PhaseType

Plugins/RecordControl/RecordControl.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626

2727
#include "RecordControlEditor.h"
2828

29-
#define PROCESSOR_NAME "Record Control"
30-
3129
#include <ProcessorHeaders.h>
3230

3331
/**

Plugins/SpikeDetector/SpikeDetector.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
#ifndef __SPIKEDETECTOR_H_3F920F95__
2525
#define __SPIKEDETECTOR_H_3F920F95__
2626

27-
#define PROCESSOR_NAME "Spike Detector"
28-
2927
#include <ProcessorHeaders.h>
3028

3129
class SpikeDetectorSettings

Source/Utils/Utils.h

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,20 @@
3131
#include <map>
3232
#include <mutex>
3333
#include <string>
34+
#include <dlfcn.h>
3435

3536
#include "../Processors/PluginManager/OpenEphysPlugin.h"
3637

3738
/* Thread-safe logger */
3839
class OELogger
3940
{
40-
std::ofstream logFile;
41-
42-
protected:
43-
OELogger() {}
44-
4541
public:
4642
static OELogger& instance()
4743
{
4844
static OELogger lg;
4945
return lg;
5046
}
5147

52-
OELogger (OELogger const&) = delete;
53-
OELogger& operator= (OELogger const&) = delete;
54-
5548
template <typename... Args>
5649
void LOGConsole (Args&&... args)
5750
{
@@ -90,24 +83,62 @@ class OELogger
9083
logFile << "[open-ephys] Session start time: " << ctime (&now);
9184
}
9285

86+
std::string getModuleName() const {
87+
Dl_info info;
88+
if (dladdr(reinterpret_cast<void*>(__builtin_return_address(0)), &info))
89+
{
90+
if (info.dli_fname) {
91+
return formatModuleName(std::string(info.dli_fname));
92+
}
93+
}
94+
return "[unknown]";
95+
}
96+
97+
std::string formatModuleName(const std::string& path) const {
98+
size_t lastSlash = path.find_last_of("/\\");
99+
std::string basename = path.substr(lastSlash + 1);
100+
std::string formatted;
101+
for (size_t i = 0; i < basename.length(); ++i) {
102+
char ch = basename[i];
103+
if (std::isupper(ch)) {
104+
if (i > 0) {
105+
formatted += '-'; // Add hyphen before uppercase letters (except the first one)
106+
}
107+
formatted += std::tolower(ch); // Convert to lowercase
108+
} else {
109+
formatted += ch;
110+
}
111+
}
112+
return "[" + formatted + "]";
113+
}
114+
93115
private:
94116
std::mutex mt;
117+
std::ofstream logFile;
118+
119+
OELogger() = default;
120+
~OELogger() = default;
121+
122+
// Disable copy and move
123+
OELogger(const OELogger&) = delete;
124+
OELogger& operator=(const OELogger&) = delete;
125+
95126
};
96127

97128
/* Expose the Logger instance to plugins */
98129
extern "C" PLUGIN_API OELogger& getOELogger();
99130

100131
/* Log Action -- taken by user */
101132
#define LOGA(...) \
102-
getOELogger().LOGFile ("[open-ephys][action] ", __VA_ARGS__);
133+
getOELogger().LOGFile (getOELogger().getModuleName(), "[action] ", __VA_ARGS__);
103134

104135
/* Log Buffer -- related logs i.e. inside process() method */
105136
#define LOGB(...) \
106-
getOELogger().LOGFile ("[open-ephys][buffer] ", __VA_ARGS__);
137+
getOELogger().LOGFile (getOELogger().getModuleName(),"[buffer] ", __VA_ARGS__);
107138

108139
/* Log Console -- gets printed to the GUI Debug Console */
109140
#define LOGC(...) \
110-
getOELogger().LOGConsole ("[open-ephys] ", __VA_ARGS__);
141+
getOELogger().LOGConsole (getOELogger().getModuleName(), " ", __VA_ARGS__);
111142

112143
/* Log Debug -- gets printed to the console in debug mode, to file otherwise */
113144
#ifdef DEBUG
@@ -117,23 +148,23 @@ extern "C" PLUGIN_API OELogger& getOELogger();
117148
#else
118149
/* Log Debug -- gets printed to the log file */
119150
#define LOGD(...) \
120-
getOELogger().LOGFile ("[open-ephys][debug] ", __VA_ARGS__);
151+
getOELogger().LOGFile (getOELogger().getModuleName(), "[debug] ", __VA_ARGS__);
121152
#endif
122153

123154
/* Log Deep Debug -- gets printed to log file (e.g. enable after a crash to get more details) */
124155
#define LOGDD(...) \
125-
getOELogger().LOGFile ("[open-ephys][ddebug] ", __VA_ARGS__);
156+
getOELogger().LOGFile (getOELogger().getModuleName(), "[ddebug] ", __VA_ARGS__);
126157

127158
/* Log Error -- gets printed to console with flare */
128159
#define LOGE(...) \
129-
getOELogger().LOGError ("[open-ephys] ***ERROR*** ", __VA_ARGS__);
160+
getOELogger().LOGError (getOELogger().getModuleName(), "***ERROR*** ", __VA_ARGS__);
130161

131162
/* Log File -- gets printed directly to main output file */
132163
#define LOGF(...) LOGD (...)
133164

134165
/* Log Graph -- gets logs related to processor graph generation/modification events */
135166
#define LOGG(...) \
136-
getOELogger().LOGFile ("[open-ephys][graph] ", __VA_ARGS__);
167+
getOELogger().LOGFile (getOELogger().getModuleName(), "[graph] ", __VA_ARGS__);
137168

138169
/* Function Timer */
139170
template <typename Time = std::chrono::microseconds, typename Clock = std::chrono::high_resolution_clock>

0 commit comments

Comments
 (0)