Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 14 additions & 30 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use env_logger::filter::Builder as FilterBuilder;
use log::{set_boxed_logger, LevelFilter, SetLoggerError};
use logger::Configuration;
use parking_lot::RwLock;
use std::{fmt, io, sync::Arc, time::SystemTime};
use std::{fmt, io, process, sync::Arc, time::SystemTime};
use thiserror::Error;

mod events;
Expand Down Expand Up @@ -160,8 +160,6 @@ enum TagMode {
/// `pmsg` device without paying the price for system calls twice.
struct Record<'tag, 'msg> {
timestamp: SystemTime,
pid: u16,
thread_id: u16,
buffer_id: Buffer,
tag: &'tag str,
priority: Priority,
Expand Down Expand Up @@ -440,22 +438,12 @@ impl Builder {
/// # use android_logd_logger::{Buffer, Priority};
/// # use std::time::SystemTime;
///
/// android_logd_logger::log(SystemTime::now(), Buffer::Main, Priority::Info, 0, 0, "tag", "message").unwrap();
/// android_logd_logger::log(SystemTime::now(), Buffer::Main, Priority::Info, "tag", "message").unwrap();
/// ```
#[cfg(target_os = "android")]
pub fn log(
timestamp: SystemTime,
buffer_id: Buffer,
priority: Priority,
pid: u16,
thread_id: u16,
tag: &str,
message: &str,
) -> Result<(), Error> {
pub fn log(timestamp: SystemTime, buffer_id: Buffer, priority: Priority, tag: &str, message: &str) -> Result<(), Error> {
let record = Record {
timestamp,
pid,
thread_id,
buffer_id,
tag,
priority,
Expand All @@ -477,22 +465,12 @@ pub fn log(
/// # use android_logd_logger::{Buffer, Priority};
/// # use std::time::SystemTime;
///
/// android_logd_logger::log(SystemTime::now(), Buffer::Main, Priority::Info, 0, 0, "tag", "message").unwrap();
/// android_logd_logger::log(SystemTime::now(), Buffer::Main, Priority::Info, "tag", "message").unwrap();
/// ```
#[cfg(not(target_os = "android"))]
pub fn log(
timestamp: SystemTime,
buffer_id: Buffer,
priority: Priority,
pid: u16,
thread_id: u16,
tag: &str,
message: &str,
) -> Result<(), Error> {
pub fn log(timestamp: SystemTime, buffer_id: Buffer, priority: Priority, tag: &str, message: &str) -> Result<(), Error> {
let record = Record {
timestamp,
pid,
thread_id,
buffer_id,
tag,
priority,
Expand Down Expand Up @@ -520,8 +498,6 @@ fn log_record(record: &Record) -> Result<(), Error> {
tag,
priority,
message,
thread_id,
pid,
..
} = record;

Expand All @@ -533,6 +509,14 @@ fn log_record(record: &Record) -> Result<(), Error> {
})
.and_then(|ts| ts.format(&DATE_TIME_FORMAT).map_err(|e| Error::Timestamp(e.to_string())))?;

eprintln!("{} {} {} {} {}: {}", timestamp, pid, thread_id, priority, tag, message);
eprintln!(
"{} {} {} {} {}: {}",
timestamp,
process::id(),
thread::id(),
priority,
tag,
message
);
Ok(())
}
2 changes: 0 additions & 2 deletions src/logd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ fn smoke() {
let timestamp = SystemTime::now();
let record = Record {
timestamp,
pid: std::process::id() as u16,
thread_id: thread::id() as u16,
buffer_id: Buffer::Main,
tag: "test",
priority: Priority::Info,
Expand Down
6 changes: 2 additions & 4 deletions src/logger.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{thread, Buffer, Priority, Record, TagMode};
use crate::{Buffer, Priority, Record, TagMode};
use env_logger::filter::{Builder, Filter};
use log::{LevelFilter, Log, Metadata};
use parking_lot::RwLock;
use std::{io, process, sync::Arc, time::SystemTime};
use std::{io, sync::Arc, time::SystemTime};

/// Logger configuration.
pub(crate) struct Configuration {
Expand Down Expand Up @@ -240,8 +240,6 @@ impl Log for LoggerImpl {
let timestamp = SystemTime::now();
let record = Record {
timestamp,
pid: process::id() as u16,
thread_id: thread::id() as u16,
buffer_id: configuration.buffer_id,
tag,
priority,
Expand Down
7 changes: 4 additions & 3 deletions src/pmsg.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::{logging_iterator::NewlineScaledChunkIterator, Buffer, Priority, Record};
use crate::{logging_iterator::NewlineScaledChunkIterator, thread, Buffer, Priority, Record};
use bytes::{BufMut, BytesMut};
use std::{
fs::{File, OpenOptions},
io::{self, Write},
process,
time::UNIX_EPOCH,
};

Expand Down Expand Up @@ -63,11 +64,11 @@ fn log_pmsg_packet(record: &Record, msg_part: &str) {
let mut buffer = bytes::BytesMut::with_capacity(packet_len as usize);
let timestamp = record.timestamp.duration_since(UNIX_EPOCH).unwrap();

write_pmsg_header(&mut buffer, packet_len, DUMMY_UID, record.pid);
write_pmsg_header(&mut buffer, packet_len, DUMMY_UID, process::id() as u16);
write_log_header(
&mut buffer,
record.buffer_id,
record.thread_id,
thread::id() as u16,
timestamp.as_secs() as u32,
timestamp.subsec_nanos(),
);
Expand Down