blob: ebb34f15520fcda6c952cce1175b2b1eb9f3afd8 [file] [log] [blame]
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
use std::ffi::c_char;
use std::ffi::CString;
pub struct HsLogger {
pub callback: extern "C" fn(u32, *const c_char),
}
impl log::Log for HsLogger {
fn enabled(&self, _: &log::Metadata) -> bool {
true
}
fn log(&self, record: &log::Record) {
let msg = format!("{}", record.args());
let c_str_msg = CString::new(msg).unwrap();
let c_level = match record.level() {
log::Level::Debug => 0,
log::Level::Info => 1,
log::Level::Warn => 2,
log::Level::Error => 3,
_ => 0,
};
(self.callback)(c_level, c_str_msg.as_ptr());
}
fn flush(&self) {}
}