diff options
| -rw-r--r-- | mullvad-daemon/src/logging.rs | 20 | ||||
| -rw-r--r-- | mullvad-daemon/src/tunnel_state_machine/connecting_state.rs | 2 | ||||
| -rw-r--r-- | talpid-core/src/lib.rs | 3 | ||||
| -rw-r--r-- | talpid-core/src/logging.rs | 20 |
4 files changed, 30 insertions, 15 deletions
diff --git a/mullvad-daemon/src/logging.rs b/mullvad-daemon/src/logging.rs index 958d5321e6..9988ea6be2 100644 --- a/mullvad-daemon/src/logging.rs +++ b/mullvad-daemon/src/logging.rs @@ -6,9 +6,10 @@ use chrono; use log; use std::fmt; -use std::fs; use std::io; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; + +use talpid_core::logging::rotate_log; error_chain! { errors { @@ -17,6 +18,9 @@ error_chain! { display("Unable to open log file for writing: {}", path.display()) } } + links { + RotateLog(::talpid_core::logging::Error, ::talpid_core::logging::ErrorKind); + } foreign_links { SetLoggerError(log::SetLoggerError); Io(io::Error); @@ -138,15 +142,3 @@ fn escape_newlines(text: String) -> String { fn escape_newlines(text: String) -> String { text.replace("\n", LINE_SEPARATOR) } - -pub fn rotate_log(file: &Path) -> Result<()> { - let backup = file.with_extension("old.log"); - fs::rename(file, backup).unwrap_or_else(|error| { - if error.kind() != io::ErrorKind::NotFound { - warn!("Failed to rotate log file ({})", error); - } - }); - - fs::File::create(file).chain_err(|| "Unable to create new log file")?; - Ok(()) -} diff --git a/mullvad-daemon/src/tunnel_state_machine/connecting_state.rs b/mullvad-daemon/src/tunnel_state_machine/connecting_state.rs index c05d85d217..9175fe3239 100644 --- a/mullvad-daemon/src/tunnel_state_machine/connecting_state.rs +++ b/mullvad-daemon/src/tunnel_state_machine/connecting_state.rs @@ -8,6 +8,7 @@ use futures::sink::Wait; use futures::sync::{mpsc, oneshot}; use futures::{Async, Future, Sink, Stream}; +use talpid_core::logging; use talpid_core::security::{NetworkSecurity, SecurityPolicy}; use talpid_core::tunnel::{CloseHandle, TunnelEvent, TunnelMetadata, TunnelMonitor}; use talpid_types::net::{TunnelEndpoint, TunnelEndpointData}; @@ -17,7 +18,6 @@ use super::{ DisconnectingState, EventConsequence, Result, ResultExt, SharedTunnelStateValues, StateEntryResult, TunnelCommand, TunnelParameters, TunnelState, TunnelStateWrapper, }; -use logging; const MIN_TUNNEL_ALIVE_TIME: Duration = Duration::from_millis(1000); diff --git a/talpid-core/src/lib.rs b/talpid-core/src/lib.rs index 1ee4d3b6ad..b96764848f 100644 --- a/talpid-core/src/lib.rs +++ b/talpid-core/src/lib.rs @@ -47,6 +47,9 @@ pub mod process; /// Abstracts over different VPN tunnel technologies pub mod tunnel; +/// Helper function to preserve previous log files. +pub mod logging; + /// Abstractions and extra features on `std::mpsc` pub mod mpsc; diff --git a/talpid-core/src/logging.rs b/talpid-core/src/logging.rs new file mode 100644 index 0000000000..fe77297b84 --- /dev/null +++ b/talpid-core/src/logging.rs @@ -0,0 +1,20 @@ +use std::path::Path; +use std::{fs, io}; + +error_chain!{} + +/// Create a new log file while backing up a previous version of it. +/// +/// A new log file is created with the given file name, but if a file with that name already exists +/// it is backed up with the extension changed to `.old.log`. +pub fn rotate_log(file: &Path) -> Result<()> { + let backup = file.with_extension("old.log"); + fs::rename(file, backup).unwrap_or_else(|error| { + if error.kind() != io::ErrorKind::NotFound { + warn!("Failed to rotate log file ({})", error); + } + }); + + fs::File::create(file).chain_err(|| "Unable to create new log file")?; + Ok(()) +} |
