创建唯一消息标识符 [英] creating unique message identifiers

查看:93
本文介绍了创建唯一消息标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的应用程序中实现日志记录,以便每个日志

消息都有其唯一标识符,例如

log(标识符,文本)

我想要实现的是,如果带有

''identifier''的log()也用于代码中的某些其他地方,那么编译器会尖叫>
使''标识符''不是唯一的。

这是用C ++实现的吗?

谢谢

I''m trying to implement logging in my application, so that each log
message has its unique identifier, e.g.
log(identifier, text)
What I want to achieve is that the compiler screams if the log() with
''identifier'' is also used in some other place in the code which would
make the ''identifier'' not unique.
Is that something that can be achieved in C++?
Thanks

推荐答案

11月4日上午11点54分,mliptak< Meht ... @ gmail.comwrote:
On Nov 4, 11:54 am, mliptak <Meht...@gmail.comwrote:

我正在尝试在我的应用程序中实现日志记录,以便

每条日志消息都有其唯一标识符,例如

log(标识符,文本)

我想要实现的是编译器尖叫如果

log()带有''identifier''也用在其他地方

代码这会使''标识符''没有独一无二。

这是用C ++实现的吗?
I''m trying to implement logging in my application, so that
each log message has its unique identifier, e.g.
log(identifier, text)
What I want to achieve is that the compiler screams if the
log() with ''identifier'' is also used in some other place in
the code which would make the ''identifier'' not unique.
Is that something that can be achieved in C++?



这取决于标识符的类型,但一般来说,是的,

提供的日志是一个宏。在一般情况下,您需要一个本地

静态变量来实现它,并且在编译时直到知道实际标识符才能知道
。但是,如果标识符是文本,

你可以使用__FILE__和__LINE__用宏生成它。


-

James Kanze(GABI软件)电子邮件:ja ********* @ gmail.com

Conseils eninformatiqueorientéeobjet/

Beratung in objektorientierter Datenverarbeitung

9个地方Sémard,78210 St.-Cyr-l''coco,法国,+ 33(0)1 30 23 00 34

It depends on the type of identifier, but in general, yes,
provided log is a macro. In the general case, you need a local
static variable to achieve it, and the actual identifier won''t
be known until compile time. If identifier is text, however,
you can generate it with a macro using __FILE__ and __LINE__.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l''école, France, +33 (0)1 30 23 00 34


11月4日下午2:21 *,James Kanze< james.ka ... @ gmail.comwrote:
On Nov 4, 2:21*pm, James Kanze <james.ka...@gmail.comwrote:

11月4日上午11:54 ,mliptak< Meht ... @ gmail.comwrote:
On Nov 4, 11:54 am, mliptak <Meht...@gmail.comwrote:

我正在尝试在我的应用程序中实现日志记录,以便

每个日志消息都有其唯一的标识符,例如

log(标识符,文本)

我想要实现的是编译器如果
$ b会尖叫带有''标识符''的$ b log()也用于其他地方

代码whi ch会使''标识符''不唯一。

是否可以用C ++实现?
I''m trying to implement logging in my application, so that
each log message has its unique identifier, e.g.
log(identifier, text)
What I want to achieve is that the compiler screams if the
log() with ''identifier'' is also used in some other place in
the code which would make the ''identifier'' not unique.
Is that something that can be achieved in C++?



这取决于标识符的类型,但一般来说,是的,

提供的日志是一个宏。 *在一般情况下,你需要一个本地的

静态变量来实现它,并且在编译时直到知道实际的标识符才能知道
。 *如果标识符是文本,但是,

您可以使用__FILE__和__LINE__通过宏生成它。


It depends on the type of identifier, but in general, yes,
provided log is a macro. *In the general case, you need a local
static variable to achieve it, and the actual identifier won''t
be known until compile time. *If identifier is text, however,
you can generate it with a macro using __FILE__ and __LINE__.



如果我想自己设置标识符,而不是在

编译时生成(使用本地静态变量),该怎么办? />

我还在考虑使用__FILE__和__LINE__但是问题

这可能会在代码更改时发生变化,我需要有
为每封邮件修复了
标识符。

What if I want to set the identifier myself, not have it generated at
compile time (using local static variable)?

I was also thinking of using the __FILE__ and __LINE__ but the problem
is this could change when the code changes, and I need to have the
identifier fixed for each message.


11月4日上午10:54 * am,mliptak< Meht ... @ gmail.comwrote:
On Nov 4, 10:54*am, mliptak <Meht...@gmail.comwrote:

我正在尝试在我的应用程序中实现日志记录,以便每条日志

消息都有其唯一标识符,例如

log(标识符,文本)
I''m trying to implement logging in my application, so that each log
message has its unique identifier, e.g.
log(identifier, text)



你需要什么标识符?

What do you need that identifier for?


我是什么想要实现的是编译器尖叫如果带有

''标识符''的log()也用在代码中的某些其他地方,那就是'b $ b' '标识符''不是唯一的。
What I want to achieve is that the compiler screams if the log() with
''identifier'' is also used in some other place in the code which would
make the ''identifier'' not unique.



在一般情况下,通过链接单独编译的几个目标文件来构建二进制文件是不可能的。在这种情况下,你可以让链接器产生错误,但是,在动态库的情况下它仍然不会是b $ b。

-

Max

It is not possible in the general case when a binary is built by
linking several object files compiled separately. In this case you
could make the linker produce an error, however, it still would not be
possible in the presence of dynamic libraries.

--
Max


这篇关于创建唯一消息标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