Vala如何支持C语言的__function____file____line__宏?
How does Vala support the C language's __function__ __file__ __line__ macros?
我需要添加一些带有源文件名、函数名的日志信息,
行号等...
我查看了官方文档,但是没有找到...
那么,怎么办呢?
这通常是通过 GLib logging 完成的。
例如试试这个 Vala 应用程序:
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;
}
输出为:
$ 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
除了G_MESSAGES_DEBUG
,您还可以设置G_DEBUG
,见running GLib applications。
您也可以安装 a custom handler 和 Log.set_handler ()
。
还有Log.FILE
、Log.LINE
、Log.METHOD
等同于C宏的原始信息
我需要添加一些带有源文件名、函数名的日志信息,
行号等...
我查看了官方文档,但是没有找到...
那么,怎么办呢?
这通常是通过 GLib logging 完成的。
例如试试这个 Vala 应用程序:
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;
}
输出为:
$ 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
除了G_MESSAGES_DEBUG
,您还可以设置G_DEBUG
,见running GLib applications。
您也可以安装 a custom handler 和 Log.set_handler ()
。
还有Log.FILE
、Log.LINE
、Log.METHOD
等同于C宏的原始信息