Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added verbosity tool for jcborras

  • Loading branch information...
commit 84ae117f7f8c24c2d599e336d07a711c9e6a6011 1 parent 8366547
@johnmyleswhite authored
View
4 DESCRIPTION
@@ -1,8 +1,8 @@
Package: log4r
Type: Package
Title: A simple logging system for R, based on log4j.
-Version: 0.1-2
-Date: 2011-05-17
+Version: 0.1-3
+Date: 2011-06-23
Author: John Myles White
Maintainer: John Myles White <jmw@johnmyleswhite.com>
Description: logr4 provides an object-oriented logging system that uses an API roughly equivalent to log4j and its related variants.
View
1  NAMESPACE
@@ -16,3 +16,4 @@ export("logformat")
export("logformat.logger")
export("logformat<-")
export("logformat<-.logger")
+export("verbosity")
View
7 R/constants.R
@@ -4,3 +4,10 @@ WARN <- 3
ERROR <- 4
FATAL <- 5
LEVELS <- seq(DEBUG, FATAL)
+
+verbosity <- function(i)
+{
+ i <- ifelse(i > max(LEVELS), max(LEVELS), i)
+ i <- ifelse(i < min(LEVELS), min(LEVELS), i)
+ return(LEVELS[max(LEVELS) - i + 1])
+}
View
16 TODO
@@ -1,8 +1,8 @@
-(1) Put this snippet of code somewhere?
- write.message(logger, '============ New Logging Session Opened ============')
-
-(2) Use gettextf() to implement a formatting system.
-
-(3) Find source of following unreproducible error:
-
-Error in logger[["level"]] : subscript out of bounds
+- Put this snippet of code somewhere?
+ write.message(logger, '============ New Logging Session Opened ============')
+- Use gettextf() to implement a formatting system.
+- Find source of following unreproducible error:
+ Error in logger[["level"]] : subscript out of bounds
+- Fix the following error:
+ * checking for unstated dependencies in examples ... NOTE
+ 'library' or 'require' call not declared from: optparse
View
BIN  log4r_0.1-2.tar.gz
Binary file not shown
View
BIN  log4r_0.1-3.tar.gz
Binary file not shown
View
43 man/verbosity.Rd
@@ -0,0 +1,43 @@
+\name{verbosity}
+\alias{verbosity}
+\title{
+ Converts an integer to a logging level
+}
+\description{
+ Converts an integer to an logging level defined in this package.
+}
+\usage{
+ verbosity(i)
+}
+\arguments{
+ \item{i}{
+ An integer from the set {1..5}. Otherwise it will be modified sensibly
+ to fit in that range.
+}
+}
+\value{
+ A logging level from the \code{log4r:::LEVELS} array. Giving
+ anything less or equal than 1 will return \code{log4r:::FATAL}. Giving
+ anything larger or equal than 5 will return \code{log4r:::DEBUG}.
+}
+\examples{
+library(optparse)
+library(log4r)
+
+optlist <- list(make_option(c('-v', '--verbosity-level'),
+ type = "integer",
+ dest = "verbosity",
+ default = 1,
+ help = "Verbosity threshold (5=DEBUG, 4=INFO 3=WARN, 2=ERROR, 1=FATAL)"))
+
+optparser <- OptionParser(option_list=optlist)
+opt <- parse_args(optparser)
+
+my.logger <- create.logger(logfile = "", level = verbosity(opt$verbosity))
+
+fatal(my.logger, "Fatal message")
+error(my.logger, "Error message")
+warn(my.logger, "Warning message")
+info(my.logger, "Informational message")
+debug(my.logger, "Debugging message")
+}
View
13 tests/2.R
@@ -0,0 +1,13 @@
+library('testthat')
+
+library('log4r')
+
+expect_that(verbosity(-19), equals(log4r:::FATAL))
+expect_that(verbosity(-1), equals(log4r:::FATAL))
+expect_that(verbosity(1), equals(log4r:::FATAL))
+expect_that(verbosity(2), equals(log4r:::ERROR))
+expect_that(verbosity(3), equals(log4r:::WARN))
+expect_that(verbosity(4), equals(log4r:::INFO))
+expect_that(verbosity(5), equals(log4r:::DEBUG))
+expect_that(verbosity(6), equals(log4r:::DEBUG))
+expect_that(verbosity(60), equals(log4r:::DEBUG))
Please sign in to comment.
Something went wrong with that request. Please try again.