I am creating an API server using the Rust actix-web framework. I am creating and checking logs (using log4rs) in the local environment without any problems. After Dockerizing, Docker runs without a problem, but the locker log is not checked.
App main.rs
#[actix_web::main]
async fn main() -> std::io::Result<()> {
//로깅
match log4rs::init_file("log4rs.yml", Default::default()) {
Ok(_) => {}
Err(e) => {
println!("{}", e);
}
}
let configuration = get_configuration().expect("F to read config");
let address = format!(
"{}:{}",
configuration.application.host, configuration.application.port
);
//DB
//let connection_pool = PgPool::connect(&configuration.database.connection_string()).await.expect("F to connect db");
let connection_pool = PgPoolOptions::new()
.max_connections(5)
.acquire_timeout(std::time::Duration::from_secs(2))
.connect_lazy(&configuration.database.connection_string())
.expect("F to connect db");
//let db_pool = web::Data::new(connection_pool);
//데이터초기화
match check_and_insert_default_data(connection_pool.clone()).await {
Ok(_) => info!("Default data checked and inserted if necessary"),
Err(e) => info!("Failed to insert default data: {}", e),
}
run(address, connection_pool)?.await
}
log4rs.yaml
refresh_rate: 30 seconds
appenders:
# An appender named "stdout" that writes to stdout
stdout:
kind: console
filters:
- kind: threshold
level: debug
trace:
kind: file
filters:
- kind: threshold
level: trace
path: "logs/trace.log"
encoder:
pattern: "{d(%Y-%m-%d %H:%M:%S %Z)(utc)} - {l}:{m}{n}"
debug:
kind: file
filters:
- kind: threshold
level: debug
path: "logs/debug.log"
encoder:
pattern: "{d(%Y-%m-%d %H:%M:%S %Z)(utc)} - {l}:{m}{n}"
info:
kind: file
filters:
- kind: threshold
level: info
path: "logs/info.log"
encoder:
pattern: "{d(%Y-%m-%d %H:%M:%S %Z)(utc)} - {l}:{m}{n}"
warn:
kind: file
filters:
- kind: threshold
level: warn
path: "logs/warn.log"
encoder:
pattern: "{d(%Y-%m-%d %H:%M:%S %Z)(utc)} - {l}:{m}{n}"
error:
kind: file
filters:
- kind: threshold
level: error
path: "logs/error.log"
encoder:
pattern: "{d(%Y-%m-%d %H:%M:%S %Z)(utc)} - {l}:{m}{n}"
# Set the default logging level to "warn" and attach the "stdout" appender to the root
root:
appenders:
- stdout
- trace
- debug
- info
- warn
- error
#docker file
FROM rust:1.77.1-slim AS builder
WORKDIR /usr/src/back
RUN cargo init .
COPY Cargo* ./
RUN cargo build --release &&
rm target/release/deps/back*
COPY . .
UN cargo build --release
FROM rust:1.77.1-slim
WORKDIR /usr/local/bin
COPY --from=builder /usr/src/back/configuration ./configuration
COPY --from=builder /usr/src/back/target/release/back .
ENV APP_ENVIRONMENT production
CMD ["./back"]
#docker run
docker run -d -p 8082:8082 --rm --name rustback back
——————————————
In local log example
2024-07-26T13:29:01.947045500+09:00 INFO back – Default data checked and inserted if necessary
2024-07-26T13:29:01.961803100+09:00 INFO actix_server::builder – starting 12 workers
2024-07-26T13:29:01.962299400+09:00 INFO actix_server::server – Actix runtime found; starting in Actix runtime
Ubuntu serve docker log example
No such file or directory (os error 2)
I’m not sure if the problem is the Docker file or the application settings.
same log shows up in linux server and local
이경서 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.