Merge pull request #85 from sdww0/log

Support for log crate
This commit is contained in:
Tate, Hongliang Tian 2023-02-23 20:55:30 +08:00 committed by GitHub
commit af4a0caa26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 65 additions and 159 deletions

View File

@ -19,6 +19,7 @@ pod = {path = "../pod"}
pod-derive = {path = "../pod-derive"}
acpi= "4.1.1"
intrusive-collections = "0.9.5"
log= "0.4"
[dependencies.lazy_static]
version = "1.0"

View File

@ -1,6 +1,6 @@
#![allow(unused)]
use crate::log::LogLevel;
use log::Level;
pub const USER_STACK_SIZE: usize = PAGE_SIZE * 4;
pub const KERNEL_STACK_SIZE: usize = PAGE_SIZE * 64;
@ -15,6 +15,6 @@ pub const PAGE_SIZE_BITS: usize = 0xc;
pub const KVA_START: usize = (usize::MAX) << PAGE_SIZE_BITS;
pub const DEFAULT_LOG_LEVEL: LogLevel = LogLevel::Error;
pub const DEFAULT_LOG_LEVEL: Level = Level::Error;
/// This value represent the base timer frequency in Hz
pub const TIMER_FREQ: u64 = 100;

View File

@ -4,9 +4,9 @@ use core::arch::x86_64::{_fxrstor, _fxsave};
use core::fmt::Debug;
use core::mem::MaybeUninit;
use crate::debug;
use crate::trap::{CalleeRegs, CallerRegs, SyscallFrame, TrapFrame};
use crate::x86_64_util::rdfsbase;
use log::debug;
use pod::Pod;
/// Defines a CPU-local variable.

View File

