Skip to content

Commit

Permalink
Merge pull request #56 from cwahbong/log-plugin-rfc
Browse files Browse the repository at this point in the history
Log plugin rfc
  • Loading branch information
cwahbong committed Jun 5, 2016
2 parents da75c1f + b787358 commit df19d96
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
78 changes: 78 additions & 0 deletions doc/rfcs/001_log.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
- Feature Name: log
- Start Date: 2016-05-07

# Summary

Log plugin collects all log messages from all plugins.

# Motivation

Println debugging is the fastest but not the best way to generate visible
informations. For example, println logging would be difficult if we are in
rustbox implemented terminal GUI. Plugins of Swiboe can run as different
processs at different machines. A centralized logger can also help us to collect
all helpful informations between different plugins.

# Detailed design

Current dummy implementation stills uses `println!`. The following features may be
added later.

- Configurable log level.
- Configurable log target: not only to console output, but also to file.

# API

Each log function represents each logging level, with the same request and
response foramt. Currently four levels are provided, listed as follows.

- `log.debug`
- `log.info`
- `log.warn`
- `log.error`

## log.{debug, info, warn, error}

Calling these functions to send log messages.

### Request

- message: The message which will be logged.
- time: The timestamp in RFC 3339 format with timezone information.

Json schema:

~~~json
{
"type": "object",
"properties": {
"message": {
"type": "string"
},
"time": {
"type": "string",
},
}
}
~~~

Example:

~~~json
{
"message": "Example message",
"time": "2016-04-15T03:03:03Z",
}
~~~

### Response

Log function always respond an empty json object.

Json schema:

~~~json
{
"type": "object",
}
~~~
2 changes: 1 addition & 1 deletion src/plugin/list_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl client::rpc::server::Rpc for ListFiles {
// NOCOM handle the result
let _ = self.client.write().unwrap().call("log.debug", &plugin::log::debug::Request {
message: String::from("list files called"),
time: String::from("now"),
time: plugin::log::current(),
});

thread::spawn(move || {
Expand Down
5 changes: 5 additions & 0 deletions src/plugin/log/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use ::client;
use ::error::Result;
use ::plugin;
use std::path;
use time;


pub struct Plugin {
Expand All @@ -26,6 +27,10 @@ impl Plugin {
}
}

pub fn current() -> String {
format!("{}", time::now_utc().rfc3339())
}

mod base;
pub mod debug;
pub mod info;
Expand Down

0 comments on commit df19d96

Please sign in to comment.