Static String Concatenation

V

velusamypv

Hi,

The following is the logging mechanism used in the code i am
maintaining.

M_UM03_LOG_INFO ((M_UM03_INFO, "G_ul_DataValue1 = [%d], G_ul_DataValue2
= [%d], G_ul_DataValue3 = [%d], G_ul_DataValue4 = [%d],
G_ul_DataValue1, G_ul_DataValue2, G_ul_DataValue3, G_ul_DataValue4)) ;

Since the log line is very big, frequently we need to use horizontal
scroll to know what is logged.

To avoid horizontal scrolling, we did the following.
M_UM03_LOG_INFO ((M_UM03_INFO, "G_ul_DataValue1 = [%d], \
G_ul_DataValue2 = [%d], G_ul_DataValue3 = [%d], \
G_ul_DataValue4 = [%d]", G_ul_DataValue1, G_ul_DataValue2, \
G_ul_DataValue3, G_ul_DataValue4)) ;
But the above is also no good because the additional spaces " " will
be added to the log which is prepended in every line. i.e, the follwing
shall be printed.

"G_ul_DataValue1 = [1], G_ul_DataValue2 = [2], G_ul_DataValue3 =
[3], G_ul_DataValue4 = [4]"

Please suggest me to do this better. We already have the option of
using multiple log statements. But, Is there any way to change the one
line log for better code readability ?

I have tried an option of concatenation like "string1"+"string2" which
i remember have worked in some environment. Here the compiler is
throwing an error.

Thanks
 
L

Lew Pitcher

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

The following is the logging mechanism used in the code i am
maintaining.

M_UM03_LOG_INFO ((M_UM03_INFO, "G_ul_DataValue1 = [%d], G_ul_DataValue2
= [%d], G_ul_DataValue3 = [%d], G_ul_DataValue4 = [%d],
G_ul_DataValue1, G_ul_DataValue2, G_ul_DataValue3, G_ul_DataValue4)) ;

Since the log line is very big, frequently we need to use horizontal
scroll to know what is logged.

To avoid horizontal scrolling, we did the following.
M_UM03_LOG_INFO ((M_UM03_INFO, "G_ul_DataValue1 = [%d], \
G_ul_DataValue2 = [%d], G_ul_DataValue3 = [%d], \
G_ul_DataValue4 = [%d]", G_ul_DataValue1, G_ul_DataValue2, \
G_ul_DataValue3, G_ul_DataValue4)) ;
But the above is also no good because the additional spaces " " will
be added to the log which is prepended in every line. i.e, the follwing
shall be printed.

"G_ul_DataValue1 = [1], G_ul_DataValue2 = [2], G_ul_DataValue3 =
[3], G_ul_DataValue4 = [4]"

Please suggest me to do this better. We already have the option of
using multiple log statements. But, Is there any way to change the one
line log for better code readability ?

String constants can be broken up into a sequence of adjecent string constant
tokens, which will be concatinated together by the compiler at compile time. So
long as no other token intervenes, you can just break your big string constant
into several little ones, and put each on a separate line.

Something like...

M_UM03_LOG_INFO ((M_UM03_INFO,
"G_ul_DataValue1 = [%d], "
"G_ul_DataValue2 = [%d], "
"G_ul_DataValue3 = [%d], "
"G_ul_DataValue4 = [%d]",
G_ul_DataValue1, G_ul_DataValue2,
G_ul_DataValue3, G_ul_DataValue4)) ;

- --
Lew Pitcher
IT Specialist, Enterprise Data Systems,
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed are my own, not my employers')
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFD1TcmagVFX4UWr64RAkTVAKCSVHXPL2lrK61Ce0AS6rxXrnPhHgCg3eSk
TOaaT9T+JpjNt33bcnfJPtk=
=xQdy
-----END PGP SIGNATURE-----
 
M

Michael Mair

Hi,

The following is the logging mechanism used in the code i am
maintaining.

