[mlview-list] lower compile time, new logging system and maybe more power to the source view



Hello,

A couple of patches hit my mlview--dodji--0.9 branch recently.
I tought it could be interesting to share these new bits with you guys :-)

1/try to lower compile time [in mlview--main--0.9]
===========================

Lots of *.h files include headers of the STL. This results in longer compile time
since headers like iostream can pull lots of bits in.
Ideally, a .h file shouldn't include any header file. Its dependancies should
be included by the client *.cc files. The problem is the dependency hell the
coder has to face in that case.
As a tradeoff, I choosed to avoid including standard headers
and the gtkmm.h in *.h files. Headers of the mlview project can be included in
*.h files.

So what I did is to that respect is to remove all the c++ standard files (C standard files are okay) from the *.h files of mlview and I updated the *.cc accordingly to
have the project compile, link and run.

It would be nice if new patches that get in ca follow this guideline.

This changes have been committted to mlview--main--0.9--patch-27

2/added a new logging system to mlview [in mlview--dodji--0.9]
===============================================================

This week end, I wrote the beginning of a new logging system for mlview.
The rationale of this logging system is that logging should be activated or deactivated
without recompilation. Also we should be able to dump logs in files so that
users can send us the logs when reporting a bug or a crash.

The log stream is based on a LogStream class.

That class is basically a stream to which you can log strings.
The strings can be thrown to stdout, stderr, or to a file.

One can use the log stream class like:
~=~
LogStream out ;
out << "Hello" ;
~=~

or like:

~=~
LogStream out (LogStream::FILE_STREAM, /tmp/log.txt) ;
out << "Yeah, logging to a file" ;
~=~

~=~
LogStream out (LogStream::FILE_STREAM) ;
out << "By default, the log file is ~/.mlview/log.txt\n" ;
~=~

That's for the big picture.
To do real logging in the code, I provide you with macros in
mlview-log-utils.h.

Basically, to log some string, you can do:

~=~
LOG ("hey, this is a log string!") ;
~=~

Or:

~=~
LOG ("I can log numbers like: " << 1) ;
LOG ("I can" + " do this " + "too!") ;
~=~

Last but not least, you can also log a scope. For example, you'd like
to log the beginning and the end of a function:

~=~
foo::bar ()
{
	LOG_SCOPE ("foo::bar function") ;

	do_this () ;
	do_that () ;
}
~=~

The log scope macro is quite magic. It logs the string given in parameter (plus some
boiler plate inforamtion like the current date and time)  at the beginning of the function and also logs the same string at the end of the function, and as a bonus it logs
the time elapsed between the two logged lines ! Oh, and there is a macro
called 'MLVIEW_FUNCTION_NAME' that expands to the fully qualified  name of the
current function. So, to log the scope of your functions you can do:

~=~
foo::bar (char* a_param)
{
	LOG_SCOPE (MLVIEW_FUNCTION_NAME) ;
}
~=~

As it names suggests, you can use this macro to log any scope. Anything delimited
by '{' and '}'.

This logging system also supports log levels. There are only two predefined log levels
at the moment: normal and verbose.

The normal log level should be used for asserts and logs that happen only in exceptional conditions. The verbose log level should be used for everything else.

When you use the 'LOG ("message")' macro, it uses the normal log level.
To log using the verbose log level, use the LOG_VERBOSE ("message")  macro.
The LOG_SCOPE("scope name") uses the verbose log level.

To wire evething up, I have added a --verbose option to mlview to see the verbose log level messages.
In the verbose log level, of course, the normal logs are also dumped whereas in the normal log level, only the normal messages are shown.

So to see logs in action, launch mlview --verbose.
You can do mlview --verbose --logtofile to dump all the logs into ~/.mlview/log.txt .

So, in short, for logging, we shouldn't see any cerr << "foo" ; or cout << "foo" ; in the code anymore :-). Everybody should use LOG ("foo") ; LOG_VERBOSE ("foo") ; now :-)

That's enough for today :-) To learn more about how to use the logging system, don't
hesitate to ask me questions or to read the code :-)

I have comitted these changes to mlview--dodji--0.9--patch-34.

3/more editing power to the source view
=======================================

This item is still a work in progress; nothing works yet.

I am working on bringing the following features to the source view:

	+ go to the next/previous xml block
	+ Indent the current xml I am typing
	+ parse the document as I type, and higlight the errors.
	+ validate the document as I type, and highlight the errors.
	+ do element and attributes name completion as I type.

This is a lot of work, but it has to be done. I think that you shouldn't be
obliged to use emacs if you want to type xml as text, and still have the beast
to help you parse your document, validate it and do completion based on schemas :-).

Time is coming for use to focus on these features at least to help people
write technical documents for GNOME, in XML. Stay tuned, and if you can't wait, send
patches :-)

Cheers,

Dodji.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]