Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "slog-stdlog"
version = "4.1.0"
version = "4.2.0"
authors = ["Dawid Ciężarkiewicz <dpc@dpc.pw>"]
description = "`log` crate adapter for slog-rs"
keywords = ["slog", "logging", "json", "log"]
Expand All @@ -17,6 +17,7 @@ path = "lib.rs"
[features]
default = []
kv_unstable = ["log/kv_unstable_std", "slog/dynamic-keys"]
record_location_unstable = []

[dependencies]
slog = "2.4"
Expand Down
16 changes: 15 additions & 1 deletion lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ extern crate log;
#[cfg(feature = "kv_unstable")]
mod kv;

use slog::{b, Level, KV};
use std::{fmt, io};
use slog::{Level, KV, b};

struct Logger;

Expand All @@ -69,7 +69,21 @@ fn log_to_slog_level(level: log::Level) -> Level {
}

fn record_as_location(r: &log::Record) -> slog::RecordLocation {
// Warning: expands Record module and file names for non-static strings by leaking strings
#[cfg(feature = "record_location_unstable")]
let module = r.module_path_static().unwrap_or(match r.module_path() {
Some(s) => Box::leak(s.to_string().into_boxed_str()),
None => "unknown",
});
#[cfg(feature = "record_location_unstable")]
let file = r.file_static().unwrap_or(match r.file() {
Some(s) => Box::leak(s.to_string().into_boxed_str()),
None => "unknown",
});

#[cfg(not(feature = "record_location_unstable"))]
let module = r.module_path_static().unwrap_or("<unknown>");
#[cfg(not(feature = "record_location_unstable"))]
let file = r.file_static().unwrap_or("<unknown>");
let line = r.line().unwrap_or_default();

Expand Down