M_UM03_LOG_INFO ((M_UM03_INFO, "G_ul_DataValue1 = [%d], G_ul_DataValue2
= [%d], G_ul_DataValue3 = [%d], G_ul_DataValue4 = [%d],
G_ul_DataValue1, G_ul_DataValue2, G_ul_DataValue3, G_ul_DataValue4)) ;

This is not your actual code. Please do only
copy and paste if posting code.

I have tried an option of concatenation like "string1"+"string2" which
i remember have worked in some environment. Here the compiler is
throwing an error.

M_UM03_LOG_INFO ((M_UM03_INFO,
"G_ul_DataValue1 = [%d], "
"G_ul_DataValue2 = [%d], "
"G_ul_DataValue3 = [%d], "
"G_ul_DataValue4 = [%d]\n",
G_ul_DataValue1, G_ul_DataValue2,
G_ul_DataValue3, G_ul_DataValue4
));

Cheers
Michael
 
A

Artie Gold

Hi,

The following is the logging mechanism used in the code i am
maintaining.

M_UM03_LOG_INFO ((M_UM03_INFO, "G_ul_DataValue1 = [%d], G_ul_DataValue2
= [%d], G_ul_DataValue3 = [%d], G_ul_DataValue4 = [%d],
G_ul_DataValue1, G_ul_DataValue2, G_ul_DataValue3, G_ul_DataValue4)) ;

Since the log line is very big, frequently we need to use horizontal
scroll to know what is logged.

To avoid horizontal scrolling, we did the following.
M_UM03_LOG_INFO ((M_UM03_INFO, "G_ul_DataValue1 = [%d], \
G_ul_DataValue2 = [%d], G_ul_DataValue3 = [%d], \
G_ul_DataValue4 = [%d]", G_ul_DataValue1, G_ul_DataValue2, \
G_ul_DataValue3, G_ul_DataValue4)) ;
But the above is also no good because the additional spaces " " will
be added to the log which is prepended in every line. i.e, the follwing
shall be printed.

"G_ul_DataValue1 = [1], G_ul_DataValue2 = [2], G_ul_DataValue3 =
[3], G_ul_DataValue4 = [4]"

Please suggest me to do this better. We already have the option of
using multiple log statements. But, Is there any way to change the one
line log for better code readability ?

I have tried an option of concatenation like "string1"+"string2" which
i remember have worked in some environment. Here the compiler is
throwing an error.
Well, no. That's not C. ;-(

You can use implicit string concatenation, i.e. "this " "is " "a "
"string" is exactly the same as "this is a string".

HTH,
--ag
 
I

Ico

Hi,

The following is the logging mechanism used in the code i am
maintaining.

M_UM03_LOG_INFO ((M_UM03_INFO, "G_ul_DataValue1 = [%d], G_ul_DataValue2
= [%d], G_ul_DataValue3 = [%d], G_ul_DataValue4 = [%d],
G_ul_DataValue1, G_ul_DataValue2, G_ul_DataValue3, G_ul_DataValue4)) ;

It seems to me there is a missing quote in this example ?
Since the log line is very big, frequently we need to use horizontal
scroll to know what is logged.

To avoid horizontal scrolling, we did the following.
M_UM03_LOG_INFO ((M_UM03_INFO, "G_ul_DataValue1 = [%d], \
G_ul_DataValue2 = [%d], G_ul_DataValue3 = [%d], \
G_ul_DataValue4 = [%d]", G_ul_DataValue1, G_ul_DataValue2, \
G_ul_DataValue3, G_ul_DataValue4)) ;
But the above is also no good because the additional spaces " " will
be added to the log which is prepended in every line. i.e, the follwing
shall be printed.

Try something like this :

M_UM03_LOG_INFO ((M_UM03_INFO,
"G_ul_DataValue1 = [%d], G_ul_DataValue2 = [%d], "
"G_ul_DataValue3 = [%d], G_ul_DataValue4 = [%d]",
G_ul_DataValue1, G_ul_DataValue2,
G_ul_DataValue3, G_ul_DataValue4)) ;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,794
Messages
2,569,641
Members
45,355
Latest member
SJLChristi

Latest Threads

Top