\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 <\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} \hyperlink{struct__Eina__Log__Domain}{Eina\_Log\_Domain} *domain,
              \hyperlink{group__Eina__Log__Group_ga5c0cd3a8463b76bb855805b70f58c7dd}{Eina\_Log\_Level} level 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->\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;

   \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} (!\hyperlink{group__Eina__Main__Group_gabf448ada5bc81a07342b66c6f818ee5e}{eina\_init}())
     \{
        printf(\textcolor{stringliteral}{"log during the initialization of Eina\_Log module\(\backslash\)n"});
        \textcolor{keywordflow}{return} EXIT\_FAILURE;
     \}

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

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

   \hyperlink{group__Eina__Main__Group_ga6741fcaba116e31e96ce14dcfa03f568}{eina\_shutdown}();

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