mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-23 15:51:06 +01:00
refactor: use tracing in session examples
This commit is contained in:
parent
931c4eea4d
commit
8ebb12b75a
@ -43,8 +43,8 @@ redis = { version = "0.24", default-features = false, features = ["tokio-comp",
|
||||
actix-session = { path = ".", features = ["cookie-session", "redis-rs-session"] }
|
||||
actix-test = "0.1.0-beta.10"
|
||||
actix-web = { version = "4", default-features = false, features = ["cookies", "secure-cookies", "macros"] }
|
||||
env_logger = "0.11"
|
||||
log = "0.4"
|
||||
tracing-subscriber = {version = "0.3", features = ["env-filter"]}
|
||||
tracing = "0.1.30"
|
||||
|
||||
[[example]]
|
||||
name = "basic"
|
||||
|
@ -5,6 +5,8 @@ use actix_web::{
|
||||
middleware, web, App, Error, HttpResponse, HttpServer, Responder,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tracing::level_filters::LevelFilter;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Credentials {
|
||||
@ -71,15 +73,21 @@ async fn secret(session: Session) -> Result<impl Responder, Error> {
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||
tracing_subscriber::fmt()
|
||||
.with_env_filter(
|
||||
EnvFilter::builder()
|
||||
.with_default_directive(LevelFilter::INFO.into())
|
||||
.from_env_lossy(),
|
||||
)
|
||||
.init();
|
||||
|
||||
// The signing key would usually be read from a configuration file/environment variables.
|
||||
let signing_key = Key::generate();
|
||||
|
||||
log::info!("setting up Redis session storage");
|
||||
tracing::info!("setting up Redis session storage");
|
||||
let storage = RedisSessionStore::new("127.0.0.1:6379").await.unwrap();
|
||||
|
||||
log::info!("starting HTTP server at http://localhost:8080");
|
||||
tracing::info!("starting HTTP server at http://localhost:8080");
|
||||
|
||||
HttpServer::new(move || {
|
||||
App::new()
|
||||
|
@ -1,5 +1,7 @@
|
||||
use actix_session::{storage::RedisSessionStore, Session, SessionMiddleware};
|
||||
use actix_web::{cookie::Key, middleware, web, App, Error, HttpRequest, HttpServer, Responder};
|
||||
use tracing::level_filters::LevelFilter;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
|
||||
/// simple handler
|
||||
async fn index(req: HttpRequest, session: Session) -> Result<impl Responder, Error> {
|
||||
@ -18,15 +20,21 @@ async fn index(req: HttpRequest, session: Session) -> Result<impl Responder, Err
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||
tracing_subscriber::fmt()
|
||||
.with_env_filter(
|
||||
EnvFilter::builder()
|
||||
.with_default_directive(LevelFilter::INFO.into())
|
||||
.from_env_lossy(),
|
||||
)
|
||||
.init();
|
||||
|
||||
// The signing key would usually be read from a configuration file/environment variables.
|
||||
let signing_key = Key::generate();
|
||||
|
||||
log::info!("setting up Redis session storage");
|
||||
tracing::info!("setting up Redis session storage");
|
||||
let storage = RedisSessionStore::new("127.0.0.1:6379").await.unwrap();
|
||||
|
||||
log::info!("starting HTTP server at http://localhost:8080");
|
||||
tracing::info!("starting HTTP server at http://localhost:8080");
|
||||
|
||||
HttpServer::new(move || {
|
||||
App::new()
|
||||
|
Loading…
Reference in New Issue
Block a user