[Logging-commits] r99 - handlers/pkg handlers/pkg/R pkg pkg/R pkg/man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Apr 18 08:16:46 CEST 2012


Author: mariotomo
Date: 2012-04-18 08:16:45 +0200 (Wed, 18 Apr 2012)
New Revision: 99

Modified:
   handlers/pkg/DESCRIPTION
   handlers/pkg/R/sentry.R
   pkg/DESCRIPTION
   pkg/R/logger.R
   pkg/R/oo.R
   pkg/man/addHandler.Rd
   pkg/man/getLogger.Rd
Log:
aligns the sentry handler with sentry 2.0 (4.0.6)

Modified: handlers/pkg/DESCRIPTION
===================================================================
--- handlers/pkg/DESCRIPTION	2011-10-12 20:00:51 UTC (rev 98)
+++ handlers/pkg/DESCRIPTION	2012-04-18 06:16:45 UTC (rev 99)
@@ -1,10 +1,10 @@
 Package: logging.handlers
-Version: 0.5-80
+Version: 0.5-99
 Date: 2011-04-27
 Title: extra logging handlers
 Author: Mario Frasca <mariotomo at gmail.com>
-Maintainer: Mario Frasca <mario.frasca at nelen-schuurmans.nl>
+Maintainer: Mario Frasca <mariotomo at gmail.com>
 Description: this package defines some useful actions for logging handlers.
 License: GPL (>=2)
 Depends: R (>= 2.12.0), logging
-Suggests: svUnit, RCurl, Ruuid, rjson
\ No newline at end of file
+Suggests: svUnit, RCurl, Ruuid, rjson, digest

Modified: handlers/pkg/R/sentry.R
===================================================================
--- handlers/pkg/R/sentry.R	2011-10-12 20:00:51 UTC (rev 98)
+++ handlers/pkg/R/sentry.R	2012-04-18 06:16:45 UTC (rev 99)
@@ -13,6 +13,8 @@
 ## along with the nens libraray.  If not, see
 ## <http://www.gnu.org/licenses/>.
 ##
+## Copyright © 2011, 2012 by Mario Frasca
+##
 ## Library    : logging
 ##
 ## Purpose    : implement a sentry logging handler
@@ -29,25 +31,23 @@
 sentryAction <- function(msg, conf, record, ...) {
   if(!all(c(require(RCurl),
             require(Ruuid),
-            require(rjson))))
-    stop("sentryAction depends on RCurl, Ruuid, rjson.")
+            require(rjson),
+            require(digest))))
+    stop("sentryAction depends on RCurl, Ruuid, rjson, digest.")
 
-  if (exists('psk', envir=conf)) {
-    if(!require(digest))
-      stop("authenticating sentryAction depends on digest.")
-  }  
-
   ## you install Ruuid this way (not with install.packages).
   ## source("http://bioconductor.org/biocLite.R")
   ## biocLite("Ruuid")
 
-  if (!exists('server', envir=conf))
-    stop("handler with sentryAction must have a 'server' element.\n")
-  if (!exists('sentry.key', envir=conf))
-    stop("handler with sentryAction must have a 'sentry.key' element.\n")
+  for(k in c("server", "sentry.private.key", "sentry.public.key", "project")) {
+    if (!exists(k, envir=conf))
+      stop(paste("handler with sentryAction must have a '", k, "' element.\n", sep=""))
+  }
 
   sentry.server <- with(conf, server)
-  sentry.key <- with(conf, sentry.key)
+  sentry.private.key <- with(conf, sentry.private.key)
+  sentry.public.key <- with(conf, sentry.public.key)
+  project <-  with(conf, project)
   client.name <- tryCatch(with(conf, client.name), error = function(e) "r.logging")
 
   if(missing(record))  # needed for `level` and `timestamp` fields.
@@ -61,31 +61,49 @@
     view.name <- perpretator.name
   }, error = function(e) "<interactive>")
 
