Skip to content

Commit 9879465

Browse files
committed
deprecate logging
1 parent f3883d7 commit 9879465

File tree

17 files changed

+56
-139
lines changed

17 files changed

+56
-139
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: nanonext
22
Type: Package
33
Title: NNG (Nanomsg Next Gen) Lightweight Messaging Library
4-
Version: 0.3.0.9003
4+
Version: 0.3.0.9004
55
Description: R binding for NNG (Nanomsg Next Gen), a successor to ZeroMQ. NNG is
66
a socket library providing high-performance scalability protocols,
77
implementing a cross-platform standard for messaging and communications.

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# nanonext 0.3.0.9003 (development)
1+
# nanonext 0.3.0.9004 (development)
22

33
#### New Features
44

@@ -11,6 +11,7 @@
1111
* Unified `send()` and `recv()` functions, and their asynchronous counterparts `send_aio()` and `recv_aio()`, are now S3 generics and can be used across Sockets, Contexts and Streams.
1212
* Revised 'block' argument for `send()` and `recv()` now allows an integer value for setting a timeout.
1313
* `send_ctx()` and `recv_ctx()` are deprecated and will be removed in a future package version - the methods for `send()` and `recv()` should be used instead.
14+
* Logging is deprecated and is being phased out. Logging can still be set via 'NANONEXT_LOG' prior to package load but the ability to set via the `logging()` function has been removed. Logging will be removed entirely in a future package version.
1415

1516
# nanonext 0.3.0
1617