@ -1,8 +1,9 @@
use alloc::{sync::Arc, vec::Vec};
use lazy_static::lazy_static;
use log::debug;
use spin::Mutex;
use crate::{cell::Cell, debug, driver::pic, x86_64_util::*, IrqAllocateHandle, TrapFrame};
use crate::{cell::Cell, driver::pic, x86_64_util::*, IrqAllocateHandle, TrapFrame};
use core::fmt::{self, Write};
bitflags::bitflags! {

View File

@ -1,8 +1,9 @@
use core::ptr::NonNull;
use crate::{info, mm::address::phys_to_virt};
use crate::mm::address::phys_to_virt;
use acpi::{AcpiHandler, AcpiTables};
use lazy_static::lazy_static;
use log::info;
use spin::Mutex;
lazy_static! {

View File

@ -1,5 +1,6 @@
use crate::{cell::Cell, debug, x86_64_util};
use crate::{cell::Cell, x86_64_util};
use lazy_static::lazy_static;
use log::debug;
use volatile::{
access::{ReadOnly, ReadWrite, WriteOnly},
Volatile,

View File

@ -1,8 +1,8 @@
use acpi::PlatformInfo;
use log::debug;
use super::acpi::ACPI_TABLES;
use crate::cell::Cell;
use crate::debug;
use crate::mm::address::phys_to_virt;
use crate::util::recycle_allocator::RecycleAllocator;
use lazy_static::lazy_static;

View File

@ -10,11 +10,10 @@ pub mod rtc;
pub mod timer;
pub use apic::ack;
use log::info;
pub use timer::TimerCallback;
pub(crate) use timer::{add_timeout_list, TICK};
use crate::info;
pub(crate) fn init(rsdp: Option<u64>) {
acpi::init(rsdp.unwrap());
timer::init();

View File

@ -1,4 +1,4 @@
use crate::{info, trap::allocate_target_irq, x86_64_util::out8, IrqAllocateHandle};
use crate::{trap::allocate_target_irq, x86_64_util::out8, IrqAllocateHandle};
use core::sync::atomic::Ordering::Relaxed;
use core::sync::atomic::{AtomicBool, AtomicU8};
@ -12,6 +12,7 @@ const TIMER_IRQ_NUM: u8 = 32;
use alloc::vec::Vec;
use lazy_static::lazy_static;
use log::info;
use spin::Mutex;
lazy_static! {

View File

@ -1,7 +1,9 @@
use log::info;
use crate::{
config,
driver::{apic::APIC_INSTANCE, pic, timer},
info, x86_64_util, TrapFrame,
x86_64_util, TrapFrame,
};
pub fn init() {

View File

@ -18,7 +18,7 @@ pub mod cpu;
pub mod device;
mod driver;
mod error;
pub mod log;
pub mod logger;
pub(crate) mod mm;
pub mod prelude;
pub mod sync;
@ -56,8 +56,7 @@ pub use x86_64::registers::rflags::RFlags;
use x86_64_util::enable_common_cpu_features;
static mut IRQ_CALLBACK_LIST: Vec<IrqCallbackHandle> = Vec::new();
// TODO: serial中断
// 讨论syscall的中断启用
#[cfg(not(feature = "serial_print"))]
pub use crate::screen_print as print;
#[cfg(not(feature = "serial_print"))]
@ -69,6 +68,7 @@ pub use crate::console_print as print;
pub use crate::console_println as println;
pub fn init(boot_info: &'static mut BootInfo) {
logger::init();
let siz = boot_info.framebuffer.as_ref().unwrap() as *const FrameBuffer as usize;
let mut memory_init = false;
// memory

View File

@ -1,134 +0,0 @@
use core::fmt::Arguments;
use crate::config::DEFAULT_LOG_LEVEL;
/// Print log message
/// This function should *NOT* be directly called.
/// Instead, print logs with macros.
#[cfg(not(feature = "serial_print"))]
#[doc(hidden)]
pub fn log_print(args: Arguments) {
use crate::device::framebuffer::WRITER;
use core::fmt::Write;
use x86_64::instructions::interrupts;
interrupts::without_interrupts(|| {
WRITER.lock().as_mut().unwrap().write_fmt(args).unwrap();
});
}
/// Print log message
/// This function should *NOT* be directly called.
/// Instead, print logs with macros.
#[cfg(feature = "serial_print")]
#[doc(hidden)]
pub fn log_print(args: Arguments) {
crate::device::serial::print(args);
}
/// This macro should not be directly called.
#[macro_export]
macro_rules! log_print {
($($arg:tt)*) => {
$crate::log::log_print(format_args!($($arg)*))
};
}
#[macro_export]
macro_rules! trace {
($($arg:tt)*) => {
if $crate::log::Logger::trace() {
$crate::log_print!("[trace]:");
$crate::log_print!($($arg)*);
$crate::log_print!("\n");
}
};
}
#[macro_export]
macro_rules! debug {
($($arg:tt)*) => {
if $crate::log::Logger::debug() {
$crate::log_print!("[debug]:");
$crate::log_print!($($arg)*);
$crate::log_print!("\n");
}
};
}
#[macro_export]
macro_rules! info {
($($arg:tt)*) => {
if $crate::log::Logger::info() {
($crate::log_print!("[info]:"));
($crate::log_print!($($arg)*));
($crate::log_print!("\n"));
}
};
}
#[macro_export]
macro_rules! warn {
($($arg:tt)*) => {
if $crate::log::Logger::warn() {
$crate::log_print!("[warn]:");
$crate::log_print!($($arg)*);
$crate::log_print!("\n");
}
};
}
#[macro_export]
macro_rules! error {
($($arg:tt)*) => {
if $crate::log::Logger::error() {
$crate::log_print!("[error]:");
$crate::log_print!($($arg)*);
$crate::log_print!("\n");
}
};
}
pub const LOGGER: Logger = Logger::default_log_level();
pub struct Logger {
log_level: LogLevel,
}
impl Logger {
pub const fn default_log_level() -> Logger {
Logger {
log_level: DEFAULT_LOG_LEVEL,
}
}
pub fn trace() -> bool {
LOGGER.log_level <= LogLevel::Trace
}
pub fn debug() -> bool {
LOGGER.log_level <= LogLevel::Debug
}
pub fn info() -> bool {
LOGGER.log_level <= LogLevel::Info
}
pub fn warn() -> bool {
LOGGER.log_level <= LogLevel::Warn
}
pub fn error() -> bool {
LOGGER.log_level <= LogLevel::Error
}
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
pub enum LogLevel {
Trace,
Debug,
Info,
Warn,
Error,
Close,
}

View File

@ -0,0 +1,27 @@
use crate::{config::DEFAULT_LOG_LEVEL, println};
use log::{Metadata, Record};
const LOGGER: Logger = Logger {};
struct Logger {}
impl log::Log for Logger {
fn enabled(&self, metadata: &Metadata) -> bool {
metadata.level() <= DEFAULT_LOG_LEVEL
}
fn log(&self, record: &Record) {
if self.enabled(record.metadata()) {
println!("[{}]: {}", record.level(), record.args());
}
}
fn flush(&self) {}
}
pub(crate) fn init() {
log::set_logger(&LOGGER)
.map(|()| log::set_max_level(DEFAULT_LOG_LEVEL.to_level_filter()))
.unwrap();
}

View File

@ -4,6 +4,7 @@ use crate::{
vm::VmFrame,
*,
};
use ::log::info;
use alloc::{collections::BTreeMap, vec, vec::Vec};
use core::{fmt, panic};
use lazy_static::lazy_static;

View File

@ -7,6 +7,5 @@ pub(crate) use alloc::sync::Arc;
pub(crate) use alloc::vec::Vec;
pub(crate) use core::any::Any;
pub use crate::debug;
pub(crate) use crate::util::AlignExt;
pub use crate::vm::{Paddr, Vaddr};

View File

@ -11,4 +11,4 @@ pub use self::scheduler::{set_scheduler, Scheduler};
pub(crate) use self::task::context_switch;
pub(crate) use self::task::TaskContext;
pub(crate) use self::task::SWITCH_TO_USER_SPACE_TASK;
pub use self::task::{Task, TaskStatus, TaskAdapter};
pub use self::task::{Task, TaskAdapter, TaskStatus};

View File

@ -1,7 +1,7 @@
//! User space.
use crate::debug;
use crate::x86_64_util::{rdfsbase, wrfsbase};
use log::debug;
use x86_64::registers::rflags::RFlags;
use crate::cpu::CpuContext;

View File

@ -12,6 +12,7 @@ jinux-frame = {path = "../../../framework/jinux-frame"}
jinux-util = {path="../../libs/jinux-util"}
pod = {path = "../../../framework/pod"}
pod-derive = {path = "../../../framework/pod-derive"}
log= "0.4"
[dependencies.lazy_static]
version = "1.0"

View File

@ -6,11 +6,11 @@ pub mod capability;
pub mod msix;
pub mod util;
extern crate alloc;
use jinux_frame::info;
extern crate pod_derive;
use alloc::{sync::Arc, vec::Vec};
use lazy_static::lazy_static;
use log::info;
use spin::mutex::Mutex;
use util::CSpaceAccessMethod;

View File

@ -1,11 +1,12 @@
use alloc::vec::Vec;
use log::debug;
use pod_derive::Pod;
use crate::util::{CSpaceAccessMethod, Location, BAR};
use super::capability::msix::CapabilityMSIXData;
use jinux_frame::{debug, offset_of, IrqAllocateHandle};
use jinux_frame::{offset_of, IrqAllocateHandle};
use jinux_util::frame_ptr::InFramePtr;
#[derive(Debug, Default)]

View File

@ -13,6 +13,7 @@ jinux-pci = {path="../jinux-pci"}
jinux-util = {path="../../libs/jinux-util"}
pod = {path = "../../../framework/pod"}
pod-derive = {path = "../../../framework/pod-derive"}
log= "0.4"
[features]

View File

@ -8,9 +8,10 @@ extern crate alloc;
use alloc::{sync::Arc, vec::Vec};
use bitflags::bitflags;
use device::VirtioDevice;
use jinux_frame::{debug, info, offset_of, TrapFrame};
use jinux_frame::{offset_of, TrapFrame};
use jinux_pci::util::{PCIDevice, BAR};
use jinux_util::frame_ptr::InFramePtr;
use log::{debug, info};
use pod_derive::Pod;
use crate::device::VirtioInfo;

View File

@ -30,6 +30,7 @@ ringbuffer = "0.10.0"
spin = "0.9.4"
vte = "0.10"
lru = "0.9.0"
log= "0.4"
[dependencies.lazy_static]
version = "1.0"

View File

@ -1,5 +1,6 @@
use log::info;
pub mod virtio;
use jinux_frame::info;
pub fn init() {
jinux_pci::init();

View File

@ -1,6 +1,5 @@
use crate::process::Process;
use alloc::sync::Arc;
use jinux_frame::info;
use jinux_pci::msix::MSIX;
use jinux_pci::PCIDevice;
use jinux_util::frame_ptr::InFramePtr;
@ -9,6 +8,7 @@ use jinux_virtio::device::block::BlkResp;
use jinux_virtio::PCIVirtioDevice;
use jinux_virtio::VitrioPciCommonCfg;
use lazy_static::lazy_static;
use log::info;
use spin::mutex::Mutex;
use super::BlockDevice;

View File

@ -3,7 +3,7 @@ use core::sync::atomic::AtomicBool;
use alloc::collections::BTreeMap;
use alloc::{string::String, sync::Arc, vec::Vec};
use jinux_frame::{debug, info, offset_of, TrapFrame};
use jinux_frame::{offset_of, TrapFrame};
use jinux_pci::{msix::MSIX, PCIDevice};
use jinux_util::frame_ptr::InFramePtr;
use jinux_virtio::device::input::device::InputProp;
@ -13,6 +13,7 @@ use jinux_virtio::{
PCIVirtioDevice,
};
use lazy_static::lazy_static;
use log::{debug, info};
use spin::Mutex;
use virtio_input_decoder::{DecodeType, Decoder};

View File

@ -14,7 +14,8 @@ pub(crate) use bitflags::bitflags;
pub(crate) use core::ffi::CStr;
pub(crate) use jinux_frame::config::PAGE_SIZE;
pub(crate) use jinux_frame::vm::Vaddr;
pub(crate) use jinux_frame::{debug, error, info, print, println, trace, warn};
pub(crate) use jinux_frame::{print, println};
pub(crate) use log::{debug, error, info, trace, warn};
pub(crate) use spin::{Mutex, RwLock};
/// return current process

View File

@ -1,7 +1,6 @@
use super::{c_types::sigaction_t, constants::*, sig_mask::SigMask, sig_num::SigNum};
use crate::prelude::*;
use bitflags::bitflags;
use jinux_frame::warn;
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum SigAction {