-  data <- list("level" = as.numeric(record$level),
+  params <- list("project" = project,
+               "event_id" = gsub("-", "", as.character(getuuid())),
+               "culprit" = view.name,
+               "timestamp" = format(record$timestamp, "%Y-%m-%dT%H:%M:%S"),
                "message" = msg,
-               "view" = view.name,
-               "message_id" = as.character(getuuid()),
+               "level" = as.numeric(record$level),
                "logger" = record$logger,
                "server_name" = client.name)
 
   metadata <- list()
   metadata$call_stack <- paste(lapply(functionCallStack, deparse), collapse=" || ")
-  data$data <- metadata
+  params$extra <- metadata
 
-  repr <- as.character(base64(toJSON(data)))
+  repr <- as.character(toJSON(params))
 
-  url <- paste(sentry.server, "store", "", sep="/")
+  url <- paste(sentry.server, "api", "store", "", sep="/")
 
-  if (exists('psk', envir=conf)) {
-    ## we do not send the sentry.key but we authenticate the message
-    ## with a hmac value.
+  timestamp <- Sys.time()
+  timestampSeconds <- format(timestamp, "%s")
+  to.sign <- paste(timestampSeconds, repr, sep=' ')
+  signature <- hmac(sentry.private.key, to.sign, "sha1")
 
-    timestamp <- format(Sys.time(), "%Y-%m-%dT%X")
-    to.sign <- paste(timestamp, repr, sep=' ')
-    authentication <- hmac(with(conf, psk), to.sign, "SHA1")
+  x.sentry.auth.parts <- c(paste("sentry_version", "2.0", sep="="),
+                           paste("sentry_signature", signature, sep="="),
+                           paste("sentry_timestamp", timestampSeconds, sep="="),
+                           paste("sentry_key", sentry.public.key, sep="="),
+                           paste("sentry_client", "r-logging.handler", sep="="))
+  x.sentry.auth <- paste("Sentry", paste(x.sentry.auth.parts, collapse=", "))
+  hdr <- c('Content-Type' = 'application/octet-stream', 'X-Sentry-Auth' = x.sentry.auth)
 
-    postForm(url, style="POST", format="json", key=sentry.key, data=repr, authentication=authentication)
-  } else {
-    postForm(url, style="POST", format="json", key=sentry.key, data=repr)
-  }
+  httpPOST(url, httpheader = hdr, postfields = toJSON(params), verbose = TRUE)
+  
 }
+
+dotest <- function() {
+  conf <- environment()
+  assign('server', 'http://localhost:9000', envir=conf) 
+  assign('sentry.public.key', '654877c851f9499a951486fd7a0ae5e6', envir=conf) 
+  assign('sentry.private.key', 'ba71e150ed854b2088c48295e39bf3ca', envir=conf) 
+  assign('project', 1, envir=conf) 
+  assign('client.name', 'raven-R', envir=conf) 
+
+  record <- list(timestamp=Sys.time(), level=30, logger="root")
+
+  sentryAction("dotest", conf, record)
+}

Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION	2011-10-12 20:00:51 UTC (rev 98)
+++ pkg/DESCRIPTION	2012-04-18 06:16:45 UTC (rev 99)
@@ -1,10 +1,10 @@
 Package: logging
-Version: 0.6-92
+Version: 0.6-99
 Date: 2010-06-17
-Title: a tentative logging package
+Title: R logging package
 Author: Mario Frasca <mariotomo at gmail.com>
-Maintainer: Mario Frasca <mario.frasca at nelen-schuurmans.nl>
-Description: a logging package emulating the python logging package.
+Maintainer: Mario Frasca <mariotomo at gmail.com>
+Description: logging is a pure R package that implements the ubiquitous log4j package.
 License: GPL (>=2)
 Depends: R (>= 2.12.0), methods
 Suggests: svUnit

Modified: pkg/R/logger.R
===================================================================
--- pkg/R/logger.R	2011-10-12 20:00:51 UTC (rev 98)
+++ pkg/R/logger.R	2012-04-18 06:16:45 UTC (rev 99)
@@ -13,6 +13,8 @@
 ## along with the nens libraray.  If not, see
 ## <http://www.gnu.org/licenses/>.
 ##
