Skip to content

Commit

Permalink
Merge pull request #9 from lunatic-solutions/lunatic-0-13
Browse files Browse the repository at this point in the history
Update to lunatic 0.13
  • Loading branch information
bkolobara authored May 5, 2023
2 parents 6fe1945 + 886c0fc commit 20b4e5d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ readme = "Readme.md"

[dependencies]
chrono = "0.4"
lunatic = "0.12"
lunatic = "0.13"
serde = { version = "1.0", features = ["derive"] }
yansi = "0.5.1"

Expand Down
10 changes: 7 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub mod subscriber;

use std::cell::RefCell;

use lunatic::ProcessName;
use lunatic::{process_local, spawn_link, Process};
use serde::{Deserialize, Serialize};
use subscriber::Subscriber;
Expand All @@ -36,6 +37,9 @@ process_local! {
static LOGGING_PROCESS: RefCell<LoggingProcess> = RefCell::new(LoggingProcess::NotLookedUp);
}

#[derive(ProcessName)]
struct LoggingProcessID;

enum LoggingProcess {
NotLookedUp,
NotPresent,
Expand All @@ -46,12 +50,12 @@ enum LoggingProcess {
///
/// The subscriber is spawned in a [`lunatic::Process`] and receives log events.
pub fn init(subscriber: impl Subscriber) -> Process<Event> {
if Process::<Event>::lookup("lunatic::logger").is_some() {
if Process::<Event>::lookup(&LoggingProcessID).is_some() {
panic!("logger already initialized");
}

let process = spawn_subscriber(subscriber);
process.register("lunatic::logger");
process.register(&LoggingProcessID);
LOGGING_PROCESS.with_borrow_mut(|mut proc| *proc = LoggingProcess::Present(process.clone()));
process
}
Expand Down Expand Up @@ -100,7 +104,7 @@ pub fn __lookup_logging_process() -> Option<Process<Event>> {
match &*proc_ref {
LoggingProcess::NotLookedUp => {
std::mem::drop(proc_ref);
match Process::<Event>::lookup("lunatic::logger") {
match Process::<Event>::lookup(&LoggingProcessID) {
Some(process) => {
*proc.borrow_mut() = LoggingProcess::Present(process.clone());
Some(process)
Expand Down
1 change: 0 additions & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
macro_rules! log {
// log!(target: "my_target", Level::Info; "a {} event", "log");
(target: $target:expr, $lvl:expr, $($arg:tt)+) => ({
use lunatic::process::Message;
if let Some(proc) = $crate::__lookup_logging_process() {
let metadata = $crate::Metadata::new(
concat!(
Expand Down

0 comments on commit 20b4e5d

Please sign in to comment.