C++实现 Android 远程调试log文件读写

news/2024/6/18 21:27:04 标签: android studio

ubuntu的实现:

新建安卓项目,选择natice c++
在项目的AndroidManifest.xml文件中添加

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

 c++示例代码如下:

#include <time.h>

#define WRITE_LOG(s, ...) do { \
FILE *f = fopen("/sdcard/log.txt", "a+"); \
  fprintf(f, s, __VA_ARGS__); \
  fflush(f); \
  fclose(f); \
} while (0)


void static print_curr_time()
{
    time_t tt = time(NULL);//这句返回的只是一个时间cuo
    tm* t= localtime(&tt);
    WRITE_LOG("%d-%02d-%02d %02d:%02d:%02d ",
              t->tm_year + 1900,
              t->tm_mon + 1,
              t->tm_mday,
              t->tm_hour,
              t->tm_min,
              t->tm_sec);
    return ;
}


print_curr_time();
WRITE_LOG( "hip_knee_ankle_value %f \n",hip_knee_ankle_value);

windows的实现:

Easyloggin++项目在Github上的开源地址:https://github.com/easylogging/easyloggingpp

下载:easylogging++.cc和easylogging++.h文件

csdn下载连接:https://download.csdn.net/download/wzhrsh/19662171

配置文件my_log.conf如下:

* GLOBAL:  
    ENABLED                 =   true  
    TO_FILE                 =   true  
    TO_STANDARD_OUTPUT      =   true  
    FORMAT                  =   "[%level | %datetime] | %msg"  
    FILENAME                =   "/sdcard/log_%datetime{%Y%M%d}.log"  
    MILLISECONDS_WIDTH      =   3  
    PERFORMANCE_TRACKING    =   false  
    MAX_LOG_FILE_SIZE       =   1048576  
    LOG_FLUSH_THRESHOLD     =   0  
      

      
* DEBUG:  
    FILENAME                =   "/sdcard/debug_log_%datetime{%Y%M%d}.log"  
      
* FATAL:  
    ENABLED                 =   false  
      
* ERROR:  
    FILENAME                =   "/sdcard/error_log_%datetime{%Y%M%d}.log"  
      
* VERBOSE:  
    ENABLED                 =   false

示例代码如下:

#define _CRT_SECURE_NO_WARNINGS
#include "easylogging++.h"  

INITIALIZE_EASYLOGGINGPP

int main(int argc, char** argv)
{
	float sum = 0;
	for (int i = 0; i < 200; i++) {
		sum = sum + i;
	}
	el::Configurations conf("my_log.conf");
	el::Loggers::reconfigureAllLoggers(conf);

	//LOG(TRACE) << "***** trace log  *****";
	LOG(DEBUG) <<"test_angle:"<< sum;
	//LOG(ERROR) << "***** error log  *****";
	//LOG(WARNING) << "***** warning log  *****";
	//LOG(INFO) <<  sum ;
	system("pause");
	return 0;
}

参考连接:https://www.yuque.com/lengyuezuixue/kggswo/kbodn3


http://www.niftyadmin.cn/n/483593.html

相关文章

232.Implement Queue using Stacks(Stack-Easy)

转载请注明作者和出处&#xff1a;http://blog.csdn.net/c406495762 Implement the following operations of a queue using stacks. push(x) – Push element x to the back of queue.pop() – Removes the element from in front of queue.peek() – Get the front element…

提升开发效率遇到的问题和总结

最近在开发AI运动方面的课程动作&#xff0c;由于课程动作很多&#xff0c;为了提升开发效率做了以下尝试&#xff1a; 1.将一些相似度高的代码封装成函数&#xff0c;这样可以提升写代码的效率和降低代码敲错的错误率&#xff0c;使课程代码更加的清晰。 遇到的问题&#xf…

20.Valid Parentheses(Stack-Easy)

转载请注明作者和出处&#xff1a;http://blog.csdn.net/c406495762 Given a string containing just the characters “(“, “)”, “{“, “}”, “[” and “]”, determine if the input string is valid. The brackets must close in the correct order, “()” and “…

150.Evaluate Reverse Polish Notation(Stack-Medium)

转载请注明作者和出处&#xff1a;http://blog.csdn.net/c406495762 Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are , -, *, /. Each operand may be an integer or another expression. Some examples: ["2"…

Caffe学习笔记(三):cifar10_quick_train_test.prototxt配置文件分析

转载请注明作者和出处&#xff1a;http://blog.csdn.net/c406495762 运行平台&#xff1a; Ubuntu14.04 在上篇笔记中&#xff0c;已经记录了如何进行图片数据格式的转换和生成txt列表清单文件。本篇笔记主要记录如何计算图片数据的均值和理解prototxt配置文件中各个层的参数。…

conda常用的使用技巧

退出conda base环境 conda deactivate 进入conda base环境 conda activate base 编辑 conda 环境变量 vim ~/.bashrc 创建环境&#xff1a;conda create -n 环境名称 python版本 激活环境&#xff1a;conda activate 环境名称

Caffe学习笔记(四):使用pycaffe生成train.prototxt、test.prototxt文件

转载请注明作者和出处&#xff1a;http://blog.csdn.net/c406495762 Python版本&#xff1a; Python2.7 运行平台&#xff1a; Ubuntu14.04 一、前言 了解到上一篇笔记的内容&#xff0c;就可以尝试自己编写python程序生成prototxt文件了&#xff0c;当然也可以直接创建文件…