muxspace/futile.logger — pull request #3 by asieira (2013-04-06 14:07:13+00:00)
Title: Small improvement to constants

When I was writing a custom layout function, I read the code to layout.simple. I quickly realized and I had no access to .LOG_LEVEL and so would have to replicate the code to turn a numeric log level into a meaningful string.

I have written and tested this alternative - assigning the string version of the level as the name of the constants:

```
> str(DEBUG)
Named int 8
- attr(*, "names")= chr "DEBUG"
> names(DEBUG)
[1] "DEBUG"
```

This way, .LOG_LEVEL is no longer necessary and the same data is available to package users when they write their custom layout functions. Now we can do away with .LOG_LEVEL completely and rewrite layout.simple as follows:

```
layout.simple <- function(level, msg, ...)
{
the.time <- format(Sys.time(), "%Y-%m-%d %H:%M:%S")
if (! is.null(substitute(...))) msg <- sprintf(msg, ...)
sprintf("%s [%s] %s\n", names(level),the.time, msg)
}
```

I have also set the constant values to be integer rather than numeric, just for efficiency purposes.