Comments (3)
Probably something like this (if this is bad, please explain to me why, i am not a great coder by any means)
util::nstring to_string() const //member of HexDump
{
util::nostringstream new_stream;//content is identical to << operator, aside from the fact that new stream is created
new_stream << std::hex << std::setfill(PLOG_NSTR('0'));
for (size_t i = 0; i < m_size;)
{
new_stream << std::setw(2) << static_cast<int>(m_ptr[i]);
if (++i < m_size)
{
if (m_group > 0 && i % m_group == 0)
{
new_stream << m_groupSeparator;
}
else
{
new_stream << m_digitSeparator;
}
}
}
return new_stream.str();
}
notes:
1.util::nstring
may be unexpected, it is wstring for me and i wondered why i was getting no output when testing it first time :)
2.have to deal with c_str when using printf.
3.new_stream
in theory is destroyed after leaving to_string
scope.
4..str()
on nostringstream
(which afaik just uses correct wideness basic_ostringstream) creates a copy, so final string lives after leaving scope.
from plog.
Hey @po0p ! Yes, it's possible. Unfortunately it will look a little bit ugly as it needs an additional call to c_str()
:
PLOGI.printf("test format: %s", plog::hexdump(arr).str().c_str());
The implementation is simpler: it's basically a one line of code. I'll push it in a while.
from plog.
Hey @po0p ! Yes, it's possible. Unfortunately it will look a little bit ugly as it needs an additional call to
c_str()
:
Hey, thanks!
Its also quite useful if you are using std::format (which wont need .c_str()
call but still i believe dont support <<
operator)
Or even more ugliness like
PLOGI<<"asd"<<std::format("...",v1,v2,v3) << plog::hexdump << "dfgh";
Actual usecase example right now (i implemented to_string
already)
PLOGW << std::format("call. len:{} input: {}(@{:#x}) result: {} st:\n{}",
length,
plog::hexdump(input, min_l).separator("", "").to_string(),
(uint64_t)input,//input is char* so needs casting to display address
plog::hexdump(out, 32).separator("", "").to_string(),
stacktrace);
from plog.
Related Issues (20)
- [Question] How to use Chained for multiple Classes within many DLL's
- \r\n for TxtFormatter in raw consoles HOT 4
- [Question] How to add custom prefix (record) information? HOT 2
- Can't add ConsoleAppender in a if statement HOT 2
- std::filesystem::path issue with new utf-8 mode on MSVC/Windows HOT 5
- Capture stdout and redirect to plog HOT 11
- How to use plog library in mac, its not working in mac for me HOT 5
- Please add instruction how to run samples HOT 3
- Features say doesnt require c++11 but code uses c++11 HOT 3
- Plog not initializing with too long of a file name? HOT 3
- License + create custom logger for open62541 HOT 2
- How to log an indented multiline text? HOT 2
- SyslogFormatter HOT 1
- write to /var/log/syslog HOT 1
- Cannot resolve symbol "init" HOT 2
- README does not talk about "Initializers" at https://github.com/SergiusTheBest/plog?tab=readme-ov-file#step-2-initialization HOT 2
- How to chain multiple shared lib's log, and identify log content using log header or instance id? HOT 2
- DynamicAppender can not work good HOT 2
- A few proposals HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plog.