我需要添加一些日志信息,包括源文件名、函数名、
行号等...
我查看了官方文档,但没有找到...
那么,该怎么办呢?
最佳答案
这通常通过 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 宏的原始信息。
关于vala - Vala如何支持C语言的__function__ __file__ __line__宏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36055888/