Skip to content

Commit

Permalink
Prepping for crates upload
Browse files Browse the repository at this point in the history
autodidaddict committed Apr 3, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 0edbc49 commit 552926a
Showing 3 changed files with 45 additions and 22 deletions.
20 changes: 17 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
[package]
name = "wascc-log"
version = "0.1.0"
name = "wascc-logging"
version = "0.6.0"
authors = ["Kevin Hoffman <[email protected]>"]
edition = "2018"
homepage = "https://wascc.dev"
repository = "https://github.com/wascc/logging-provider"
description = "Structured logging capability provider for the waSCC host runtime"
license = "Apache-2.0"
documentation = "https://docs.rs/wascc-logging"
readme = "README.md"
keywords = ["webassembly", "wasm", "wasi", "wascc", "logging"]
categories = ["wasm", "api-bindings"]

[badges]
maintenance = { status = "actively-developed" }

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

[features]
static_plugin = [] # Enable to statically compile this into a host

[dependencies]
wascc-codec = "0.5.2"
wascc-codec = "0.6.0"
log = "0.4.8"
env_logger = "0.7.1"
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
[![crates.io](https://img.shields.io/crates/v/wascc-logging.svg)](https://crates.io/crates/wascc-logging)&nbsp;
![Rust](https://github.com/wascc/logging-provider/workflows/Rust/badge.svg)&nbsp;
![license](https://img.shields.io/crates/l/wascc-logging.svg)&nbsp;
[![documentation](https://docs.rs/wascc-logging/badge.svg)](https://docs.rs/wascc-logging)

# waSCC Logging Provider
This library is a _native capability provider_ for the `wascc:logging` capability. Only actors signed with tokens containing this capability privilege will be allowed to use it. It allows actors to use normal `log` macros to write logs from within the actor.

This library is a _native capability provider_ for the `wascc:logging` capability. Only actors signed with tokens containing this capability privilege will be allowed to use it. It allows actors to use normal `log` macros (like `info!`, `warn!`, `error!`, etc, to write logs from within the actor.

It should be compiled as a native linux (`.so`) binary and made available to the **waSCC** host runtime as a plugin.

If you want to statically link (embed) this capability provider into a custom host, then enable the `static_plugin` feature in your dependencies as follows:

```
wascc-logging = { version="??", features = ["static_plugin"] }
```

33 changes: 15 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2019 Capital One Services, LLC
// Copyright 2015-2020 Capital One Services, LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
extern crate wascc_codec as codec;

use codec::capabilities::{CapabilityProvider, Dispatcher, NullDispatcher};
use codec::core::{CapabilityConfiguration, OP_CONFIGURE, OP_REMOVE_ACTOR};
use codec::core::{CapabilityConfiguration, OP_BIND_ACTOR, OP_REMOVE_ACTOR};
use codec::{
deserialize,
logging::{WriteLogRequest, OP_LOG},
@@ -28,23 +28,27 @@ extern crate log;
use std::error::Error;
use std::sync::RwLock;

#[cfg(not(feature = "static_plugin"))]
capability_provider!(LoggingProvider, LoggingProvider::new);

const CAPABILITY_ID: &str = "wascc:logging";

const ERROR: usize = 1;
const WARN: usize = 2;
const INFO: usize = 3;
const DEBUG: usize = 4;
const TRACE: usize = 5;
const ERROR: u32 = 1;
const WARN: u32 = 2;
const INFO: u32 = 3;
const DEBUG: u32 = 4;
const TRACE: u32 = 5;

pub struct LoggingProvider {
dispatcher: RwLock<Box<dyn Dispatcher>>,
}

impl Default for LoggingProvider {
fn default() -> Self {
env_logger::init();
match env_logger::try_init() {
Ok(_) => {},
Err(_) => {}
}

LoggingProvider {
dispatcher: RwLock::new(Box::new(NullDispatcher::new())),
@@ -55,15 +59,7 @@ impl Default for LoggingProvider {
impl LoggingProvider {
pub fn new() -> Self {
Self::default()
}

fn configure(
&self,
_config: impl Into<CapabilityConfiguration>,
) -> Result<Vec<u8>, Box<dyn Error>> {
trace!("configuring {}", CAPABILITY_ID);
Ok(vec![])
}
}
}

impl CapabilityProvider for LoggingProvider {
@@ -89,7 +85,7 @@ impl CapabilityProvider for LoggingProvider {
fn handle_call(&self, actor: &str, op: &str, msg: &[u8]) -> Result<Vec<u8>, Box<dyn Error>> {
// TIP: do not allow individual modules to attempt to send configuration,
// only accept it from the host runtime
if op == OP_CONFIGURE && actor == "system" {
if op == OP_BIND_ACTOR && actor == "system" {
// if there were configuration values, we'd call
// self.configure() here:
// self.configure(cfgvals).map(|_| vec![])
@@ -101,6 +97,7 @@ impl CapabilityProvider for LoggingProvider {
// tear down stuff here
Ok(vec![])
} else if op == OP_LOG {
println!("LOGG");
let log_msg = deserialize::<WriteLogRequest>(msg)?;
match log_msg.level {
ERROR => error!("[{}] {}", actor, log_msg.body),

0 comments on commit 552926a

Please sign in to comment.