Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Remove global initialization of logger #174

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 57 additions & 0 deletions examples/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ members = [
"bigint",
"tuples",
"uuid",
"logging",
]
6 changes: 5 additions & 1 deletion examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ clean:
make -C bigint clean
make -C tuple clean
make -C cleanup clean
make -C logging clean


test: test-function test-cb test-async-cb test-promise test-json test-class-simple \
test-class-wrapper test-class-async test-stream test-buffer test-array test-bigint \
test-class-wrapper test-class-async test-stream test-buffer test-array test-bigint test-logging\
test-cleanup

test-function:
Expand Down Expand Up @@ -65,6 +66,9 @@ test-bigint:
test-tuple:
make -C tuple test

test-logging:
make -C logging test

test-cleanup:
make -C cleanup test

Expand Down
1 change: 1 addition & 0 deletions examples/logging/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dylib
18 changes: 18 additions & 0 deletions examples/logging/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "nj-example-logging"
version = "0.1.0"
authors = ["fluvio.io"]
edition = "2018"


[lib]
crate-type = ["cdylib"]


[dependencies]
node-bindgen = { path = "../.."}
log = "0.4"
env_logger = "0.9"

[build-dependencies]
node-bindgen = { path = "../../", features = ["build"] }
10 changes: 10 additions & 0 deletions examples/logging/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
all: build

build:
nj-cli build

test: build
RUST_LOG=info node test.js

clean:
rm -rf dist
1 change: 1 addition & 0 deletions examples/logging/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
simple hello world
3 changes: 3 additions & 0 deletions examples/logging/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
node_bindgen::build::configure();
}
16 changes: 16 additions & 0 deletions examples/logging/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use node_bindgen::derive::node_bindgen;
use node_bindgen::init::node_bindgen_init_once;
use log::{info, warn};

#[node_bindgen_init_once]
fn init_logging() {
// initialize logging framework
env_logger::init();
info!("logging initialized");
}

#[node_bindgen()]
fn hello(count: i32) -> String {
warn!("calling hello");
format!("hello world {}", count)
}
7 changes: 7 additions & 0 deletions examples/logging/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
let addon = require('./dist');
const assert = require('assert');

assert.strictEqual(addon.hello(2), "hello world 2");


console.log("logging tests succeed");
7 changes: 3 additions & 4 deletions nj-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ use class::JSObjectWrapper;
pub mod sys {
pub use nj_sys::*;
}
pub mod init {
pub use ctor::ctor as node_bindgen_init_once;
}

pub mod future {
pub use fluvio_future::task::spawn;
Expand Down Expand Up @@ -120,7 +123,3 @@ macro_rules! method {
nj::core::Property::new($name).method($rs_method)
}};
}

pub fn init_logger() {
sehz marked this conversation as resolved.
Show resolved Hide resolved
fluvio_future::subscriber::init_logger();
}
1 change: 0 additions & 1 deletion nj-core/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ fn init_module() {
],
};

crate::init_logger();
unsafe {
napi_module_register(&mut _MODULE);
}
Expand Down
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ pub mod sys {
pub use nj_sys::*;
}

#[cfg(feature = "node")]
pub mod init {
pub use nj_core::init::*;
}

#[cfg(feature = "node")]
pub mod derive {
pub use nj_derive::*;
Expand Down