summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornatrixaeria <janng@gmx.de>2019-05-25 23:47:02 +0200
committernatrixaeria <janng@gmx.de>2019-05-25 23:47:02 +0200
commite2e4f0f698b95ca979e78ac12fa2395635321dd3 (patch)
tree960e696c9bc744946b1605e619754c2cafbff58c
parentd727f6e769ae6f3210a57f32f6c198469efaa9b8 (diff)
Add colored logging with fern
-rw-r--r--WebInterface/wasm/asm-paint/Cargo.toml20
-rw-r--r--WebInterface/wasm/asm-paint/index.html1
-rw-r--r--WebInterface/wasm/asm-paint/src/client_logger.rs34
-rw-r--r--WebInterface/wasm/asm-paint/src/lib.rs20
4 files changed, 60 insertions, 15 deletions
diff --git a/WebInterface/wasm/asm-paint/Cargo.toml b/WebInterface/wasm/asm-paint/Cargo.toml
index c0a7c68..e8f5acb 100644
--- a/WebInterface/wasm/asm-paint/Cargo.toml
+++ b/WebInterface/wasm/asm-paint/Cargo.toml
@@ -1,7 +1,10 @@
[package]
name = "asm-paint-rs"
version = "0.1.0"
-authors = ["Dennis Kobert <d-kobert@web.de>"]
+authors = [
+ "natrixaeria",
+ "Dennis Kobert <d-kobert@web.de>"
+]
edition = "2018"
[lib]
@@ -9,3 +12,18 @@ crate-type = ["cdylib"]
[dependencies]
wasm-bindgen = "0.2"
+log = "0.4"
+fern = "0.5"
+
+[dependencies.web-sys]
+version = "0.3"
+features = [
+ 'Document',
+ 'Element',
+ 'HtmlCanvasElement',
+ 'WebGlBuffer',
+ 'WebGlRenderingContext',
+ 'WebGlProgram',
+ 'WebGlShader',
+ 'Window'
+]
diff --git a/WebInterface/wasm/asm-paint/index.html b/WebInterface/wasm/asm-paint/index.html
index 46be213..631122d 100644
--- a/WebInterface/wasm/asm-paint/index.html
+++ b/WebInterface/wasm/asm-paint/index.html
@@ -6,5 +6,6 @@
<script src='loader.js' type='module'></script>
</head>
<body>
+ <canvas id='canvas'></canvas>
</body>
</html>
diff --git a/WebInterface/wasm/asm-paint/src/client_logger.rs b/WebInterface/wasm/asm-paint/src/client_logger.rs
new file mode 100644
index 0000000..a8765c6
--- /dev/null
+++ b/WebInterface/wasm/asm-paint/src/client_logger.rs
@@ -0,0 +1,34 @@
+use wasm_bindgen::prelude::*;
+
+#[wasm_bindgen]
+extern "C" {
+ #[wasm_bindgen(js_namespace=console, js_name=log)]
+ fn __console_log_colored2(f: &str, c1: &str, c2: &str);
+}
+
+fn log(rec: &log::Record) {
+ __console_log_colored2(&format!("{}", rec.args()),
+ &format!("color: {}", match rec.level() {
+ log::Level::Trace => "violet",
+ log::Level::Debug => "blue",
+ log::Level::Info => "green",
+ log::Level::Warn => "orange",
+ log::Level::Error => "red"
+ }), "");
+}
+
+pub fn init_logger() {
+ fern::Dispatch::new().format(|out, message, record|{
+ out.finish(format_args!(
+ "%c{}%c {} > {}",
+ record.level(),
+ record.target(),
+ message
+ )
+ )
+ })
+ .level(log::LevelFilter::Debug)
+ .chain(fern::Output::call(log))
+ .apply().unwrap();
+}
+
diff --git a/WebInterface/wasm/asm-paint/src/lib.rs b/WebInterface/wasm/asm-paint/src/lib.rs
index b6a5840..fea9d0f 100644
--- a/WebInterface/wasm/asm-paint/src/lib.rs
+++ b/WebInterface/wasm/asm-paint/src/lib.rs
@@ -1,21 +1,13 @@
-use wasm_bindgen::prelude::*;
-
-macro_rules! console_log {
- ($($t:tt)*) => (log(&format_args!($($t)*).to_string()))
-}
+mod client_logger;
-#[wasm_bindgen]
-extern "C" {
- #[wasm_bindgen(js_namespace = console)]
- fn log(s: &str);
+use wasm_bindgen::prelude::*;
- #[wasm_bindgen(js_namespace = document)]
- fn write(s: &str);
-}
+#[macro_use]
+extern crate log;
#[wasm_bindgen(start)]
pub fn entry() {
- console_log!("hello {} wasm", 44);
+ client_logger::init_logger();
- write("gooo");
+ info!("{}", 42);
}