Skip to content

Commit 0ef7693

Browse files
Log system environment
1 parent a4cbbce commit 0ef7693

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/deploy_task.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use git::GitRepo;
44
use notifier;
55
use repo_config::{RepoConfig, DeployMethod};
66
use server_config::Environment;
7+
use std::env;
78
use std::error::Error;
89
use std::fs::File;
910
use std::io::Write;
@@ -48,15 +49,18 @@ impl Runnable for DeployTask {
4849
};
4950
logfile.write_all(b"\ntask running...\n");
5051

51-
// Log the environment variables
52-
logfile.write_all(format!("environment: {}\n", format_environment(&self.env)).as_bytes());
52+
// Log the hookshot environment variables
53+
logfile.write_all(format!("hookshot environment:\n---------------------\n {}\n", format_environment(&self.env)).as_bytes());
54+
55+
// Log the system environment variables
56+
logfile.write_all(format!("system environment:\n------------------\n {}\n", format_os_environment()).as_bytes());
5357

5458
// Log the current user
55-
logfile.write_all(format!("user: {}\n", users::get_current_username().unwrap_or("<none>".to_owned())).as_bytes());
59+
logfile.write_all(format!("user: {}\n\n", users::get_current_username().unwrap_or("<none>".to_owned())).as_bytes());
5660

5761
// Log what time the task started.
5862
let time_task_started = UTC::now();
59-
logfile.write_all(format!("started: {}...\n", time_task_started).as_bytes());
63+
logfile.write_all(format!("started: {}\n", time_task_started).as_bytes());
6064

6165
if let Err(git_error) = self.repo.get_latest() {
6266
let stderr = String::from_utf8(git_error.output.unwrap().stderr).unwrap();
@@ -150,8 +154,8 @@ impl Runnable for DeployTask {
150154
// Log what time the task ended and how long it took
151155
let time_task_ended = UTC::now();
152156
let duration = time_task_ended - time_task_started;
153-
logfile.write_all(format!("task finished: {}...\n", time_task_ended).as_bytes());
154-
logfile.write_all(format!("duration: {}...\n", format_duration(duration)).as_bytes());
157+
logfile.write_all(format!("task finished: {}\n", time_task_ended).as_bytes());
158+
logfile.write_all(format!("duration: {}...\n\n", format_duration(duration)).as_bytes());
155159

156160
// Log the exit code and the standard streams
157161
logfile.write_all(format!("exit code: {}.\n", exit_code).as_bytes());
@@ -187,3 +191,11 @@ fn format_environment(env: &Environment) -> String {
187191
}
188192
env_string
189193
}
194+
195+
fn format_os_environment() -> String {
196+
let mut env_string = String::new();
197+
for (k, v) in env::vars() {
198+
env_string.push_str(&format!("{}: {}\n", k, v))
199+
}
200+
env_string
201+
}

0 commit comments

Comments
 (0)