Login with Vala

I am new to Vala programming and have experience with Java and .NET, but I could not find anything useful in how to register with Vala. Is there any useful logging facility, such as log4j or log4net, or what is offered to log into Vala with scaling to several levels of logging such as error, warning, debugging and tracing? What about defensive programs such as approvals and contracts? Is there any or what way to offer defensive programming and get the most useful logs with stack and exact reasons? Thanks for the advice.

+8
logging defensive-programming vala
source share
3 answers

Logging

Vala has some pretty powerful logging tools built in. You can use debug() , message() , warning() , error() and critical() as shortcuts for the slightly more complex log() . All of them are included in the database (automatically included) GLib namespace .

If you want to redirect log output or send different types of messages to different destinations, all you need is in the GLib.Log namespace . You might want to read glib docs while logging for what happens behind the scenes.

Defensive programming

Vala also includes support for approvals and contracts. Short version: assert() and assert_not_reached() for assertions and requires() and ensures() in method signatures for contracts. See the Approval and Programming Contracts section of the manual for more information.

Error processing

Vala's error handling is a bit odd: similar to exceptions, but not exactly the same. The basics of the Error Handling lesson cover the basics very well, and again it may be helpful to read glib docs about errors to gain a deeper understanding of what is going on behind the scenes. As far as I know, there is no way to get the stack trace from Vala errors - just the type and message.

Best practics

As for best practices, I think Vala is pretty similar to Java or C #, that the practices you already know can be applied in a general sense. I suggest playing with these features to get a feel for how the features look in Vala. Good luck

+22
source share

In addition to @chazomaticus's wonderful answer, you can get a stacktrace from Vala without calling a call stack.

It is simply that it is not baked in the language of Vala.

I wrote a library like this: ivy

ivy

+3
source share

I would like to add 2 questions to @chazomaticus answer:

Further reading:

+1
source share

All Articles