+## Copyright © 2009-2012 by Mario Frasca
+##
 ## Library    : logging
 ##
 ## Purpose    : emulate the python standard logging package

Modified: pkg/R/oo.R
===================================================================
--- pkg/R/oo.R	2011-10-12 20:00:51 UTC (rev 98)
+++ pkg/R/oo.R	2012-04-18 06:16:45 UTC (rev 99)
@@ -13,6 +13,8 @@
 ## along with the nens libraray.  If not, see
 ## <http://www.gnu.org/licenses/>.
 ##
+## Copyright © 2011, 2012 by Mario Frasca
+##
 ## Library    : logging
 ##
 ## Purpose    : the object oriented interface

Modified: pkg/man/addHandler.Rd
===================================================================
--- pkg/man/addHandler.Rd	2011-10-12 20:00:51 UTC (rev 98)
+++ pkg/man/addHandler.Rd	2012-04-18 06:16:45 UTC (rev 99)
@@ -6,36 +6,46 @@
 \alias{removeHandler}
 \description{
   
-  use these functions to maintain the list of handlers attached to a logger.
+  use these functions to maintain the list of handlers attached to a
+  logger.
+
+  addHandler and removeHandler are also offered as methods of the
+  \var{Logger} S4 class. in that case there is no \var{logger} argument.
   
 }
 \title{add a handler to or remove one from a logger}
+\usage{
+addHandler(handler, ..., logger = "")
+removeHandler(handler, logger='')
+}
+\arguments{
+  \item{handler}{the name of the handler, or its action}
+  \item{...}{extra parameters for the action, to be stored in the handler list}
+  \item{logger}{character parameter for the functional form: the name of
+    the logger to which to attach the new handler, defaults to the root
+    logger}
+}
 \details{
 
   \dots may contain extra parameters that will be passed to the handler
   action.  some elements in the \dots will be interpreted here.
 
-  a handler has a \var{name} and at least the three fields:
+  handler are implemented as environments. within a logger a handler is
+  identified by its \var{name} and all handlers define at least the
+  three variables:
   \describe{
     \item{level}{all records at level lower than this are skipped.}
     \item{formatter}{a function getting a record and returning a string}
     \item{action(msg, handler)}{a function accepting two parameters: a
-  formatted log record and the handler itself.}}
+  formatted log record and the handler itself. making the handler a
+  parameter of the action allows us to have reusable action functions.}}
 
-  further a handler may have as many fields as you think you need.  keep
-  in mind the handler (and all of its fields) are passed to the action
-  function.
+  being an environment, a handler may define as many variables as you
+  think you need.  keep in mind the handler is passed to the action
+  function, which can check for existence and can use all variables that
+  the handler defines.
+  
 }
-\usage{
-addHandler(handler, ..., logger = "")
-removeHandler(handler, logger='')
-}
-\arguments{
-  \item{handler}{the name of the handler, or its action}
-  \item{...}{extra parameters for the action, to be stored in the handler list}
-  \item{logger}{the name of the logger to which to attach the new
-    handler, defaults to the root logger}
-}
 \examples{
 logReset()
 addHandler(writeToConsole)

Modified: pkg/man/getLogger.Rd
===================================================================
--- pkg/man/getLogger.Rd	2011-10-12 20:00:51 UTC (rev 98)
+++ pkg/man/getLogger.Rd	2012-04-18 06:16:45 UTC (rev 99)
@@ -3,11 +3,11 @@
 
 \name{getLogger}
 \alias{getLogger}
-\title{set defaults and get current values for the named logger}
+\title{set defaults and get the named logger}
 \description{
 
-  this makes sure a logger with a specific name exists and returns its
-  current values.  if not yet present, the logger will be created and
+  make sure a logger with a specific name exists and return it as a
+  \var{Logger} S4 object.  if not yet present, the logger will be created and
   given the values specified in the ... arguments.
 
 }



More information about the Logging-commits mailing list