SPDLOG适配鸿蒙Next,添加控制台sink

最近工作需要,原有的 native 模块需要编译支持 OHOS(BTW, OHOS 真的很容易拼错)。因此,我为 OHOS 增加了一个 console 的 sink,与 Android 基本一致。废话不多说,直接上代码吧。直接复制 android_sink.h 即可,里面的 level 转换和 output 接口改一下就能完美运行。当然,其中的 domain 和失败返回重试还有待商榷。

// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)

#pragma once

#include <spdlog/details/fmt_helper.h>
#include <spdlog/details/null_mutex.h>
#include <spdlog/details/os.h>
#include <spdlog/details/synchronous_factory.h>
#include <spdlog/sinks/base_sink.h>

#include <chrono>
// $OHOS_HOME/sdk/default/openharmony/native/sysroot/usr/include/hilog/log.h
#include <hilog/log.h>
#include <mutex>
#include <string>
#include <thread>

#if !defined(SPDLOG_OHOS_RETRIES)
#define SPDLOG_OHOS_RETRIES 2
#endif

namespace spdlog {
   
   
namespace sinks {
   
   

/*
 * OHOS sink (logging using OH_LOG_Print)
 */
template<typename Mutex
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值