Skip to content

Commit edfb2b2

Browse files
committed
improve logging
1 parent 08e3485 commit edfb2b2

File tree

23 files changed

+82
-31
lines changed

23 files changed

+82
-31
lines changed

src/meta-cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ path = "src/main.rs"
2727
[features]
2828
default = []
2929
typegate = ["dep:typegate_engine"]
30+
tracing-instrument = []
3031

3132
[dependencies]
3233

src/meta-cli/src/cli/completion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub struct Completion {
2222

2323
#[async_trait]
2424
impl Action for Completion {
25-
#[tracing::instrument]
25+
#[cfg_attr(feature = "tracing-instrument", tracing::instrument)]
2626
async fn run(&self, _args: ConfigArgs) -> Result<()> {
2727
let mut cmd = Args::command();
2828
let name = cmd.get_name().to_string();

src/meta-cli/src/cli/deploy.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub struct Deploy {
106106
}
107107

108108
impl Deploy {
109-
#[tracing::instrument]
109+
#[cfg_attr(feature = "tracing-instrument", tracing::instrument)]
110110
pub async fn new(deploy: &DeploySubcommand, args: &ConfigArgs) -> Result<Self> {
111111
let dir: Arc<Path> = args.dir()?.into();
112112

@@ -143,7 +143,7 @@ impl Deploy {
143143

144144
#[async_trait]
145145
impl Action for DeploySubcommand {
146-
#[tracing::instrument]
146+
#[cfg_attr(feature = "tracing-instrument", tracing::instrument)]
147147
async fn run(&self, args: ConfigArgs) -> Result<()> {
148148
let deploy = Deploy::new(self, &args).await?;
149149

@@ -285,7 +285,7 @@ mod watch_mode {
285285

286286
use super::*;
287287

288-
#[tracing::instrument]
288+
#[cfg_attr(feature = "tracing-instrument", tracing::instrument)]
289289
pub async fn enter_watch_mode(deploy: Deploy) -> Result<()> {
290290
if deploy.file.is_some() {
291291
bail!("Cannot use --file in watch mode");

src/meta-cli/src/cli/dev.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub struct Dev {
4848

4949
#[async_trait]
5050
impl Action for Dev {
51-
#[tracing::instrument]
51+
#[cfg_attr(feature = "tracing-instrument", tracing::instrument)]
5252
async fn run(&self, args: ConfigArgs) -> Result<()> {
5353
log::info!("'meta dev' subcommand is an alias to 'meta deploy --codegen --allow-dirty --watch --create-migration'");
5454
let options = DeployOptions {

src/meta-cli/src/cli/doctor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn shell(cmds: Vec<&str>) -> Result<String> {
3131

3232
#[async_trait]
3333
impl Action for Doctor {
34-
#[tracing::instrument]
34+
#[cfg_attr(feature = "tracing-instrument", tracing::instrument)]
3535
async fn run(&self, args: ConfigArgs) -> Result<()> {
3636
let dir = &args.dir()?;
3737

src/meta-cli/src/cli/fdk_template.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct CreateFdkTemplate {
2828

2929
#[async_trait]
3030
impl Action for CreateFdkTemplate {
31-
#[tracing::instrument]
31+
#[cfg_attr(feature = "tracing-instrument", tracing::instrument)]
3232
async fn run(&self, args: ConfigArgs) -> Result<()> {
3333
let dir = args.dir()?.join(&self.dir);
3434
tracing::info!("creating fdk template at {:?}", dir);

src/meta-cli/src/cli/gen.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub struct Gen {
3737

3838
#[async_trait]
3939
impl Action for Gen {
40-
#[tracing::instrument]
40+
#[cfg_attr(feature = "tracing-instrument", tracing::instrument)]
4141
async fn run(&self, args: ConfigArgs) -> Result<()> {
4242
let dir = args.dir()?;
4343
let config = Config::load_or_find(args.config.as_deref(), &dir)?;
@@ -84,19 +84,29 @@ impl Action for Gen {
8484
resolver,
8585
)
8686
.await?;
87+
88+
let working_dir = args.dir()?;
89+
let working_dir = &working_dir;
90+
8791
files
8892
.0
8993
.into_iter()
9094
.map(|(path, file)| async move {
9195
tokio::fs::create_dir_all(path.parent().unwrap()).await?;
9296
if file.overwrite || !tokio::fs::try_exists(&path).await? {
97+
let relative_path = pathdiff::diff_paths(&path, working_dir);
98+
info!(
99+
"writing to {:?}...",
100+
relative_path.as_deref().unwrap_or(path.as_path()),
101+
);
93102
tokio::fs::write(path, file.contents).await?;
94103
}
95104
Ok::<_, tokio::io::Error>(())
96105
})
97106
.collect::<Vec<_>>()
98107
.try_join()
99108
.await?;
109+
info!("all outputs have successfully been written");
100110

101111
Ok(())
102112
}
@@ -158,7 +168,7 @@ async fn load_fdk_template(
158168
}
159169

160170
impl InputResolver for MetagenCtx {
161-
#[tracing::instrument]
171+
#[cfg_attr(feature = "tracing-instrument", tracing::instrument)]
162172
async fn resolve(&self, order: GeneratorInputOrder) -> Result<GeneratorInputResolved> {
163173
Ok(match order {
164174
GeneratorInputOrder::TypegraphFromTypegate { name } => {
@@ -206,7 +216,7 @@ impl InputResolver for MetagenCtx {
206216
}
207217
}
208218

209-
#[tracing::instrument]
219+
#[cfg_attr(feature = "tracing-instrument", tracing::instrument)]
210220
async fn load_tg_at(
211221
config: Arc<Config>,
212222
path: PathBuf,

src/meta-cli/src/cli/list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub struct List {
3232

3333
#[async_trait]
3434
impl Action for List {
35-
#[tracing::instrument]
35+
#[cfg_attr(feature = "tracing-instrument", tracing::instrument)]
3636
async fn run(&self, args: ConfigArgs) -> Result<()> {
3737
let dir = args.dir()?;
3838
let config_path = args.config.clone();

src/meta-cli/src/cli/new.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@ pub struct New {
4242

4343
#[async_trait]
4444
impl Action for New {
45-
#[tracing::instrument]
45+
#[cfg_attr(feature = "tracing-instrument", tracing::instrument)]
4646
async fn run(&self, args: ConfigArgs) -> Result<()> {
4747
let dir = PathBuf::from(&self.dir);
4848
let target_dir = if dir.is_absolute() {
4949
dir
5050
} else {
5151
args.dir()?.join(&dir)
5252
};
53-
println!("target directory {}", target_dir.display());
53+
debug!("target directory {}", target_dir.display());
5454

5555
let template_name = self.template.name();
5656
match TEMPLATES.get_dir(template_name) {
5757
Some(template) => {
5858
if !target_dir.exists() {
59-
println!("creating directory: {}", target_dir.display());
59+
info!("creating directory: {}", target_dir.display());
6060
std::fs::create_dir(&target_dir)?;
6161
} else if target_dir.is_file() {
6262
bail!("target directory is a file: {}", target_dir.display());

src/meta-cli/src/cli/serialize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub struct Serialize {
5151

5252
#[async_trait]
5353
impl Action for Serialize {
54-
#[tracing::instrument]
54+
#[cfg_attr(feature = "tracing-instrument", tracing::instrument)]
5555
async fn run(&self, args: ConfigArgs) -> Result<()> {
5656
let dir = args.dir()?;
5757
let config_path = args.config.clone();

src/meta-cli/src/cli/undeploy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub struct Undeploy {
2323

2424
#[async_trait]
2525
impl Action for Undeploy {
26-
#[tracing::instrument]
26+
#[cfg_attr(feature = "tracing-instrument", tracing::instrument)]
2727
async fn run(&self, args: super::ConfigArgs) -> Result<()> {
2828
let dir = args.dir()?;
2929
let config_path = args.config.clone();

src/meta-cli/src/cli/upgrade.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub struct Upgrade {
2525

2626
#[async_trait]
2727
impl Action for Upgrade {
28-
#[tracing::instrument]
28+
#[cfg_attr(feature = "tracing-instrument", tracing::instrument)]
2929
async fn run(&self, _args: ConfigArgs) -> Result<()> {
3030
// https://github.com/jaemk/self_update/issues/44
3131
let opts = self.clone();
@@ -60,7 +60,7 @@ impl Action for Upgrade {
6060
}
6161
}
6262

63-
#[tracing::instrument]
63+
#[cfg_attr(feature = "tracing-instrument", tracing::instrument)]
6464
pub async fn upgrade_check() -> Result<()> {
6565
let config_path = GlobalConfig::default_path()?;
6666
let mut local_config = GlobalConfig::load(&config_path).await?;

src/meta-cli/src/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl NodeConfig {
108108
}
109109
}
110110

111-
#[tracing::instrument]
111+
#[cfg_attr(feature = "tracing-instrument", tracing::instrument)]
112112
pub async fn get_admin_password(
113113
&self,
114114
dir: impl AsRef<Path> + std::fmt::Debug,
@@ -142,7 +142,7 @@ impl NodeConfig {
142142
Ok(password)
143143
}
144144

145-
#[tracing::instrument]
145+
#[cfg_attr(feature = "tracing-instrument", tracing::instrument)]
146146
pub async fn build<P: AsRef<Path> + core::fmt::Debug>(&self, dir: P) -> Result<Node> {
147147
Node::new(
148148
self.url.clone(),

src/meta-cli/src/deploy/actors/typegate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl TypegateInit {
7171
})
7272
}
7373

74-
#[tracing::instrument]
74+
#[cfg_attr(feature = "tracing-instrument", tracing::instrument)]
7575
pub async fn start(self, console: Addr<ConsoleActor>) -> Result<(Addr<TypegateActor>, u16)> {
7676
let (ready_tx, ready_rx) = oneshot::channel();
7777

src/meta-cli/src/main.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ use shadow_rs::shadow;
5757

5858
shadow!(build);
5959

60-
#[tracing::instrument]
60+
#[cfg_attr(feature = "tracing-instrument", tracing::instrument)]
6161
fn main() -> Result<()> {
6262
/* FIXME: handle broken pipe on all `println!` calls
6363
* setting default SIG_PIPE behaviour would be one
@@ -82,7 +82,14 @@ fn main() -> Result<()> {
8282

8383
if args.verbose.is_present() {
8484
let filter = args.verbose.log_level_filter().to_string();
85-
unsafe { std::env::set_var("RUST_LOG", format!("warn,meta={filter}")) };
85+
unsafe {
86+
std::env::set_var(
87+
"RUST_LOG",
88+
format!(
89+
"warn,meta={filter},metagen={filter},tg_schema={filter},typegraph={filter}"
90+
),
91+
)
92+
};
8693
}
8794
logger::init();
8895
if args.version {

src/metagen/src/client_py/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,13 @@ impl crate::Plugin for Generator {
8787
_ => bail!("unexpected input type"),
8888
};
8989
let mut out = IndexMap::new();
90+
info!("building render manifest");
9091
let tg = TypegraphExpansionConfig::default().expand_with_default_params(tg)?;
9192
let manif = ClientPyManifest::new(tg.clone())?;
9293
let mut contents = String::new();
94+
info!("rendering...");
9395
manif.render(&mut contents, &self.config)?;
96+
info!("rendering done successfully");
9497
out.insert(
9598
self.config.base.path.join("client.py"),
9699
GeneratedFile {

src/metagen/src/client_rs/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,17 @@ impl crate::Plugin for Generator {
161161
};
162162
let tg = TypegraphExpansionConfig::default().expand_with_default_params(tg)?;
163163
let mut out = IndexMap::new();
164+
info!("building render manifest");
164165
let manif = RsClientManifest::new(
165166
tg.clone(),
166167
&RsClientManifestOpts {
167168
non_partial_output_types: false,
168169
},
169170
)?;
170171
let mut buf = String::new();
172+
info!("rendering...");
171173
manif.render(&mut buf)?;
174+
info!("rendering done successfully");
172175
out.insert(
173176
self.config.base.path.join("client.rs"),
174177
GeneratedFile {

src/metagen/src/client_ts/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,12 @@ impl crate::Plugin for Generator {
132132

133133
let tg = TypegraphExpansionConfig::default().expand_with_default_params(tg)?;
134134
let mut out = IndexMap::new();
135+
info!("building render manifest");
135136
let manif = TsClientManifest::new(tg.clone(), false)?;
136137
let mut buf = String::new();
138+
info!("rendering...");
137139
manif.render(&mut buf)?;
140+
info!("rendering done successfully");
138141
out.insert(
139142
self.config.base.path.join("client.ts"),
140143
GeneratedFile {

src/metagen/src/fdk_py/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,19 @@ impl FdkPythonTemplate {
8888
writeln!(&mut fdk_py)?;
8989
self.gen_static(&mut fdk_py)?;
9090
let ty_name_memo = if config.exclude_client.unwrap_or_default() {
91+
info!("building render manifest...");
9192
let manif = PyTypesPage::new(&tg);
9293
manif.cache_references();
94+
info!("rendering...");
9395
manif.render_all(&mut fdk_py)?;
96+
info!("rendering done successfully");
9497
manif.get_cached_refs()
9598
} else {
99+
info!("building render manifest...");
96100
let manif = ClientPyManifest::new(tg.clone())?;
101+
info!("rendering...");
97102
manif.render_client(&mut fdk_py, true)?;
103+
info!("rendering done successfully");
98104
manif.maps.types
99105
};
100106
writeln!(&mut fdk_py)?;

src/metagen/src/fdk_rs/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,15 @@ impl FdkRustTemplate {
207207
self.gen_static(&mut mod_rs, config)?;
208208

209209
let maps = if config.exclude_client.unwrap_or_default() {
210+
info!("building render manifest...");
210211
let manifest = RustTypesConfig::default()
211212
.output_types(OutputTypes::NonPartial)
212213
.derive_serde(true)
213214
.derive_debug(true)
214215
.build_manifest(&tg);
216+
info!("rendering...");
215217
manifest.render_full(&mut mod_rs.buf)?;
218+
info!("rendering done successfully");
216219

217220
Maps {
218221
inputs: manifest.inputs.get_cached_refs(),
@@ -221,24 +224,21 @@ impl FdkRustTemplate {
221224
.as_ref()
222225
.map(|p| p.get_cached_refs())
223226
.unwrap_or_default(),
224-
// partial_outputs: manifest
225-
// .partial_outputs
226-
// .as_ref()
227-
// .map(|p| p.get_cached_refs())
228-
// .unwrap_or_default(),
229227
}
230228
} else {
229+
info!("building render manifest...");
231230
let manifest = RsClientManifest::new(
232231
tg.clone(),
233232
&RsClientManifestOpts {
234233
non_partial_output_types: true,
235234
},
236235
)?;
236+
info!("rendering...");
237237
manifest.render_client(&mut mod_rs.buf, &GenClientRsOpts { hostcall: true })?;
238+
info!("rendering done successfully");
238239
Maps {
239240
inputs: manifest.maps.input_types,
240241
outputs: manifest.maps.output_types,
241-
// partial_outputs: manifest.maps.partial_output_types,
242242
}
243243
};
244244

src/metagen/src/fdk_ts/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,18 @@ impl FdkTypescriptTemplate {
9595
self.gen_static(&mut fdk_ts)?;
9696

9797
let map = if config.exclude_client.unwrap_or_default() {
98+
info!("building render manifest...");
9899
let manif = TsTypesPage::new(&tg, true);
100+
info!("rendering...");
99101
manif.render_all(&mut fdk_ts)?;
102+
info!("rendering done successfully");
100103
manif.get_cached_refs()
101104
} else {
105+
info!("building render manifest...");
102106
let manif = TsClientManifest::new(tg.clone(), true)?;
107+
info!("rendering...");
103108
manif.render_client(&mut fdk_ts, &GenClientTsOpts { hostcall: true })?;
109+
info!("rendering done successfully");
104110
manif.types.get_cached_refs()
105111
};
106112

0 commit comments

Comments
 (0)