faking a C logging macro
    clayasaurus 
    clayasaurus at gmail.com
       
    Thu Apr 20 15:01:00 PDT 2006
    
    
  
According to the D change log @ version .116 this was included.
"Added __FILE__, __LINE__, __DATE__, __TIME__, __TIMESTAMP__."
Maybe ask Walter to add __FUNCTION__ ?
You might want to check out build's preprocessor stuff as well. 
http://www.dsource.org/forums/viewtopic.php?t=624
BCS wrote:
> Tydr Schnubbis wrote:
>> Can I get something like this in D, using mixins or whatever?
>>
>> #define log(s) logprintf(__FILE__ ": " __FUNCTION__ ": %s", s)
> 
> 
> sed "/log\(/logprintf(__FILE__ `: ` __FUNCTION__ `: %s`, /" in.d -o out.d
> 
> ???
> 
> No but seriously folks, I have wanted something like this a few times 
> myself. Particularly, some way to get the __FILE__, etc. set of 
> constants of the line where a template is instanced. Something like the 
> following would be great.
> 
> 
> 
> template log(
>   char[] s,
>   char[] fi = __FILE__,
>   int li = __LINE__,
>   char[] fn = __FUNCTION__)  // const defaults come from called location
> {
>     const char[] log = ...
> }
> 
> 
> main.d
> int i;
> void main()
> {
>     pragma(msg, log!("this is broken!!!");
> }
> 
> 
> 
> compile time output:
> main.d:4 this is broken!!!
> 
> 
    
    
More information about the Digitalmars-d-learn
mailing list