R/listdial.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ dial <- function(socket,
8282
logerror(res)
8383
return(invisible(res))
8484
}
85-
if (logging()) loginfo(evt = "dial start", pkey = "sock", pval = attr(res, "socket"),
85+
if (.logging.) loginfo(evt = "dial start", pkey = "sock", pval = attr(res, "socket"),
8686
skey = "url", sval = url)
8787
} else {
8888
res <- .Call(rnng_dialer_create, .subset2(socket, "socket"), url)
@@ -109,7 +109,7 @@ dial <- function(socket,
109109
logerror(res)
110110
return(invisible(res))
111111
}
112-
if (logging()) loginfo(evt = "dial start", pkey = "sock", pval = attr(res, "socket"),
112+
if (.logging.) loginfo(evt = "dial start", pkey = "sock", pval = attr(res, "socket"),
113113
skey = "url", sval = url)
114114
} else {
115115
res <- .Call(rnng_dialer_create, socket, url)
@@ -208,7 +208,7 @@ listen <- function(socket,
208208
logerror(res)
209209
return(invisible(res))
210210
}
211-
if (logging()) loginfo(evt = "list start", pkey = "sock", pval = attr(res, "socket"),
211+
if (.logging.) loginfo(evt = "list start", pkey = "sock", pval = attr(res, "socket"),
212212
skey = "url", sval = url)
213213
} else {
214214
res <- .Call(rnng_listener_create, .subset2(socket, "socket"), url)
@@ -235,7 +235,7 @@ listen <- function(socket,
235235
logerror(res)
236236
return(invisible(res))
237237
}
238-
if (logging()) loginfo(evt = "list start", pkey = "sock", pval = attr(res, "socket"),
238+
if (.logging.) loginfo(evt = "list start", pkey = "sock", pval = attr(res, "socket"),
239239
skey = "url", sval = url)
240240
} else {
241241
res <- .Call(rnng_listener_create, socket, url)

R/messenger.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ messenger <- function(dial = NULL, listen = NULL) {
4141
close(sock)
4242
invisible()
4343
})
44+
cat("\014", file = stdout())
4445
intro <- unlist(strsplit("nanonext messenger", ""))
4546
for (i in seq_along(intro)) {
4647
cat("\r", `length<-`(intro, i), sep = " ", file = stdout())

R/methods.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ start.nanoListener <- function(x, ...) {
2929
xc <- .Call(rnng_listener_start, x)
3030
if (xc) {
3131
logerror(xc)
32-
} else if (logging()) {
32+
} else if (.logging.) {
3333
loginfo(evt = "list start", pkey = "sock", pval = attr(x, "socket"),
3434
skey = "url", sval = attr(x, "url"))
3535
}
@@ -46,7 +46,7 @@ start.nanoDialer <- function(x, async = TRUE, ...) {
4646
xc <- .Call(rnng_dialer_start, x, async)
4747
if (xc) {
4848
logerror(xc)
49-
} else if (logging()) {
49+
} else if (.logging.) {
5050
loginfo(evt = "dial start", pkey = "sock", pval = attr(x, "socket"),
5151
skey = "url", sval = attr(x, "url"))
5252
}
@@ -92,7 +92,7 @@ close.nanoSocket <- function(con, ...) {
9292
xc <- .Call(rnng_close, con)
9393
if (xc) {
9494
logerror(xc)
95-
} else if (logging()) {
95+
} else if (.logging.) {
9696
loginfo(evt = "sock close", pkey = "id", pval = attr(con, "id"),
9797
skey = "protocol", sval = attr(con, "protocol"))
9898
}
@@ -121,7 +121,7 @@ close.nanoDialer <- function(con, ...) {
121121
xc <- .Call(rnng_dialer_close, con)
122122
if (xc) {
123123
logerror(xc)
124-
} else if (logging()) {
124+
} else if (.logging.) {
125125
loginfo(evt = "dial close", pkey = "sock", pval = attr(con, "socket"),
126126
skey = "url", sval = attr(con, "url"))
127127
}
@@ -139,7 +139,7 @@ close.nanoListener <- function(con, ...) {
139139
xc <- .Call(rnng_listener_close, con)
140140
if (xc) {
141141
logerror(xc)
142-
} else if (logging()) {
142+
} else if (.logging.) {
143143
loginfo(evt = "list close", pkey = "sock", pval = attr(con, "socket"),
144144
skey = "url", sval = attr(con, "url"))
145145
}
@@ -157,7 +157,7 @@ close.nanoStream <- function(con, ...) {
157157
pkey <- if (is.null(attr(con, "dialer"))) "list" else "dial"
158158
sval <- attr(con, "url")
159159
xc <- .Call(rnng_stream_close, con)
160-
if (logging()) loginfo(evt = "stream close", pkey = pkey, pval = 1,
160+
if (.logging.) loginfo(evt = "stream close", pkey = pkey, pval = 1,
161161
skey = "url", sval = sval)
162162
invisible(xc)
163163

R/nanonext-package.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,11 @@
124124
NULL
125125

126126
.onLoad <- function(libname, pkgname) {
127-
logging <- logging()
128-
logging <<- logging
127+
.logging. <- switch(tolower(Sys.getenv("NANONEXT_LOG")),
128+
info = TRUE,
129+
FALSE)
130+
.logging. <<- .logging.
129131
invisible()
130132
}
131133

134+
.logging. <- FALSE

R/protocol.R

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@
2424
#' @examples
2525
#' pub <- socket("pub", listen = "inproc://nanonext")
2626
#' sub <- socket("sub", dial = "inproc://nanonext")
27-
#' logging(level = "info")
2827
#'
2928
#' subscribe(sub, "examples")
3029
#' send(pub, c("examples", "this is an example"), mode = "raw")
3130
#' recv(sub, "character")
3231
#' send(pub, c("other", "this other topic will not be received"), mode = "raw")
3332
#' recv(sub, "character")
3433
#'
35-
#' logging(level = "error")
3634
#' close(pub)
3735
#' close(sub)
3836
#'
@@ -43,7 +41,7 @@ subscribe <- function(socket, topic = NULL) {
4341
xc <- .Call(rnng_socket_set_string, socket, "sub:subscribe" , topic)
4442
if (xc) {
4543
logerror(xc)
46-
} else if (logging()) {
44+
} else if (.logging.) {
4745
loginfo(evt = "subscribe", pkey = "sock", pval = attr(socket, "id"),
4846
skey = "topic", sval = if (is.null(topic)) "ALL" else topic)
4947
}
@@ -78,7 +76,6 @@ subscribe <- function(socket, topic = NULL) {
7876
#' @examples
7977
#' pub <- socket("pub", listen = "inproc://nanonext")
8078
#' sub <- socket("sub", dial = "inproc://nanonext")
81-
#' logging(level = "info")
8279
#'
8380
#' subscribe(sub, NULL)
8481
#' send(pub, c("examples", "this is an example"), mode = "raw")
@@ -87,7 +84,6 @@ subscribe <- function(socket, topic = NULL) {
8784
#' send(pub, c("examples", "this example will not be received"), mode = "raw")
8885
#' recv(sub, "character")
8986
#'
90-
#' logging(level = "error")
9187
#' close(pub)
9288
#' close(sub)
9389
#'
@@ -98,7 +94,7 @@ unsubscribe <- function(socket, topic = NULL) {
9894
xc <- .Call(rnng_socket_set_string, socket, "sub:unsubscribe" , topic)
9995
if (xc) {
10096
logerror(xc)
101-
} else if (logging()) {
97+
} else if (.logging.) {
10298
loginfo(evt = "unsubscribe", pkey = "sock", pval = attr(socket, "id"),
10399
skey = "topic", sval = if (is.null(topic)) "ALL" else topic)
104100
}
@@ -133,7 +129,6 @@ unsubscribe <- function(socket, topic = NULL) {
133129
#' @examples
134130
#' sur <- socket("surveyor", listen = "inproc://nanonext")
135131
#' res <- socket("respondent", dial = "inproc://nanonext")
136-
#' logging(level = "info")
137132
#'
138133
#' survey_time(sur, 1000)
139134
#' send(sur, "reply to this survey")
@@ -144,7 +139,6 @@ unsubscribe <- function(socket, topic = NULL) {
144139
#'
145140
#' call_aio(aio)$data
146141
#'
147-
#' logging(level = "error")
148142
#' close(sur)
149143
#' close(res)
150144
#'
@@ -155,7 +149,7 @@ survey_time <- function(socket, time) {
155149
xc <- .Call(rnng_socket_set_ms, socket, "surveyor:survey-time", time)
156150
if (xc) {
157151
logerror(xc)
158-
} else if (logging()) {
152+
} else if (.logging.) {
159153
loginfo(evt = "survey", pkey = "sock", pval = attr(socket, "id"),
160154
skey = "set time", sval = as.character(time))
161155
}

R/socket.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ socket <- function(protocol = c("pair", "bus", "push", "pull", "req", "rep",
6969
logerror(res)
7070
return(invisible(res))
7171
}
72-
if (logging()) {
72+
if (.logging.) {
7373
loginfo(evt = "sock open", pkey = "id", pval = attr(res, "id"),
7474
skey = "protocol", sval = attr(res, "protocol"))
7575
}

R/stream.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ stream <- function(dial = NULL, listen = NULL, textframes = FALSE) {
4545
logerror(res)
4646
return(invisible(res))
4747
}
48-
if (logging()) {
48+
if (.logging.) {
4949
loginfo(evt = "stream open", pkey = "list", pval = 1L,
5050
skey = "url", sval = listen)
5151
}
@@ -58,7 +58,7 @@ stream <- function(dial = NULL, listen = NULL, textframes = FALSE) {
5858
logerror(res)
5959
return(invisible(res))
6060
}
61-
if (logging()) {
61+
if (.logging.) {
6262
loginfo(evt = "stream open", pkey = "dial", pval = 1L,
6363
skey = "url", sval = dial)
6464
}

R/utils.R

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -77,57 +77,25 @@ is_error_value <- function(x) inherits(x, "errorValue")
7777

7878
#' Logging Level
7979
#'
80-
#' Set the logging level of nanonext.
80+
#' This function is deprecated.
8181
#'
82-
#' @param level specify a logging level
83-
#' \itemize{
84-
#' \item{'keep'} {which keeps the current logging level}
85-
#' \item{'check'} {which checks the value of environment variable 'NANONEXT_LOG'}
86-
#' \item{'error'} {which sends all NNG errors to stderr}
87-
#' \item{'info'} {which in addition sends key informational events such as
88-
#' socket open etc. to stdout}
89-
#' }
82+
#' @param level specify a logging level. No longer used.
9083
#'
91-
#' @return Invisible NULL. A confirmation is printed to the console (stdout) if
92-
#' the logging level has changed. If the function is called with no arguments,
93-
#' the integer code of the logging level is returned instead.
84+
#' @return Invisible NULL. If the function is called with no arguments,
85+
#' the logical code of the logging level is returned instead.
9486
#'
9587
#' @details The environment variable 'NANONEXT_LOG' is checked automatically on
96-
#' package load and then cached for optimal performance. It is also checked
97-
#' each time \code{logging(level = "check")} is called. If the variable is
98-
#' set incorrectly, the default level of 'error' is used instead.
99-
#'
100-
#' @examples
101-
#' logging(level = "info")
102-
#' sock <- socket("respondent", dial = "inproc://nanolog")
103-
#' logging(level = "error")
104-
#' close(sock)
88+
#' package load. If the variable is set incorrectly, the default level
89+
#' of 'error' is used instead.
10590
#'
10691
#' @export
10792
#'
108-
logging <- function(level) {
109-
110-
cache <- switch(tolower(Sys.getenv("NANONEXT_LOG")),
111-
info = TRUE,
112-
FALSE)
113-
114-
logging <- function(level = c("keep", "check", "error", "info")) {
115-
116-
missing(level) && return(cache)
117-
level <- match.arg(level)
118-
original <- cache
119-
cache <<- switch(level,
120-
check = switch(tolower(Sys.getenv("NANONEXT_LOG")),
121-
info = TRUE,
122-
FALSE),
123-
error = FALSE,
124-
info = TRUE,
125-
keep = original)
126-
if (cache != original) cat(sprintf("%s [ %s ] %s: %s\n",
127-
format.POSIXct(Sys.time()), "log level", "set to",
128-
if (cache) "info" else "error"), file = stdout())
93+
logging <- function(level = c("keep", "check", "error", "info")) {
12994

130-
}
95+
missing(level) && return(.logging.)
96+
cat("nanonext logging is deprecated and this function can no longer be used\n",
97+
"logging level can still be set via the environment variable NANONEXT_LOG\n",
98+
"prior to package load for the time being\n", file = stderr())
13199

132100
}
133101

0 commit comments

Comments
 (0)