Skip to content

How can we log custom class object using PmLog::Stream #1

@rajesh6115

Description

@rajesh6115

How we can support for input operator( << ) for custom types.
Something like the below code?


#include <PmLog.h>
using namespace std;
pmlog::PmLog appLog("helloapp");
pmlog::PmLog::Stream pmDebug= appLog.debug() ;

class MyCustomType{
private:
	int x;
	int y;
	float d;

public:
	MyCustomType(int x, int y, float d):x(x),y(y),d(d){}
	friend pmlog::PmLog::Stream& operator << (pmlog::PmLog::Stream& out, const MyCustomType& obj);
};

pmlog::PmLog::Stream& operator << (pmlog::PmLog::Stream& out, const MyCustomType& obj) {
	out << "\n x=" << obj.x;
	out << ", y=" << obj.y;
	out << ", d=" << obj.d << "\n";
	return out;
}

int main() {
	pmDebug << "Hello world";
	MyCustomType obj1{1,2,3.4f};
	pmDebug << obj1;
	return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions