R/message.R

Defines functions print.MSG_SPAN setTags.MSG_SPAN finish.MSG_SPAN otlog.MSG_SPAN print.MSG_TRACER startSpan.MSG_TRACER getMsgTracer

Documented in getMsgTracer

#' A Message Tracer
#'
#' This implements a tracer that delegates function calls to \code{message()}.
#'
#' @return a new tracer instance
#' @rdname message
#' @examples
#' z <- ot::getMsgTracer()
#' @export
getMsgTracer <- function() {
  structure(0, class="MSG_TRACER")
}

#' @export
startSpan.MSG_TRACER <- function(tracer, name, ..., childOf=list()) {
  ts <- Sys.time()
  span <- list(name=name,
               start=Sys.time(),
               tags=list(...),
               depth=paste0(childOf$depth,"  "),
               tracer=tracer)

  class(span) <- "MSG_SPAN"
  message(span$depth, "<", span$start, "> Entering: ", span$name)
  span
}

#' @export
print.MSG_TRACER <- function(x, ...) {}

###

#' @export
otlog.MSG_SPAN <- function(span, fmt, ..., timestamp=Sys.time()) {
  message(span$depth, "<", timestamp, "> ", sprintf(fmt, ...))
}

#' @export
finish.MSG_SPAN <- function(span, finishTime=Sys.time()) {
  message(span$depth, "<", finishTime, ">", "Exiting ", span$name)
}

#' @export
setTags.MSG_SPAN <- function(span, ...) {
  message(span$depth, "<", Sys.time(), ">", "Tag ", list(...), " on ", span$name)
}


#' @export
print.MSG_SPAN <- function(x, ...) {}

Try the ot package in your browser

Any scripts or data that you put into this service are public.

ot documentation built on July 8, 2020, 7:34 p.m.