~zethra/stargazer

0976fac2bf22fd51bb7886e5e953841362336770 — Ben Aaron Goldberg 2 months ago fbbf828
logger: log date+time
3 files changed, 8 insertions(+), 5 deletions(-)

M Cargo.lock
M Cargo.toml
M src/logger.rs
M Cargo.lock => Cargo.lock +2 -0
@@ 255,8 255,10 @@ version = "0.4.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
dependencies = [
 "libc",
 "num-integer",
 "num-traits",
 "winapi",
]

[[package]]

M Cargo.toml => Cargo.toml +1 -0
@@ 64,6 64,7 @@ net2 = "0.2"
[dependencies.chrono]
version = "0.4"
default-features = false
features = ["std", "clock"]

[dependencies.async-rustls]
version = "0.2"

M src/logger.rs => src/logger.rs +5 -5
@@ 14,6 14,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.

use chrono::prelude::*;
use colored::Colorize;
use crossbeam_channel::{self as chan, Sender};
use log::{Level, LevelFilter, Log, Metadata, Record, SetLoggerError};


@@ 34,8 35,7 @@ pub struct Logger {

pub fn init(log_level: LevelFilter) -> Result<(), SetLoggerError> {
    let (_shutdown, s): (Sender<()>, _) = chan::bounded(0);
    let (message_queue, m): (Sender<Option<(String, Channel)>>, _) =
        chan::unbounded();
    let (message_queue, m): (Sender<Option<(String, Channel)>>, _) = chan::unbounded();

    thread::Builder::new()
        .name("stargazer-logger".into())


@@ 72,8 72,7 @@ pub fn init(log_level: LevelFilter) -> Result<(), SetLoggerError> {
        _shutdown,
        message_queue,
    };
    log::set_boxed_logger(Box::new(logger))
        .map(|()| log::set_max_level(log_level))
    log::set_boxed_logger(Box::new(logger)).map(|()| log::set_max_level(log_level))
}

impl Log for Logger {


@@ 92,7 91,8 @@ impl Log for Logger {
                Level::Info => Channel::StdOut,
                _ => Channel::StdErr,
            };
            let msg = format!("{} - {}", level, record.args());
            let now: DateTime<Local> = Local::now();
            let msg = format!("{} {} - {}", now.to_rfc3339(), level, record.args());
            self.message_queue
                .send(Some((msg, channel)))
                .expect("Logger thread isn't running");