How does Vala support the C language's __function__ __file__ __line__ macros?

感情迁移 提交于 2019-12-24 02:17:04

问题


I need add some log informations with souce file name, function name,

line number etc...

I have check the official docs, but not found...

so, how to do for it ?


回答1:


This is usually done via GLib logging.

For example try this Vala application:

int main (string[] args) {
    // info () is not shown by default, set G_MESSAGES_DEBUG=all in your shell to see them
    info ("Hello World");
    warning ("Hello World");
    //assert_true (false);
    // error () terminates the program
    error ("Hello World");
    return 0;
}

The output is:

$ G_MESSAGES_DEBUG=all src/glib_logging_test 
** INFO: glib_logging_test.vala:4: Hello World

** (process:10129): WARNING **: glib_logging_test.vala:5: Hello World

** (process:10129): ERROR **: glib_logging_test.vala:9: Hello World
Trace/Breakpoint ausgelöst

You can also set G_DEBUG in addition to G_MESSAGES_DEBUG, see running GLib applications.

You can install a custom handler with Log.set_handler () as well.

There is also Log.FILE, Log.LINE, Log.METHOD for the raw information equivalent to the C macros.



来源:https://stackoverflow.com/questions/36055888/how-does-vala-support-the-c-languages-function-file-line-macros

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!