1
1
mirror of https://github.com/wez/wezterm.git synced 2024-09-20 11:17:15 +03:00

adopt log and env_logger for logging

This commit is contained in:
Wez Furlong 2019-06-08 15:17:41 -07:00
parent 000c5eddac
commit 34d6d95b6f
22 changed files with 59 additions and 41 deletions

View File

@ -17,6 +17,7 @@ bitflags = "1.0"
clipboard = "0.5"
dirs = "1.0"
euclid = "0.19"
env_logger = "0.6"
failure = "0.1"
failure_derive = "0.1"
foreign-types = "0.3"
@ -27,6 +28,7 @@ harfbuzz = { path = "deps/harfbuzz" }
lazy_static = "1.3"
leb128 = "0.2"
libc = "0.2"
log = "0.4"
open = "1.2"
palette = "0.4"
portable-pty = { path = "pty", features = ["serde_support"]}

View File

@ -15,6 +15,7 @@ use core_text::font_descriptor::{
kCTFontDefaultOrientation, SymbolicTraitAccessors, TraitAccessors,
};
use failure::{format_err, Error};
use log::debug;
use std::ptr;
#[allow(non_upper_case_globals)]
@ -246,7 +247,7 @@ impl Font for CoreTextFontImpl {
// freetype renderer.
let bearing_x = rect.origin.x - AA_PADDING;
let bearing_y = height as f64 + AA_PADDING + rect.origin.y;
eprintln!(
debug!(
"rasterize_glyph {:?} -> {}x{} bearing_x={} bearing_y={}",
rect, width, height, bearing_x, bearing_y
);

View File

@ -6,6 +6,7 @@ use crate::font::ftfont::FreeTypeFontImpl;
use crate::font::{fcwrap, ftwrap};
use crate::font::{shape_with_harfbuzz, FallbackIdx, Font, FontSystem, GlyphInfo, NamedFont};
use failure::{bail, ensure, err_msg, Error};
use log::error;
pub type FontSystemImpl = FontConfigAndFreeType;
@ -28,7 +29,7 @@ impl FontSystem for FontConfigAndFreeType {
let mut pattern = if !fonts.is_empty() {
let mut pattern = FontPattern::new()?;
if fonts.len() > 1 {
eprintln!(
error!(
"FIXME: fontconfig loader currently only processes
the first in your set of fonts for {:?}",
style
@ -88,7 +89,7 @@ impl NamedFontImpl {
// care to abort the rest of what we're doing
match lib.set_lcd_filter(ftwrap::FT_LcdFilter::FT_LCD_FILTER_DEFAULT) {
Ok(_) => (),
Err(err) => eprintln!("Ignoring: FT_LcdFilter failed: {:?}", err),
Err(err) => error!("Ignoring: FT_LcdFilter failed: {:?}", err),
};
// Enable some filtering options and pull in the standard

View File

@ -6,6 +6,7 @@ use crate::font::{
ftwrap, shape_with_harfbuzz, FallbackIdx, Font, FontSystem, GlyphInfo, NamedFont,
};
use failure::{format_err, Error};
use log::{debug, error};
struct NamedFontImpl {
_lib: ftwrap::Library,
@ -41,13 +42,13 @@ impl FontSystem for FontLoaderAndFreeType {
// care to abort the rest of what we're doing
match lib.set_lcd_filter(ftwrap::FT_LcdFilter::FT_LCD_FILTER_DEFAULT) {
Ok(_) => (),
Err(err) => eprintln!("Ignoring: FT_LcdFilter failed: {:?}", err),
Err(err) => error!("Ignoring: FT_LcdFilter failed: {:?}", err),
};
let mut fonts = Vec::new();
let mut fontdata = Vec::new();
for (data, idx) in fontloader::load_system_fonts(config, style)? {
eprintln!("want idx {} in bytes of len {}", idx, data.len());
debug!("want idx {} in bytes of len {}", idx, data.len());
let face = lib.new_face_from_slice(&data, idx.into())?;
fontdata.push(data);

View File

@ -2,6 +2,7 @@
use super::hbwrap as harfbuzz;
use crate::font::{ftwrap, Font, FontMetrics, RasterizedGlyph};
use failure::{bail, Error};
use log::debug;
use std::cell::RefCell;
use std::mem;
use std::slice;

View File

@ -1,4 +1,5 @@
use failure::{bail, format_err, Error};
use log::{debug, error};
use serde_derive::*;
mod ftfont;
mod hbwrap;
@ -319,7 +320,7 @@ pub fn shape_with_harfbuzz(
let mut shape = match shape_with_harfbuzz(font, font_idx + 1, substr) {
Ok(shape) => Ok(shape),
Err(e) => {
eprintln!("{:?} for {:?}", e, substr);
error!("{:?} for {:?}", e, substr);
if font_idx == 0 && s == "?" {
bail!("unable to find any usable glyphs for `?` in font_idx 0");
}
@ -361,7 +362,7 @@ pub fn shape_with_harfbuzz(
let mut shape = match shape_with_harfbuzz(font, font_idx + 1, substr) {
Ok(shape) => Ok(shape),
Err(e) => {
eprintln!("{:?} for {:?}", e, substr);
error!("{:?} for {:?}", e, substr);
if font_idx == 0 && s == "?" {
bail!("unable to find any usable glyphs for `?` in font_idx 0");
}

View File

@ -9,6 +9,7 @@ use failure::{bail, Error};
use glium;
use glium::glutin::EventsLoopProxy;
use glium::glutin::WindowId;
use log::{debug, error};
use promise::{Executor, Future, SpawnFunc};
use std::cell::RefCell;
use std::collections::HashMap;
@ -368,7 +369,7 @@ impl GuiEventLoop {
}
Ok(Break) => Break,
Err(err) => {
eprintln!("Error in event loop: {:?}", err);
error!("Error in event loop: {:?}", err);
Break
}
}

View File

@ -13,6 +13,7 @@ use failure::{format_err, Error};
use glium;
use glium::glutin::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize};
use glium::glutin::{self, ElementState, MouseCursor};
use log::{debug, error};
use std::rc::Rc;
use std::sync::Arc;
use term;
@ -175,7 +176,7 @@ impl TerminalWindow for GliumTerminalWindow {
.ok_or_else(|| format_err!("failed to get inner window size"))?;
let dpi_scale = self.host.display.gl_window().get_hidpi_factor();
let (width, height): (u32, u32) = size.to_physical(dpi_scale).into();
eprintln!(
debug!(
"resize {}x{}@{} -> {}x{}@{}",
self.width, self.height, old_dpi_scale, width, height, dpi_scale
);
@ -207,7 +208,7 @@ impl GliumTerminalWindow {
let height = cell_height * physical_rows;
let logical_size = LogicalSize::new(width as f64, height as f64);
eprintln!("make window with {}x{}", width, height);
debug!("make window with {}x{}", width, height);
let display = {
let pref_context = glutin::ContextBuilder::new()
@ -645,7 +646,7 @@ impl GliumTerminalWindow {
ElementState::Released => {}
}
} else {
eprintln!("event {:?} with no mapping", event);
error!("event {:?} with no mapping", event);
}
self.paint_if_needed()?;
Ok(())
@ -685,7 +686,7 @@ impl GliumTerminalWindow {
} => {
// Coupled with logic in key_event which gates whether
// we allow processing unicode chars here
// eprintln!("ReceivedCharacter {} {:?}", c as u32, c);
// debug!("ReceivedCharacter {} {:?}", c as u32, c);
if self.allow_received_character {
self.allow_received_character = false;
let mux = Mux::get().unwrap();

View File

@ -6,6 +6,7 @@ use crate::mux::Mux;
use clipboard::{ClipboardContext, ClipboardProvider};
use failure::Fallible;
use failure::{format_err, Error};
use log::error;
use portable_pty::PtySize;
use promise::Future;
use std::collections::HashMap;
@ -358,7 +359,7 @@ impl<'a, H: HostHelper> term::TerminalHost for TabHost<'a, H> {
fn click_link(&mut self, link: &Arc<Hyperlink>) {
match open::that(link.uri()) {
Ok(_) => {}
Err(err) => eprintln!("failed to open {}: {:?}", link.uri(), err),
Err(err) => error!("failed to open {}: {:?}", link.uri(), err),
}
}

View File

@ -7,6 +7,7 @@ use crate::opengl::render::Renderer;
use crate::opengl::textureatlas::OutOfTextureSpace;
use failure::{ensure, format_err, Error};
use glium;
use log::{debug, error};
use portable_pty::PtySize;
use std::rc::Rc;
use std::sync::Arc;
@ -145,7 +146,7 @@ pub trait TerminalWindow {
match res {
Err(err) => {
if let Some(&OutOfTextureSpace { size }) = err.downcast_ref::<OutOfTextureSpace>() {
eprintln!("out of texture space, allocating {}", size);
error!("out of texture space, allocating {}", size);
self.recreate_texture_atlas(size)?;
tab.renderer().make_all_lines_dirty();
// Recursively initiate a new paint
@ -225,7 +226,7 @@ pub trait TerminalWindow {
let fonts = self.fonts();
let dpi_scale = dpi_scale.unwrap_or_else(|| fonts.get_dpi_scale());
let font_scale = font_scale.unwrap_or_else(|| fonts.get_font_scale());
eprintln!(
debug!(
"TerminalWindow::scaling_changed dpi_scale={} font_scale={}",
dpi_scale, font_scale
);

View File

@ -6,6 +6,7 @@ use crate::mux::tab::Tab;
use crate::mux::Mux;
use crate::server::listener::spawn_listener;
use failure::{bail, Error};
use log::info;
use promise::Executor;
use promise::SpawnFunc;
use std::rc::Rc;
@ -68,7 +69,7 @@ impl FrontEnd for MuxServerFrontEnd {
}
if Mux::get().unwrap().is_empty() {
eprintln!("No more tabs; all done!");
info!("No more tabs; all done!");
return Ok(());
}
}

View File

@ -1,3 +1,4 @@
use log::debug;
use term::{KeyCode, KeyModifiers};
mod keyboard;
use egli;
@ -124,7 +125,7 @@ impl Connection {
let egl_display = egli::Display::from_display_id(display as *mut _).map_err(egli_err)?;
let egl_version = egl_display.initialize_and_get_version().map_err(egli_err)?;
println!("Using EGL {}", egl_version);
debug!("Using EGL {}", egl_version);
let configs = egl_display
.config_filter()

View File

@ -7,6 +7,7 @@ use crate::frontend::FrontEnd;
use crate::mux::tab::Tab;
use crate::mux::Mux;
use failure::{bail, Error};
use log::debug;
use mio::{Events, Poll, PollOpt, Ready, Token};
use mio_extras::channel::{channel, Receiver as GuiReceiver, Sender as GuiSender};
use portable_pty::PtySize;
@ -234,7 +235,7 @@ impl GuiEventLoop {
}
fn schedule_window_close(&self, window_id: WindowId) -> Result<(), Error> {
eprintln!("schedule_window_close {:?}", window_id);
debug!("schedule_window_close {:?}", window_id);
let mut windows = self.windows.borrow_mut();
windows.by_id.remove(&window_id);

View File

@ -10,6 +10,7 @@ use crate::mux::window::WindowId;
use crate::mux::{Mux, SessionTerminated};
use crate::opengl::render::Renderer;
use failure::Error;
use log::{debug, error};
use std::rc::Rc;
use std::sync::Arc;
use term::{self, KeyCode, KeyModifiers, MouseButton, MouseEvent, MouseEventKind};
@ -239,7 +240,7 @@ impl X11TerminalWindow {
4 => MouseButton::WheelUp,
5 => MouseButton::WheelDown,
_ => {
eprintln!("button {} is not implemented", button_press.detail());
error!("button {} is not implemented", button_press.detail());
return Ok(());
}
},
@ -250,7 +251,7 @@ impl X11TerminalWindow {
}
xcb::CLIENT_MESSAGE => {
let msg: &xcb::ClientMessageEvent = unsafe { xcb::cast_event(event) };
println!("CLIENT_MESSAGE {:?}", msg.data().data32());
debug!("CLIENT_MESSAGE {:?}", msg.data().data32());
if msg.data().data32()[0] == self.conn.atom_delete() {
return Err(SessionTerminated::WindowClosed.into());
}

View File

@ -1,3 +0,0 @@
macro_rules! debug {
($($arg:tt)*) => (if cfg!(debug_assertions) { println!($($arg)*) })
}

View File

@ -1,9 +1,8 @@
// Don't create a new standard console window when launched from the windows GUI.
#![windows_subsystem = "windows"]
#[macro_use]
pub mod log;
use failure::Error;
use log::{error, info};
use std::ffi::OsString;
use structopt::StructOpt;
@ -139,6 +138,7 @@ fn run_terminal_gui(config: Arc<config::Config>, opts: &StartCommand) -> Result<
}
fn main() -> Result<(), Error> {
env_logger::init();
// This is a bit gross.
// In order to not to automatically open a standard windows console when
// we run, we use the windows_subsystem attribute at the top of this
@ -169,21 +169,21 @@ fn main() -> Result<(), Error> {
.unwrap_or_else(|| SubCommand::Start(StartCommand::default()))
{
SubCommand::Start(start) => {
println!("Using configuration: {:#?}\nopts: {:#?}", config, opts);
error!("Using configuration: {:#?}\nopts: {:#?}", config, opts);
run_terminal_gui(config, &start)
}
SubCommand::Cli(_) => {
use crate::server::client::Client;
use crate::server::codec::*;
let mut client = Client::new(&config)?;
eprintln!("ping: {:?}", client.ping()?);
info!("ping: {:?}", client.ping()?);
let tabs = client.list_tabs()?;
for (tab_id, title) in tabs.tabs.iter() {
eprintln!("tab {}: {}", tab_id, title);
info!("tab {}: {}", tab_id, title);
let _data = client.get_coarse_tab_renderable_data(GetCoarseTabRenderableData {
tab_id: *tab_id,
})?;
// eprintln!("coarse: {:?}", data);
// info!("coarse: {:?}", data);
}
Ok(())
}

View File

@ -10,6 +10,7 @@ use crate::frontend::guicommon::localtab::LocalTab;
use crate::mux::tab::Tab;
use crate::mux::Mux;
use failure::Error;
use log::info;
use portable_pty::cmdbuilder::CommandBuilder;
use portable_pty::{PtySize, PtySystem};
use std::rc::Rc;
@ -41,7 +42,7 @@ impl Domain for LocalDomain {
};
let (master, slave) = self.pty_system.openpty(size)?;
let child = slave.spawn_command(cmd)?;
eprintln!("spawned: {:?}", child);
info!("spawned: {:?}", child);
let terminal = term::Terminal::new(
size.rows as usize,

View File

@ -2,6 +2,7 @@ use crate::config::Config;
use crate::frontend::gui_executor;
use failure::Error;
use failure_derive::*;
use log::{debug, error, warn};
use portable_pty::ExitStatus;
use promise::{Executor, Future};
use std::cell::{Ref, RefCell, RefMut};
@ -36,11 +37,11 @@ fn read_from_tab_pty(tab_id: TabId, mut reader: Box<std::io::Read>) {
loop {
match reader.read(&mut buf) {
Ok(size) if size == 0 => {
eprintln!("read_pty EOF: tab_id {}", tab_id);
error!("read_pty EOF: tab_id {}", tab_id);
break;
}
Err(err) => {
eprintln!("read_pty failed: tab {} {:?}", tab_id, err);
error!("read_pty failed: tab {} {:?}", tab_id, err);
break;
}
Ok(size) => {
@ -83,12 +84,12 @@ impl<'a> TerminalHost for Host<'a> {
fn click_link(&mut self, link: &Arc<Hyperlink>) {
match open::that(link.uri()) {
Ok(_) => {}
Err(err) => eprintln!("failed to open {}: {:?}", link.uri(), err),
Err(err) => error!("failed to open {}: {:?}", link.uri(), err),
}
}
fn get_clipboard(&mut self) -> Result<String, Error> {
eprintln!("peer requested clipboard; ignoring");
warn!("peer requested clipboard; ignoring");
Ok("".into())
}
@ -152,7 +153,7 @@ impl Mux {
}
pub fn remove_tab(&self, tab_id: TabId) {
eprintln!("removing tab {}", tab_id);
debug!("removing tab {}", tab_id);
self.tabs.borrow_mut().remove(&tab_id);
}

View File

@ -10,6 +10,7 @@ use glium::backend::Facade;
use glium::texture::SrgbTexture2d;
use glium::{self, IndexBuffer, Surface, VertexBuffer};
use glium::{implement_vertex, uniform};
use log::debug;
use std::cell::RefCell;
use std::collections::HashMap;
use std::mem;

View File

@ -2,6 +2,7 @@ use crate::config::Config;
use crate::server::codec::*;
use crate::server::UnixStream;
use failure::{bail, ensure, err_msg, Error};
use log::info;
use std::path::Path;
use std::sync::Arc;
@ -43,7 +44,7 @@ impl Client {
.as_ref()
.ok_or_else(|| err_msg("no mux_server_unix_domain_socket_path"))?,
);
eprintln!("connect to {}", sock_path.display());
info!("connect to {}", sock_path.display());
let stream = UnixStream::connect(sock_path)?;
Ok(Self { stream, serial: 0 })
}

View File

@ -13,6 +13,7 @@
use crate::mux::tab::TabId;
use failure::{bail, Error};
use leb128;
use log::debug;
use serde_derive::*;
use std::collections::HashMap;
use std::sync::Arc;
@ -88,7 +89,7 @@ fn decode_raw<R: std::io::Read>(mut r: R) -> Result<Decoded, std::io::Error> {
} else {
(len, false)
};
eprintln!("decode_raw {} compressed={}", len, is_compressed);
debug!("decode_raw {} compressed={}", len, is_compressed);
let serial = read_u64(r.by_ref())?;
let ident = read_u64(r.by_ref())?;
let data_len = len as usize - (encoded_length(ident) + encoded_length(serial));
@ -127,7 +128,7 @@ fn serialize<T: serde::Serialize>(t: &T) -> Result<(Vec<u8>, bool), Error> {
drop(encode);
compress.finish()?;
eprintln!(
debug!(
"serialized+compress len {} vs {}",
compressed.len(),
uncompressed.len()

View File

@ -5,6 +5,7 @@ use crate::server::{UnixListener, UnixStream};
use failure::{err_msg, format_err, Error};
#[cfg(unix)]
use libc::{mode_t, umask};
use log::{debug, error};
use promise::{Executor, Future};
use std::collections::HashMap;
use std::fs::{remove_file, DirBuilder};
@ -33,7 +34,7 @@ impl Listener {
thread::spawn(move || session.run());
}
Err(err) => {
eprintln!("accept failed: {}", err);
error!("accept failed: {}", err);
return;
}
}
@ -54,7 +55,7 @@ impl ClientSession {
fn process(&mut self) -> Result<(), Error> {
loop {
let decoded = Pdu::decode(&mut self.stream)?;
eprintln!("got pdu {:?} from client", decoded);
debug!("got pdu {:?} from client", decoded);
match decoded.pdu {
Pdu::Ping(Ping {}) => {
Pdu::Pong(Pong {}).encode(&mut self.stream, decoded.serial)?;
@ -153,7 +154,7 @@ impl Drop for UmaskSaver {
fn safely_create_sock_path(sock_path: &str) -> Result<UnixListener, Error> {
let sock_path = Path::new(sock_path);
eprintln!("setting up {}", sock_path.display());
debug!("setting up {}", sock_path.display());
let _saver = UmaskSaver::new();