FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

mango.log help
Goto page 1, 2  Next
 
Post new topic   Reply to topic     Forum Index -> Mango
View previous topic :: View next topic  
Author Message
larsivi
Site Admin


Joined: 27 Mar 2004
Posts: 453
Location: Trondheim, Norway

PostPosted: Mon Jan 23, 2006 2:43 am    Post subject: mango.log help Reply with quote

Hey, I'm trying out mango.log, and sortof don't get why the following don't work (it is missing some parts here, but it works fine with writefln).
I want this output to the console, and AFAICS from the Log4J docs, the BasicConfigurator.configure just set up a console appender or something.

For the commandline
$ myproggie -D tester.o

I would expect the output

"Debug: Processing tester.o"

Code:

void main() {

    // Set up logger
    Logger logger = Logger.getLogger("ddl.debug");
    logger.setLevel(Logger.Level.None);
    BasicConfigurator.configure();

    // Here I use ArgParser, is called if the -D option is passed.
    parser.bind("-", "D", delegate uint(char[] value){
        if (logger.getLevel() == Logger.Level.None) {
            Stdout.println("Setting debug level");
            logger.setLevel(Logger.Level.Trace);
        }
        else {
            logger.setLevel(Logger.Level.None);
        }
        return 0;
    });

    // Then this is called for all other arguments
    parser.bindDefault(delegate uint(char[] value){
        logger.trace("Debug: Processing " ~ value);
    }
}
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Mon Jan 23, 2006 3:05 am    Post subject: Reply with quote

That's really odd. I just tried something similar, and it operates as expected. Does the message "Setting debug level" get displayed at all? Are you certain the delegate is being called once only? I ask because the else statement might somehow be invoked?

Perhaps it might be worthwhile trying this?

Code:

        if (logger.getLevel is logger.Level.None) {
           logger.setLevel (logger.Level.Trace);
           logger.trace ("Setting debug level");
         }
Back to top
View user's profile Send private message
larsivi
Site Admin


Joined: 27 Mar 2004
Posts: 453
Location: Trondheim, Norway

PostPosted: Mon Jan 23, 2006 3:10 am    Post subject: Reply with quote

kris wrote:
That's really odd. I just tried something similar, and it operates as expected. Does the message "Setting debug level" get displayed at all? Are you certain the delegate is being called once only? I ask because the else statement might somehow be invoked?

Perhaps it might be worthwhile trying this?

Code:

        if (logger.getLevel is logger.Level.None) {
           logger.setLevel (logger.Level.Trace);
           logger.trace ("Setting debug level");
         }


Hmm, I still don't get any logger output, tried some more combinations Razz

But I suppose I forgot an important part of information; I use linux, could it be an issue there?
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Mon Jan 23, 2006 3:12 am    Post subject: Reply with quote

larsivi wrote:
kris wrote:
That's really odd. I just tried something similar, and it operates as expected. Does the message "Setting debug level" get displayed at all? Are you certain the delegate is being called once only? I ask because the else statement might somehow be invoked?

Perhaps it might be worthwhile trying this?

Code:

        if (logger.getLevel is logger.Level.None) {
           logger.setLevel (logger.Level.Trace);
           logger.trace ("Setting debug level");
         }


Hmm, I still don't get any logger output, tried some more combinations Razz

But I suppose I forgot an important part of information; I use linux, could it be an issue there?


Give me a moment and I'll check it out ...
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Mon Jan 23, 2006 3:15 am    Post subject: Reply with quote

I just tried the logging.d example (in mango/example) on Ubuntu/VMPlayer, and it operates as expected. Can you perhaps check that out also?

- Kris
Back to top
View user's profile Send private message
larsivi
Site Admin


Joined: 27 Mar 2004
Posts: 453
Location: Trondheim, Norway

PostPosted: Mon Jan 23, 2006 3:20 am    Post subject: Reply with quote

kris wrote:
I just tried the logging.d example (in mango/example) on Ubuntu/VMPlayer, and it operates as expected. Can you perhaps check that out also?

- Kris


Hmm, it works for me too, and I modelled my use on that example. You almighty Kris of the Mango, what do I do wrong?
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Mon Jan 23, 2006 3:25 am    Post subject: Reply with quote

Laughing

Do you even get anything if you do this:

Code:
    BasicConfigurator.configure();
    Logger logger = Logger.getLogger("ddl.debug");
    logger.trace ("starting");


I'm grasping at straws, but perhaps configure() needs to be called first? It shouldn't have to be, but let's try it?

- Kris


(p.s. You didn't say whether the "setting debug level" was emitted)
Back to top
View user's profile Send private message
larsivi
Site Admin


Joined: 27 Mar 2004
Posts: 453
Location: Trondheim, Norway

PostPosted: Mon Jan 23, 2006 3:36 am    Post subject: Reply with quote

kris wrote:
Laughing

Do you even get anything if you do this:

Code:
    BasicConfigurator.configure();
    Logger logger = Logger.getLogger("ddl.debug");
    logger.trace ("starting");


I'm grasping at straws, but perhaps configure() needs to be called first? It shouldn't have to be, but let's try it?

- Kris


(p.s. You didn't say whether the "setting debug level" was emitted)


Ok, I got it sorted out. What happens is that the setLevel(None) at the top is canceled out by the configurator call, meaning that my little test program didn't actually do anything. Bad luck really! Which probably hit my second and third tests too, because then I didn't try to move the configurator.

I don't know if the above is a bug, but it certainly pose no problems for me as it is.

A million thanks for thee!

Now, next question: How do I get rid of the "1 TRACE" etc at the start of each line?
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Mon Jan 23, 2006 4:17 am    Post subject: Reply with quote

The BasicConfigurator.configure() bugs me. It's in there for compatability, but I think it should be removed. Thoughts?

Formatting: Log4J has all kinds of nifty formatters available. Mango.log has only a few for now, but you apply them in the same manner as Log4J. Instead of calling BasicConfigurator.configure(), do this instead:

Code:
Logger.getRootLogger.addAppender (new ConsoleAppender (new LAYOUT));


where LAYOUT defines the formatting you want. Mango.log currently has SimpleLayout, SimpleTimerLayout (the one you don't like), DateLayout, and XmlLayout.

You can easily make your own Layout by copying one of the existing ones (see Layout.d and DateLayout.d). Here's what SimpleLayout looks like:

Code:
public class SimpleLayout : Layout
{
        char[] header (Event event)
        {
                event.append (event.getLevelName)
                     .append(event.getName)
                     .append(" - ");
                return event.getContent;
        }
}


Thus, you can create a new kind of layout and attach it as desired. If I wanted a MinimalLayout without the milliseconds/level displayed, I'd do this:

Code:
import mango.log.Layout;

public class MinimalLayout : Layout
{
        char[] header (Event event)
        {
                event.append(event.getName).append(" - ");
                return event.getContent;
        }
}


and attach it like so (instead of BasicConfigurator.configure):

Code:
Logger.getRootLogger.addAppender (new ConsoleAppender (new MinimalLayout));


In a similar fashion, one can add various 'appenders' to the logging system ~ each with independent layout handlers if you like. Appenders are invoked by traversing up the tree (towards the root), invoking each configured appender along the way. This means you can (a) configure the reporting in whatever manner you like (emit to the screen, and also to some remote monitor), and/or (b) configure the logging system to take different actions based upon the tree-location of various appenders. For example, you might have some low-level logging that you always want to log into a file ~ you would configure an appender just for that subtree in the following manner:

Code:
myLowLevelLogger.addAppender (new FileAppender (new FilePath("thefile"), new MinimalLayout));


The logger tree itself is built via the logger names. Thus, the name "low.level" is a parent to both "low.level.foo" and "low.level.bar". If you were to attach the above FileAppender to "low.level", then all logging to "low.level", "low.level.foo" and "low.level.bar" would end up in the file. On the other hand, logging to "xyz.wumpus" would not, since it's in a different subtree.

A note on formatting the logging content: if you need to emit printf() style format to a logger, I'd suggest considering mango.convert.Sprint as a means of constructing the output string. Also, you might consider using mango.io.Print instead of Stdout? I mention this only because Print is a bit lighter than Stdout.

Hope this helps!
Back to top
View user's profile Send private message
larsivi
Site Admin


Joined: 27 Mar 2004
Posts: 453
Location: Trondheim, Norway

PostPosted: Wed Jan 25, 2006 11:03 am    Post subject: Reply with quote

kris wrote:
The BasicConfigurator.configure() bugs me. It's in there for compatability, but I think it should be removed. Thoughts?

Formatting: Log4J has all kinds of nifty formatters available. Mango.log has only a few for now, but you apply them in the same manner as Log4J. Instead of calling BasicConfigurator.configure(), do this instead:

Code:
Logger.getRootLogger.addAppender (new ConsoleAppender (new LAYOUT));


where LAYOUT defines the formatting you want. Mango.log currently has SimpleLayout, SimpleTimerLayout (the one you don't like), DateLayout, and XmlLayout.

You can easily make your own Layout by copying one of the existing ones (see Layout.d and DateLayout.d). Here's what SimpleLayout looks like:

Code:
public class SimpleLayout : Layout
{
        char[] header (Event event)
        {
                event.append (event.getLevelName)
                     .append(event.getName)
                     .append(" - ");
                return event.getContent;
        }
}


Thus, you can create a new kind of layout and attach it as desired. If I wanted a MinimalLayout without the milliseconds/level displayed, I'd do this:

Code:
import mango.log.Layout;

public class MinimalLayout : Layout
{
        char[] header (Event event)
        {
                event.append(event.getName).append(" - ");
                return event.getContent;
        }
}


and attach it like so (instead of BasicConfigurator.configure):

Code:
Logger.getRootLogger.addAppender (new ConsoleAppender (new MinimalLayout));


In a similar fashion, one can add various 'appenders' to the logging system ~ each with independent layout handlers if you like. Appenders are invoked by traversing up the tree (towards the root), invoking each configured appender along the way. This means you can (a) configure the reporting in whatever manner you like (emit to the screen, and also to some remote monitor), and/or (b) configure the logging system to take different actions based upon the tree-location of various appenders. For example, you might have some low-level logging that you always want to log into a file ~ you would configure an appender just for that subtree in the following manner:

Code:
myLowLevelLogger.addAppender (new FileAppender (new FilePath("thefile"), new MinimalLayout));


The logger tree itself is built via the logger names. Thus, the name "low.level" is a parent to both "low.level.foo" and "low.level.bar". If you were to attach the above FileAppender to "low.level", then all logging to "low.level", "low.level.foo" and "low.level.bar" would end up in the file. On the other hand, logging to "xyz.wumpus" would not, since it's in a different subtree.

A note on formatting the logging content: if you need to emit printf() style format to a logger, I'd suggest considering mango.convert.Sprint as a means of constructing the output string. Also, you might consider using mango.io.Print instead of Stdout? I mention this only because Print is a bit lighter than Stdout.

Hope this helps!


Thanks for all the tips! The minimal layout was the one I wanted for now.

Your quick explanation of the logging trees (log.foo.bar and such) was excellent, it gave me much more than the API docs.

As for mango.io.Print/Stdout: this choice isn't relevant for mango.log, no?

And I will consider Sprint.

Thanks again!
Back to top
View user's profile Send private message
larsivi
Site Admin


Joined: 27 Mar 2004
Posts: 453
Location: Trondheim, Norway

PostPosted: Wed Jan 25, 2006 11:26 am    Post subject: Reply with quote

larsivi wrote:

And I will consider Sprint.


Hmm, using ?d (or ?s for that matter), gives me an assert error at line 171 in convert.Integer. Why does that happen? The call in question is this:

Code:

logger.trace(sprint("Debug: .rel.text has ?d relocation entries.", sechdrs[i].sh_size / sechdrs[i].sh_entsize));


sh_size and sh_entisize are uints, and as always, it worked fine with Stdout.println Wink
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Wed Jan 25, 2006 11:56 am    Post subject: Reply with quote

larsivi wrote:
larsivi wrote:

And I will consider Sprint.


Hmm, using ?d (or ?s for that matter), gives me an assert error at line 171 in convert.Integer. Why does that happen?

That is bizarre!

Perhaps there's some strange mismatch over obj files, or source files? You noted earlier that example/logging.d works? It uses the same kind of formatting as you appear to be, so this is most odd. Heck, ?s shouldn't get anywhere near Integer.convert Smile

I assume you're using the Sprint class, and stashing a sprint = new Sprint(xx); somewhere in your code?
Back to top
View user's profile Send private message
larsivi
Site Admin


Joined: 27 Mar 2004
Posts: 453
Location: Trondheim, Norway

PostPosted: Wed Jan 25, 2006 12:03 pm    Post subject: Reply with quote

kris wrote:
larsivi wrote:
larsivi wrote:

And I will consider Sprint.


Hmm, using ?d (or ?s for that matter), gives me an assert error at line 171 in convert.Integer. Why does that happen?

That is bizarre!

Perhaps there's some strange mismatch over obj files, or source files? You noted earlier that example/logging.d works? It uses the same kind of formatting as you appear to be, so this is most odd. Heck, ?s shouldn't get anywhere near Integer.convert Smile

I assume you're using the Sprint class, and stashing a sprint = new Sprint(xx); somewhere in your code?


Sorry for a couple of mistakes, here. The assert hit _only_ when I used ?s to print a number. Putting ?d everywhere got it working (I'd missed a couple of places Embarassed )
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Wed Jan 25, 2006 12:09 pm    Post subject: Reply with quote

And I just traced how ?s can get into Integer.convert; whoops Embarassed

I'll add a specific case for ?s in there, to do one of two things: either throw an error saying "must use ?d, ?b, ?x, ?X, ?o, or ?u for integer formatting", or silently pretend the ?s is a ?d instead.

What do you think?
Back to top
View user's profile Send private message
larsivi
Site Admin


Joined: 27 Mar 2004
Posts: 453
Location: Trondheim, Norway

PostPosted: Wed Jan 25, 2006 12:11 pm    Post subject: Reply with quote

kris wrote:
And I just traced how ?s can get into Integer.convert Smile

I'll add a specific case for ?s in there, to do one of two things: either throw an error saying "must use ?d, ?b, ?x, ?X, ?o, or ?u for integer formatting", or silently pretend the ?s is a ?d instead.

What do you think?


Well, the last one matches Stdout.println in functionality and might be better if you're sure it will always work.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Mango All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group