[ox/logconn] Change some C strings to StringViews, add macro for initializing logger
This commit is contained in:
parent
cf5786a4ed
commit
7755168004
27
deps/ox/src/ox/logconn/def.hpp
vendored
Normal file
27
deps/ox/src/ox/logconn/def.hpp
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2015 - 2023 gary@drinkingtea.net
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(DEBUG) && !defined(OX_BARE_METAL)
|
||||
#define OX_INIT_DEBUG_LOGGER(loggerName, appName) \
|
||||
ox::LoggerConn loggerName; \
|
||||
{ \
|
||||
const auto loggerErr = (loggerName).initConn(appName); \
|
||||
if (loggerErr) { \
|
||||
oxErrf("Could not connect to logger: {} ({}:{})\n", toStr(loggerErr), loggerErr.file, loggerErr.line); \
|
||||
} else { \
|
||||
ox::trace::setLogger(&(loggerName)); \
|
||||
} \
|
||||
ox::trace::init(); \
|
||||
}
|
||||
#else
|
||||
#define OX_INIT_DEBUG_LOGGER(loggerName, appName)
|
||||
#endif
|
||||
|
||||
|
2
deps/ox/src/ox/logconn/logconn.cpp
vendored
2
deps/ox/src/ox/logconn/logconn.cpp
vendored
@ -34,7 +34,7 @@ LoggerConn::~LoggerConn() noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
ox::Error LoggerConn::initConn(const char *appName) noexcept {
|
||||
ox::Error LoggerConn::initConn(ox::CRStringView appName) noexcept {
|
||||
sockaddr_in addr{};
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
||||
|
2
deps/ox/src/ox/logconn/logconn.hpp
vendored
2
deps/ox/src/ox/logconn/logconn.hpp
vendored
@ -38,7 +38,7 @@ class LoggerConn: public trace::Logger {
|
||||
LoggerConn &operator=(const LoggerConn&) noexcept = delete;
|
||||
ox::Error send(const trace::TraceMsg&) noexcept final;
|
||||
ox::Error sendInit(const trace::InitTraceMsg&) noexcept final;
|
||||
ox::Error initConn(const char *appName = "") noexcept;
|
||||
ox::Error initConn(ox::CRStringView appName) noexcept;
|
||||
ox::Error send(const char *buff, std::size_t len) const noexcept;
|
||||
private:
|
||||
void msgSend() noexcept;
|
||||
|
Loading…
Reference in New Issue
Block a user