feat(log): clean up logging
This commit is contained in:
		| @@ -39,7 +39,7 @@ impl<R: Read> BufReader<R> { | ||||
|     #[inline] | ||||
|     pub fn get_buf(&self) -> &[u8] { | ||||
|         if self.pos < self.cap { | ||||
|             debug!("slicing {:?}", (self.pos, self.cap, self.buf.len())); | ||||
|             trace!("slicing {:?}", (self.pos, self.cap, self.buf.len())); | ||||
|             &self.buf[self.pos..self.cap] | ||||
|         } else { | ||||
|             &[] | ||||
| @@ -68,6 +68,7 @@ impl<R: Read> BufReader<R> { | ||||
|         if self.cap == cap { | ||||
|             self.buf.reserve(cmp::min(cap * 4, MAX_BUFFER_SIZE) - cap); | ||||
|             let new = self.buf.capacity() - self.buf.len(); | ||||
|             trace!("reserved {}", new); | ||||
|             self.buf.extend(iter::repeat(0).take(new)); | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -182,7 +182,7 @@ impl<'a, U: IntoUrl> RequestBuilder<'a, U> { | ||||
|     pub fn send(self) -> HttpResult<Response> { | ||||
|         let RequestBuilder { client, method, url, headers, body } = self; | ||||
|         let mut url = try!(url.into_url()); | ||||
|         debug!("client.request {:?} {:?}", method, url); | ||||
|         trace!("send {:?} {:?}", method, url); | ||||
|  | ||||
|         let can_have_body = match &method { | ||||
|             &Method::Get | &Method::Head => false, | ||||
| @@ -364,12 +364,12 @@ fn get_host_and_port(url: &Url) -> HttpResult<(String, u16)> { | ||||
|         Some(host) => host, | ||||
|         None => return Err(HttpUriError(UrlError::EmptyHost)) | ||||
|     }; | ||||
|     debug!("host={:?}", host); | ||||
|     trace!("host={:?}", host); | ||||
|     let port = match url.port_or_default() { | ||||
|         Some(port) => port, | ||||
|         None => return Err(HttpUriError(UrlError::InvalidPort)) | ||||
|     }; | ||||
|     debug!("port={:?}", port); | ||||
|     trace!("port={:?}", port); | ||||
|     Ok((host, port)) | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -52,7 +52,6 @@ impl Request<Fresh> { | ||||
|         -> HttpResult<Request<Fresh>> where | ||||
|         C: NetworkConnector<Stream=S>, | ||||
|         S: Into<Box<NetworkStream + Send>> { | ||||
|         debug!("{} {}", method, url); | ||||
|         let (host, port) = try!(get_host_and_port(&url)); | ||||
|  | ||||
|         let stream = try!(connector.connect(&*host, port, &*url.scheme)).into(); | ||||
| @@ -84,14 +83,14 @@ impl Request<Fresh> { | ||||
|             uri.push_str(&q[..]); | ||||
|         } | ||||
|  | ||||
|         debug!("writing head: {:?} {:?} {:?}", self.method, uri, self.version); | ||||
|         debug!("request line: {:?} {:?} {:?}", self.method, uri, self.version); | ||||
|         try!(write!(&mut self.body, "{} {} {}{}", | ||||
|                     self.method, uri, self.version, LINE_ENDING)); | ||||
|  | ||||
|  | ||||
|         let stream = match self.method { | ||||
|             Method::Get | Method::Head => { | ||||
|                 debug!("headers [\n{:?}]", self.headers); | ||||
|                 debug!("headers={:?}", self.headers); | ||||
|                 try!(write!(&mut self.body, "{}{}", self.headers, LINE_ENDING)); | ||||
|                 EmptyWriter(self.body.into_inner()) | ||||
|             }, | ||||
| @@ -124,7 +123,7 @@ impl Request<Fresh> { | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|                 debug!("headers [\n{:?}]", self.headers); | ||||
|                 debug!("headers={:?}", self.headers); | ||||
|                 try!(write!(&mut self.body, "{}{}", self.headers, LINE_ENDING)); | ||||
|  | ||||
|                 if chunked { | ||||
|   | ||||
| @@ -46,13 +46,13 @@ impl Response { | ||||
|             match headers.get::<TransferEncoding>() { | ||||
|                 Some(&TransferEncoding(ref codings)) => { | ||||
|                     if codings.len() > 1 { | ||||
|                         debug!("TODO: #2 handle other codings: {:?}", codings); | ||||
|                         trace!("TODO: #2 handle other codings: {:?}", codings); | ||||
|                     }; | ||||
|  | ||||
|                     if codings.contains(&Chunked) { | ||||
|                         ChunkedReader(stream, None) | ||||
|                     } else { | ||||
|                         debug!("not chuncked. read till eof"); | ||||
|                         trace!("not chuncked. read till eof"); | ||||
|                         EofReader(stream) | ||||
|                     } | ||||
|                 } | ||||
| @@ -64,7 +64,7 @@ impl Response { | ||||
|                 None => unreachable!() | ||||
|             } | ||||
|         } else { | ||||
|             debug!("neither Transfer-Encoding nor Content-Length"); | ||||
|             trace!("neither Transfer-Encoding nor Content-Length"); | ||||
|             EofReader(stream) | ||||
|         }; | ||||
|  | ||||
|   | ||||
| @@ -117,7 +117,7 @@ impl Headers { | ||||
|     pub fn from_raw<'a>(raw: &[httparse::Header<'a>]) -> HttpResult<Headers> { | ||||
|         let mut headers = Headers::new(); | ||||
|         for header in raw { | ||||
|             debug!("raw header: {:?}={:?}", header.name, &header.value[..]); | ||||
|             trace!("raw header: {:?}={:?}", header.name, &header.value[..]); | ||||
|             let name = UniCase(CowStr(Cow::Owned(header.name.to_owned()))); | ||||
|             let mut item = match headers.data.entry(name) { | ||||
|                 Entry::Vacant(entry) => entry.insert(Item::new_raw(vec![])), | ||||
| @@ -234,11 +234,11 @@ impl fmt::Display for Headers { | ||||
|  | ||||
| impl fmt::Debug for Headers { | ||||
|     fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
|         try!(fmt.write_str("Headers {{ ")); | ||||
|         try!(fmt.write_str("Headers { ")); | ||||
|         for header in self.iter() { | ||||
|             try!(write!(fmt, "{:?}, ", header)); | ||||
|         } | ||||
|         try!(fmt.write_str("}}")); | ||||
|         try!(fmt.write_str("}")); | ||||
|         Ok(()) | ||||
|     } | ||||
| } | ||||
|   | ||||
							
								
								
									
										10
									
								
								src/http.rs
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/http.rs
									
									
									
									
									
								
							| @@ -77,7 +77,7 @@ impl<R: Read> Read for HttpReader<R> { | ||||
|     fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { | ||||
|         match *self { | ||||
|             SizedReader(ref mut body, ref mut remaining) => { | ||||
|                 debug!("Sized read, remaining={:?}", remaining); | ||||
|                 trace!("Sized read, remaining={:?}", remaining); | ||||
|                 if *remaining == 0 { | ||||
|                     Ok(0) | ||||
|                 } else { | ||||
| @@ -96,7 +96,7 @@ impl<R: Read> Read for HttpReader<R> { | ||||
|                     // None means we don't know the size of the next chunk | ||||
|                     None => try!(read_chunk_size(body)) | ||||
|                 }; | ||||
|                 debug!("Chunked read, remaining={:?}", rem); | ||||
|                 trace!("Chunked read, remaining={:?}", rem); | ||||
|  | ||||
|                 if rem == 0 { | ||||
|                     *opt_remaining = Some(0); | ||||
| @@ -104,7 +104,7 @@ impl<R: Read> Read for HttpReader<R> { | ||||
|                     // chunk of size 0 signals the end of the chunked stream | ||||
|                     // if the 0 digit was missing from the stream, it would | ||||
|                     // be an InvalidInput error instead. | ||||
|                     debug!("end of chunked"); | ||||
|                     trace!("end of chunked"); | ||||
|                     return Ok(0) | ||||
|                 } | ||||
|  | ||||
| @@ -205,7 +205,7 @@ fn read_chunk_size<R: Read>(rdr: &mut R) -> io::Result<u64> { | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|     debug!("chunk size={:?}", size); | ||||
|     trace!("chunk size={:?}", size); | ||||
|     Ok(size) | ||||
| } | ||||
|  | ||||
| @@ -279,7 +279,7 @@ impl<W: Write> Write for HttpWriter<W> { | ||||
|             ThroughWriter(ref mut w) => w.write(msg), | ||||
|             ChunkedWriter(ref mut w) => { | ||||
|                 let chunk_size = msg.len(); | ||||
|                 debug!("chunked write, size = {:?}", chunk_size); | ||||
|                 trace!("chunked write, size = {:?}", chunk_size); | ||||
|                 try!(write!(w, "{:X}{}", chunk_size, LINE_ENDING)); | ||||
|                 try!(w.write_all(msg)); | ||||
|                 try!(w.write_all(LINE_ENDING.as_bytes())); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user