Cedric,

while I agree with performance concerns, nobody is doing core parts in
C++ (yet), so for the random app user this is negligible performance
hit. Of course C++ mixes nicely with C, so it is still possible to use
the original macros/functions which will execute vfprintf() only if
log level is required.

Felipe, could we make the operator implementations just return if
current log level is not to be used? Like, in the beginning of the
operator we could do:

    if (eina_log_domain_registered_level_get(mydom.id) >
EINA_LOG_LEVEL_DBG) return;  // used for mydom.dbg "io";

that way the performance impact is negligible. AFAIR the evaluation is
left->right, thus the following could be grouped as:

    mydom.dbg << "hello world" << 0.3456;
   (mydom.dbg << "hello world") << 0.3456;

which usually the operator<<() would return an instance of itself,
then it results in:

   mydom.dbg << "hello world" << 0.3456;
   mydom.dbg << "hello world";  mydom.dbg << 0.3456;

so if operator<<() does the level check (which is very light), then we
get performance and usability.



On Mon, Mar 10, 2014 at 4:19 AM, Cedric BAIL <cedric.b...@free.fr> wrote:
> On Mon, Mar 10, 2014 at 2:47 AM, Gustavo Sverzut Barbieri
> <barbi...@gmail.com> wrote:
>> On Mon, Mar 10, 2014 at 12:37 AM, Felipe Magno de Almeida
>> <fel...@expertisesolutions.com.br> wrote:
>>> cedric pushed a commit to branch master.
>>>
>>> http://git.enlightenment.org/core/efl.git/commit/?id=416376e03c8ac2f5fa990956fbebcada5704c666
>>>
>>> commit 416376e03c8ac2f5fa990956fbebcada5704c666
>>> Author: Felipe Magno de Almeida <fel...@expertisesolutions.com.br>
>>> Date:   Mon Mar 10 12:25:20 2014 +0900
>>>
>>>     eina-cxx: Added eina_log support for C++, using IOStreams syntax
>>>
>>>     Summary:
>>>     Added eina_log support for C++ using the following macros:
>>>
>>>     For logging into a domain:
>>>
>>>     EINA_CXX_DOM_LOG
>>>     EINA_CXX_DOM_LOG_CRIT
>>>     EINA_CXX_DOM_LOG_ERR
>>>     EINA_CXX_DOM_LOG_INFO
>>>     EINA_CXX_DOM_LOG_DBG
>>>     EINA_CXX_DOM_LOG_WARN
>>>
>>>     And for logging into the default domain:
>>>
>>>     EINA_CXX_LOG
>>>     EINA_CXX_LOG_CRIT
>>>     EINA_CXX_LOG_ERR
>>>     EINA_CXX_LOG_INFO
>>>     EINA_CXX_LOG_DBG
>>>     EINA_CXX_LOG_WARN
>>>
>>>     The usage is simple as can be seen in the tests:
>>>
>>>       efl::eina::log_domain domain("error_domain_name");
>>>       domain.set_level(efl::eina::log_level::critical);
>>>       EINA_CXX_DOM_LOG_CRIT(domain, "something went wrong with the 
>>> following error: " << error);
>>
>> couldn't this be exposed in a shorter form, similar to:
>>
>> using namespace efl::eina:log;
>>
>>     err << "hi there" << 5;
>>     mydom.dbg << "hello world" << 0.3456;
>>
>> no idea how to make it able to detect end of line so it issue the
>> actual eina log print call, I always see people doing <<endl, so we
>> could use the same, at each <<endl we flush by doing a new print call.
>> So this would be allowed:
>>
>>    err << "hi there" << 5 << endl << "new line" << endl;
>>    mydom.dbg << "hello world << 0.345 << endl << "new line" << endl;
>>
>> This would have a nice side effect that is to accumulate the string
>> among different calls, producing a single output that in C would need
>> to use strcat()/sprintf() such as:
>>
>>    mydom.dbg << "options:";
>>    for (i = 0; i < options.length(); i++) mydom.dbg << " " << options.get(i);
>>    mydom.dbg << endl;
>>
>> I'm not sure if you can get caller information in C++ without
>> resorting to CPP. If you can't, then something like this may do:
>>
>>   EINA_LOG(mydom.dbg) << "hello world" << 0.3456 << endl;
>>
>> would expand to something like: mydom.dbg(__FILE__, __LINE__, __FUNCTION__)
>>
>>
>> Anyway I find the current implementation of this patch quite awful :-D
>>
>>     EINA_CXX_DOM_LOG_CRIT(domain, "foo 0x" << std::hex << 10);
>>     EINA_CXX_LOG_CRIT("foo 0x" << std::hex << 10);
>>
>> versus:
>>
>>     EINA_LOG(domain.crit) << "foo 0x" << std::hex << 10 << endl;
>>     EINA_LOG(crit) <<  "foo 0x" << std::hex << 10 << endl;
>>
>> (assuming the long version with macro and endl is required)
>
> This solution has a draw back, you will always execute the string
> generation even when not needed. I do think it will impact speed and
> will limit the use case for efl::eina::log.
> --
> Cedric BAIL
>
> ------------------------------------------------------------------------------
> Learn Graph Databases - Download FREE O'Reilly Book
> "Graph Databases" is the definitive new guide to graph databases and their
> applications. Written by three acclaimed leaders in the field,
> this first edition is now available. Download your free book today!
> http://p.sf.net/sfu/13534_NeoTech
> _______________________________________________
> enlightenment-devel mailing list
> enlightenment-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/enlightenment-devel



-- 
Gustavo Sverzut Barbieri
--------------------------------------
Mobile: +55 (19) 99225-2202
Contact: http://www.gustavobarbieri.com.br/contact

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to