186 lines
20 KiB
HTML
186 lines
20 KiB
HTML
<!-- HTML header for doxygen 1.8.8-->
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<!-- For Mobile Devices -->
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
<meta name="generator" content="Doxygen 1.8.12"/>
|
|
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
|
|
<title>Elog: Etk log interface: Elog Tutorial: Add some Log (using)</title>
|
|
<!--<link href="tabs.css" rel="stylesheet" type="text/css"/>-->
|
|
<script type="text/javascript" src="dynsections.js"></script>
|
|
<link href="search/search.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="search/searchdata.js"></script>
|
|
<script type="text/javascript" src="search/search.js"></script>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css" />
|
|
<link href="customdoxygen.css" rel="stylesheet" type="text/css"/>
|
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
|
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
|
|
<script type="text/javascript" src="doxy-boot.js"></script>
|
|
</head>
|
|
<body>
|
|
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
|
|
<div class="container">
|
|
<div class="navbar-header">
|
|
<a class="navbar-brand">Elog: Etk log interface 0.4.0</a>
|
|
</div>
|
|
<div id="navbar" class="navbar-collapse collapse">
|
|
<ul class="nav navbar-nav">
|
|
<li><a href="index.html">Main Page</a></li>
|
|
<li><a href="pages.html">Related Pages</a></li>
|
|
<li><a href="namespaces.html">Namespaces</a></li>
|
|
<li><a href="annotated.html">Classes</a></li>
|
|
<li><a href="files.html">Files</a></li>
|
|
</ul>
|
|
<ul class="nav navbar-nav navbar-right">
|
|
<li class="dropdown">
|
|
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
|
|
Link-libs<span class="caret"></span>
|
|
</a>
|
|
<ul class="dropdown-menu">
|
|
<li><a href="http://HeeroYui.github.io/lutin">lutin</a></li>
|
|
<li><a href="http://atria-soft.github.io/ewol">ewol</a></li>
|
|
<li><a href="http://atria-soft.github.io/echrono">echrono</a></li>
|
|
<li><a href="http://atria-soft.github.io/etk">etk</a></li>
|
|
<li><a href="http://atria-soft.github.io/ejson">ejson</a></li>
|
|
<li><a href="http://atria-soft.github.io/exml">exml</a></li>
|
|
<li><a href="http://atria-soft.github.io/esvg">esvg</a></li>
|
|
<li><a href="http://atria-soft.github.io/egami">egami</a></li>
|
|
<li><a href="http://atria-soft.github.io/gale">gale</a></li>
|
|
<li><a href="http://atria-soft.github.io/ege">ege</a></li>
|
|
<li><a href="http://atria-soft.github.io/elog">elog</a></li>
|
|
<li><a href="http://atria-soft.github.io/ememory">ememory</a></li>
|
|
<li><a href="http://atria-soft.github.io/enet">enet</a></li>
|
|
<li><a href="http://atria-soft.github.io/eproperty">eproperty</a></li>
|
|
<li><a href="http://atria-soft.github.io/esignal">esignal</a></li>
|
|
<li><a href="http://atria-soft.github.io/etranslate">etranslate</a></li>
|
|
<li><a href="http://atria-soft.github.io/zeus">zeus</a></li>
|
|
<li><a href="http://musicdsp.github.io/audio-ess">audio-ess</a></li>
|
|
<li><a href="http://musicdsp.github.io/audio">audio</a></li>
|
|
<li><a href="http://musicdsp.github.io/audio-drain">audio-drain</a></li>
|
|
<li><a href="http://musicdsp.github.io/audio-orchestra">audio-orchestra</a></li>
|
|
<li><a href="http://musicdsp.github.io/audio-river">audio-river</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
<div id="search-box" class="input-group">
|
|
<div class="input-group-btn">
|
|
<button aria-expanded="false" type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
|
|
<span class="glyphicon glyphicon-search"></span>
|
|
<span class="caret"></span>
|
|
</button>
|
|
<ul class="dropdown-menu">
|
|
<li><a href="#">All</a></li>
|
|
<li><a href="#">Classes</a></li>
|
|
<li><a href="#">Namespaces</a></li>
|
|
<li><a href="#">Files</a></li>
|
|
<li><a href="#">Functions</a></li>
|
|
<li><a href="#">Variables</a></li>
|
|
<li><a href="#">Typedefs</a></li>
|
|
<li><a href="#">Enumerations</a></li>
|
|
<li><a href="#">Enumerator</a></li>
|
|
<li><a href="#">Friends</a></li>
|
|
<li><a href="#">Macros</a></li>
|
|
<li><a href="#">Pages</a></li>
|
|
</ul>
|
|
</div>
|
|
<button id="search-close" type="button" class="close" aria-label="Close">
|
|
<span aria-hidden="true"></span>
|
|
</button>
|
|
<input id="search-field" class="form-control" accesskey="S" onkeydown="searchBox.OnSearchFieldChange(event);" placeholder="Search ..." type="text">
|
|
</div>
|
|
</div><!--/.nav-collapse -->
|
|
</div>
|
|
</nav>
|
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
|
<div class="content" id="content">
|
|
<div class="container">
|
|
<div class="row">
|
|
<div class="col-sm-12 panel panel-default" style="padding-bottom: 15px;">
|
|
<div style="margin-bottom: 15px;margin-top: 60px;">
|
|
<!-- end header part -->
|
|
<!-- Generated by Doxygen 1.8.12 -->
|
|
<script type="text/javascript">
|
|
var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|
</script>
|
|
<script type="text/javascript" src="menudata.js"></script>
|
|
<script type="text/javascript" src="menu.js"></script>
|
|
<script type="text/javascript">
|
|
$(function() {
|
|
initMenu('',true,false,'search.php','Search');
|
|
$(document).ready(function() { init_search(); });
|
|
});
|
|
</script>
|
|
<div id="main-nav"></div>
|
|
<!-- window showing the filter options -->
|
|
<div id="MSearchSelectWindow"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
|
</div>
|
|
|
|
<!-- iframe showing the search results (closed by default) -->
|
|
<div id="MSearchResultsWindow">
|
|
<iframe src="javascript:void(0)" frameborder="0"
|
|
name="MSearchResults" id="MSearchResults">
|
|
</iframe>
|
|
</div>
|
|
|
|
<div id="nav-path" class="navpath">
|
|
<ul>
|
|
<li class="navelem"><a class="el" href="elog_tutorial.html">Tutorials</a></li> </ul>
|
|
</div>
|
|
</div><!-- top -->
|
|
<div class="header">
|
|
<div class="headertitle">
|
|
<div class="title">Elog Tutorial: Add some Log (using) </div> </div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
<div class="toc"><h3>Table of Contents</h3>
|
|
<ul><li class="level1"><a href="#elog_tutorial_01_declaration">Declaring the list of macro </a></li>
|
|
<li class="level1"><a href="#elog_tutorial_01_using_it">Using it </a></li>
|
|
<li class="level1"><a href="#elog_tutorial_01_external">Log in an external logger </a></li>
|
|
</ul>
|
|
</div>
|
|
<div class="textblock"><p>You might not use the log directly. The reson is simple:</p><ul>
|
|
<li>It is designed to be replaced by an other log library.</li>
|
|
</ul>
|
|
<p>This permit you to use custom log library just replacing Macro and basic functions</p>
|
|
<h1><a class="anchor" id="elog_tutorial_01_declaration"></a>
|
|
Declaring the list of macro </h1>
|
|
<p><b>debug.hpp</b></p>
|
|
<div class="fragment"><div class="line"></div><div class="line"><span class="preprocessor">#pragma once</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include <<a class="code" href="log_8hpp.html">elog/log.hpp</a>></span></div><div class="line"></div><div class="line"><span class="keyword">namespace </span>appl {</div><div class="line"> int32_t getLogId();</div><div class="line">};</div><div class="line"></div><div class="line"><span class="preprocessor">#define APPL_BASE(info,data) ELOG_BASE(appl::getLogId(),info,data)</span></div><div class="line"></div><div class="line"><span class="preprocessor">#define APPL_PRINT(data) APPL_BASE(-1, data)</span></div><div class="line"><span class="preprocessor">#define APPL_CRITICAL(data) APPL_BASE(1, data)</span></div><div class="line"><span class="preprocessor">#define APPL_ERROR(data) APPL_BASE(2, data)</span></div><div class="line"><span class="preprocessor">#define APPL_WARNING(data) APPL_BASE(3, data)</span></div><div class="line"><span class="preprocessor">#ifdef DEBUG</span></div><div class="line"><span class="preprocessor"> #define APPL_INFO(data) APPL_BASE(4, data)</span></div><div class="line"><span class="preprocessor"> #define APPL_DEBUG(data) APPL_BASE(5, data)</span></div><div class="line"><span class="preprocessor"> #define APPL_VERBOSE(data) APPL_BASE(6, data)</span></div><div class="line"><span class="preprocessor"> #define APPL_TODO(data) APPL_BASE(4, "TODO : " << data)</span></div><div class="line"><span class="preprocessor">#else</span></div><div class="line"><span class="preprocessor"> #define APPL_INFO(data) do { } while(false)</span></div><div class="line"><span class="preprocessor"> #define APPL_DEBUG(data) do { } while(false)</span></div><div class="line"><span class="preprocessor"> #define APPL_VERBOSE(data) do { } while(false)</span></div><div class="line"><span class="preprocessor"> #define APPL_TODO(data) do { } while(false)</span></div><div class="line"><span class="preprocessor">#endif</span></div><div class="line"></div><div class="line"><span class="preprocessor">#define APPL_ASSERT(cond,data) \</span></div><div class="line"><span class="preprocessor"> do { \</span></div><div class="line"><span class="preprocessor"> if (!(cond)) { \</span></div><div class="line"><span class="preprocessor"> APPL_CRITICAL(data); \</span></div><div class="line"><span class="preprocessor"> assert(!#cond); \</span></div><div class="line"><span class="preprocessor"> } \</span></div><div class="line"><span class="preprocessor"> } while (0)</span></div><div class="line"></div></div><!-- fragment --><p><b>debug.cpp</b></p>
|
|
<div class="fragment"><div class="line"></div><div class="line"><span class="preprocessor">#include "debug.hpp"</span></div><div class="line"></div><div class="line">int32_t appl::getLogId() {</div><div class="line"> <span class="keyword">static</span> int32_t g_val = <a class="code" href="namespaceelog.html#a7e40b0be74fd80765658df83f72a4e3e">elog::registerInstance</a>(<span class="stringliteral">"your application name"</span>);</div><div class="line"> <span class="keywordflow">return</span> g_val;</div><div class="line">}</div><div class="line"></div></div><!-- fragment --><ul>
|
|
<li>on your main application:</li>
|
|
</ul>
|
|
<div class="fragment"><div class="line"><span class="preprocessor">#include "debug.hpp"</span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="elog_8hpp.html">elog/elog.hpp</a>></span></div></div><!-- fragment --><div class="fragment"><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> _argc, <span class="keyword">const</span> <span class="keywordtype">char</span> *_argv[]) {</div><div class="line"> <span class="comment">// if you use etk/ewol/gale, elog init in contain in it.</span></div><div class="line"> <a class="code" href="namespaceelog.html#a1005ac82c94e09b499d29b70a98cd5cc">elog::init</a>(_argc, _argv);</div></div><!-- fragment --> <h1><a class="anchor" id="elog_tutorial_01_using_it"></a>
|
|
Using it </h1>
|
|
<p>You just need to call the macro whe you want to add debug log:</p>
|
|
<div class="fragment"><div class="line"> APPL_VERBOSE(<span class="stringliteral">"VERBOSE display"</span>);</div><div class="line"> APPL_DEBUG(<span class="stringliteral">"DEBUG display"</span>);</div><div class="line"> APPL_INFO(<span class="stringliteral">"INFO display"</span>);</div><div class="line"> APPL_WARNING(<span class="stringliteral">"WARNING display"</span>);</div><div class="line"> APPL_ERROR(<span class="stringliteral">"ERROR display"</span>);</div><div class="line"> APPL_PRINT(<span class="stringliteral">"PRINT display"</span>);</div><div class="line"> <span class="comment">//APPL_CRITICAL("CRITICAL display"); // Disable critical because it create an assert ...</span></div></div><!-- fragment --><h2>Specification of logs </h2>
|
|
<ul>
|
|
<li>*_CRITICAL(***); This will log the data and asert just after (display backtrace if possible)</li>
|
|
<li>*_PRINT(***); display on console (can not be removed with the log-level)</li>
|
|
</ul>
|
|
<h1><a class="anchor" id="elog_tutorial_01_external"></a>
|
|
Log in an external logger </h1>
|
|
<p>You must specify an external function that is receiving the logs:</p>
|
|
<div class="fragment"><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> myExternalLogCallback(<span class="keyword">const</span> <span class="keywordtype">char</span>* _libName, <span class="keyword">enum</span> <a class="code" href="namespaceelog.html#a2aac95a15381721219c16f6ff5b4fb89">elog::level</a> _level, int32_t _ligne, <span class="keyword">const</span> <span class="keywordtype">char</span>* _funcName, <span class="keyword">const</span> <span class="keywordtype">char</span>* _log) {</div></div><!-- fragment --><p> Now you must connect it on the elog backend:</p>
|
|
<div class="fragment"><div class="line"> <span class="comment">// Set a callback:</span></div><div class="line"> <a class="code" href="namespaceelog.html#a8c02ad11df203c22c7e65c759b43efdd">elog::setCallbackLog</a>(&myExternalLogCallback);</div></div><!-- fragment --> <div class="fragment"><div class="line"><a class="code" href="namespaceelog.html#a8c02ad11df203c22c7e65c759b43efdd">elog::setCallbackLog</a>(&myExternalLogCallback);</div></div><!-- fragment --><p>The full code of the callback: </p><div class="fragment"><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> myExternalLogCallback(<span class="keyword">const</span> <span class="keywordtype">char</span>* _libName, <span class="keyword">enum</span> <a class="code" href="namespaceelog.html#a2aac95a15381721219c16f6ff5b4fb89">elog::level</a> _level, int32_t _ligne, <span class="keyword">const</span> <span class="keywordtype">char</span>* _funcName, <span class="keyword">const</span> <span class="keywordtype">char</span>* _log) {</div><div class="line"> <span class="keywordflow">switch</span>(_level) {</div><div class="line"> <span class="keywordflow">default</span>:</div><div class="line"> std::cout << <span class="stringliteral">"[?] "</span>;</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> <a class="code" href="namespaceelog.html#a2aac95a15381721219c16f6ff5b4fb89a93c9ecff62779bddcc1bc2e7fc5dd829">elog::level_print</a>:</div><div class="line"> std::cout << <span class="stringliteral">"[P] "</span>;</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> <a class="code" href="namespaceelog.html#a2aac95a15381721219c16f6ff5b4fb89a4c2b8e97dbaeda89eb1fbce53e691625">elog::level_critical</a>:</div><div class="line"> std::cout << <span class="stringliteral">"[C] "</span>;</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> <a class="code" href="namespaceelog.html#a2aac95a15381721219c16f6ff5b4fb89add2b92a662d3e09201bfc37cf42f906c">elog::level_error</a>:</div><div class="line"> std::cout << <span class="stringliteral">"[E] "</span>;</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> <a class="code" href="namespaceelog.html#a2aac95a15381721219c16f6ff5b4fb89abe0c0f2534e916ba560a798d1392ce0c">elog::level_warning</a>:</div><div class="line"> std::cout << <span class="stringliteral">"[W] "</span>;</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> <a class="code" href="namespaceelog.html#a2aac95a15381721219c16f6ff5b4fb89aec0f38e9cdb484718ef007a57628e021">elog::level_info</a>:</div><div class="line"> std::cout << <span class="stringliteral">"[I] "</span>;</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> <a class="code" href="namespaceelog.html#a2aac95a15381721219c16f6ff5b4fb89a97d8804cb4c8776f67824ec0acf53efb">elog::level_debug</a>:</div><div class="line"> std::cout << <span class="stringliteral">"[D] "</span>;</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> <a class="code" href="namespaceelog.html#a2aac95a15381721219c16f6ff5b4fb89adf726904a7486e61530282123dbd58cd">elog::level_verbose</a>:</div><div class="line"> std::cout << <span class="stringliteral">"[V] "</span>;</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> }</div><div class="line"> std::cout << _libName << <span class="stringliteral">" ("</span> << _ligne << <span class="stringliteral">") "</span> << _funcName << <span class="stringliteral">" | "</span> << _log << std::endl;</div><div class="line">}</div></div><!-- fragment --><p> you can test the program:</p>
|
|
<div class="fragment"><div class="line">lutin -C -P -mdebug elog-sample?build?run:--elog-level=2</div></div><!-- fragment --> </div></div><!-- contents -->
|
|
<!-- HTML footer for doxygen 1.8.8-->
|
|
<!-- start footer part -->
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<hr class="footer"/><address class="footer"><small>
|
|
Generated on Mon Oct 24 2016 15:35:46 for Elog: Etk log interface by  <a href="http://www.doxygen.org/index.html">
|
|
<img class="footer" src="doxygen.png" alt="doxygen"/>
|
|
</a> 1.8.12
|
|
</small></address>
|
|
</body>
|
|
</html>
|