Skip to content

Commit

Permalink
feat(server): add param to define logs directory (#551)
Browse files Browse the repository at this point in the history
## What problem are you trying to solve?

IntelliJ would like to define the directory to save the logs.

## What is your solution?

Added a new option to define the path of the folder to save the logs.

## Alternatives considered

## What the reviewer should know

IDE-3777
  • Loading branch information
robertohuertasm authored Nov 5, 2024
1 parent d03da35 commit 5a775d9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
26 changes: 18 additions & 8 deletions crates/bins/src/bin/datadog_static_analyzer_server/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,38 @@ fn get_opts() -> Options {
"directory for static files",
"/path/to/directory",
);
opts.optopt("p", "port", "port to run the server on", "8000");
opts.optopt("a", "address", "address to listen on", "127.0.0.1");
opts.optopt("p", "port", "Port to run the server on", "8000");
opts.optopt("a", "address", "Address to listen on", "127.0.0.1");
opts.optopt(
"k",
"keep-alive-timeout",
"how many seconds without a request the server will exit",
"How many seconds without a request the server will exit",
"90",
);
opts.optflag("e", "enable-shutdown", "enables the shutdown endpoint");
opts.optflag("h", "help", "print this help");
opts.optflag("v", "version", "shows the tool version");
opts.optflag("e", "enable-shutdown", "Enables the shutdown endpoint");
opts.optflag("h", "help", "Print this help");
opts.optflag("v", "version", "Shows the tool version");

opts.optopt(
"l",
"logs",
"Enables log rotation and saves logs to a file in a system temp folder. Options: minutely, hourly, daily",
"[minutely, hourly, daily]",
);

opts.optopt(
"d",
"logs-dir",
"Allows to define the directory where the logs will be saved",
"/tmp/static-analysis-server",
);

// TODO (JF): Remove this when releasing 0.3.8
opts.optflag("", "ddsa-runtime", "(deprecated)");
opts
}

fn get_log_dir() -> PathBuf {
fn get_default_log_dir() -> PathBuf {
let path = "static-analysis-server/logs";
#[cfg(unix)]
{
Expand Down Expand Up @@ -138,7 +146,9 @@ pub fn prepare_rocket(tx_keep_alive_error: Sender<i32>) -> Result<RocketPreparat
// initialize the tracing subscriber here as we're only interested in the server logs not the other CLI instructions
let guard = if let Some(log_rolling) = matches.opt_str("l") {
// tracing with logs
let log_dir = get_log_dir();
let log_dir = matches
.opt_str("d")
.map_or_else(get_default_log_dir, std::convert::Into::into);
let file_appender = try_to_file_appender(
log_rolling,
log_dir,
Expand Down
5 changes: 1 addition & 4 deletions crates/bins/src/bin/datadog_static_analyzer_server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ pub async fn start() {
// launch the rocket and check if we receive a keep-alive error
let result = rocket::tokio::select! {
a = endpoints::launch_rocket_with_endpoints(*rocket, tx_rocket_shutdown) => a,
b = rx_keep_alive_error.recv() => match b {
Some(c) => Err(c.into()),
_ => Err(EndpointError::ExitCode(ERROR_CHANNEL_SENDER_DROPPED))
},
b = rx_keep_alive_error.recv() => b.map_or_else(|| Err(EndpointError::ExitCode(ERROR_CHANNEL_SENDER_DROPPED)), |c| Err(c.into())),
};

if let Err(e) = result {
Expand Down

0 comments on commit 5a775d9

Please sign in to comment.