\hypertarget{eina_log_03_8c-example}{}\section{eina\+\_\+log\+\_\+03.\+c}

\begin{DoxyCodeInclude}
\textcolor{comment}{//Compile with:}
\textcolor{comment}{//gcc -Wall -o eina\_log\_03 eina\_log\_03.c `pkg-config --cflags --libs eina`}

\textcolor{preprocessor}{#include <stdlib.h>}
\textcolor{preprocessor}{#include <stdio.h>}

\textcolor{preprocessor}{#include <\mbox{\hyperlink{Eina_8h}{Eina.h}}>}

\textcolor{preprocessor}{#define log(fmt, ...)                                    \(\backslash\)}
\textcolor{preprocessor}{   eina\_log\_print(EINA\_LOG\_LEVEL\_ERR, \_\_FILE\_\_, \_\_FUNCTION\_\_, \_\_LINE\_\_, fmt, ##\_\_VA\_ARGS\_\_)}

\textcolor{keyword}{typedef} \textcolor{keyword}{struct }\_Data Data;

\textcolor{keyword}{struct }\_Data
\{
   \textcolor{keywordtype}{int} to\_stderr;
\};

\textcolor{keywordtype}{void} print\_cb(\textcolor{keyword}{const} \mbox{\hyperlink{struct__Eina__Log__Domain}{Eina\_Log\_Domain}} *domain,
              \mbox{\hyperlink{group__Eina__Log__Group_ga5c0cd3a8463b76bb855805b70f58c7dd}{Eina\_Log\_Level}} level \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}},
              \textcolor{keyword}{const} \textcolor{keywordtype}{char} *file,
              \textcolor{keyword}{const} \textcolor{keywordtype}{char} *fnc,
              \textcolor{keywordtype}{int} line,
              \textcolor{keyword}{const} \textcolor{keywordtype}{char} *fmt,
              \textcolor{keywordtype}{void} *data,
              va\_list args)
\{
   Data *d;
   FILE *output;
   \textcolor{keywordtype}{char} *str;

   d = (Data*)data;
   \textcolor{keywordflow}{if} (d->to\_stderr)
     \{
        output = stderr;
        str = \textcolor{stringliteral}{"stderr"};
    \}
   \textcolor{keywordflow}{else}
     \{
       output = stdout;
        str = \textcolor{stringliteral}{"stdout"};
     \}

   fprintf(output, \textcolor{stringliteral}{"%s:%s:%s (%d) %s: "},
           domain->\mbox{\hyperlink{struct__Eina__Log__Domain_adac00ef51a0009e12583ca5932275f2e}{domain\_str}}, file, fnc, line, str);
   vfprintf(output, fmt, args);
   putc(\textcolor{charliteral}{'\(\backslash\)n'}, output);
\}

\textcolor{keywordtype}{void} test(Data *data, \textcolor{keywordtype}{int} i)
\{
   \textcolor{keywordflow}{if} (i < 0)
      data->to\_stderr = 0;
   \textcolor{keywordflow}{else}
      data->to\_stderr = 1;

   \mbox{\hyperlink{group__Eina__Log__Group_gafb145e82df0f9441244832c94e87a21b}{EINA\_LOG\_INFO}}(\textcolor{stringliteral}{"Log message..."});
\}

\textcolor{keywordtype}{int} main(\textcolor{keywordtype}{void})
\{
   Data data;

   \textcolor{keywordflow}{if} (!\mbox{\hyperlink{group__Eina__Main__Group_gafee4bfc0e509b6ffed6598edf6f4b3de}{eina\_init}}())
     \{
        printf(\textcolor{stringliteral}{"log during the initialization of Eina\_Log module\(\backslash\)n"});
        \textcolor{keywordflow}{return} EXIT\_FAILURE;
     \}

   \mbox{\hyperlink{group__Eina__Log__Group_ga50184735e08f530d4139c28fcdb02fbb}{eina\_log\_print\_cb\_set}}(print\_cb, &data);

   test(&data, -1);
   test(&data, 0);

   \mbox{\hyperlink{group__Eina__Main__Group_ga2c8b4020427108a30c44707af22c99d3}{eina\_shutdown}}();

   \textcolor{keywordflow}{return} EXIT\_SUCCESS;
\}
\end{DoxyCodeInclude}
 