Giter VIP home page Giter VIP logo

outputredirect's Introduction

outputRedirect

Linux 输出重定向

用法

1 创建输出文件

outputRedirect testLog = {0};
outputRedirect_Init(&testLog, "test.log", MOED_WR_ONCE);
//MOED_WR_ONCE 创建新的文件(会覆盖存在文件)  
//MODE_WR_APPEND 追加到存在的文件

2 设置文件最大容量

outputRedirect_SetMaxSize(&testLog, 1 * 1024 * 1024);//设置文件最大大小为1M
//当文件达到最大容量时,会将文件内容清零,从文件头开始写入
//不设置或者设置为0时不限制大小

3 开始重定向

outputRedirect_Start(&testLog);

printf(FONT_COLOR_RED "Test\n" FONT_COLOR_BLACK);
//这个时候printf putc等函数会输出到test.log文件
//其中FONT_COLOR_RED FONT_COLOR_BLACK等是字体颜色宏,参考头文件,用于辅助输出提示

outputRedirect_OriPrintf(FONT_COLOR_RED "Test1\n" FONT_COLOR_BLACK);
//outputRedirect_OriPrintf 函数总会把内容输出到原始的输出源(例如控制台),不受 outputRedirect_Start 影响
//outputRedirect_FilePrintf 函数总会把内容输出到文件,不受 outputRedirect_Start 影响
//outputRedirect_AllPrintf 函数会把内容同时输出到文件和原始输出源

outputRedirect_Flush(&testLog);//刷新输出缓存,讲输出内容写进硬盘

4 结束重定向

outputRedirect_End(&testLog);//结束重定向,printf等输出恢复
//结束时会强制刷新缓存

5 关闭输出文件

outputRedirect_Close(&testLog);
//关闭时会强制自动结束重定向
注意,暂时还不支持多线程(可以在多线程下使用全部接口,但是在多线程情况下,printf等输出结果未知, 可以用outputRedirect_OriPrintf、outputRedirect_FilePrintf或outputRedirect_AllPrintf代替)

outputredirect's People

Contributors

sherwinsshan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.