stc icon indicating copy to clipboard operation
stc copied to clipboard

Timer logging should be switched to a flag.

Open sunrabbit123 opened this issue 1 year ago • 10 comments

  1. the function is platform dependent
  2. if you want to bind to multiple platforms, this function can be a headache.
  3. when not in debug mode, it times but does not log.

https://github.com/dudykr/stc/blob/main/crates/stc_ts_type_checker/src/lib.rs#L91-L107


Suggest solution

mapping function, and take flag

sunrabbit123 avatar Sep 08 '23 15:09 sunrabbit123

part of resolve #1085

not implemented flag system

sunrabbit123 avatar Sep 11 '23 09:09 sunrabbit123

hi there I am new to rust

  pub fn check(&self, entry: Arc<FileName>) -> ModuleId {
        let timer = PerfTimer::tracing_debug();

        let modules = self.module_loader.load_module(&entry, true).expect("failed to load entry");
        #[cfg(debug_assertions)]
        timer.log(&format!("Loading of `{}` and dependencies", entry));
        let timer = PerfTimer::tracing_debug();

        self.analyze_module(None, entry.clone());
        #[cfg(debug_assertions)]
        timer.log(&format!("Analysis of `{}` and dependencies", entry));

        modules.entry.id
    }

should the changes be like this? @sunrabbit123

moaoa avatar Oct 14 '23 08:10 moaoa

or should i use #[cfg(feature = "debug")] ?

moaoa avatar Oct 14 '23 08:10 moaoa

It's a similar feeling, but I hope that the ratings for debug, information, error, etc. will be divided

sunrabbit123 avatar Oct 14 '23 08:10 sunrabbit123

Do you mean we need to create another flag for logging?

moaoa avatar Oct 14 '23 15:10 moaoa

Do you mean we need to create another flag for logging?

Something like this:

#[cfg(feature = "log")]

moaoa avatar Oct 14 '23 15:10 moaoa

I know that you can't assign a value to a feature flag. Is there a workaround?

What I'm envisioning is to divide the log levels and ignore logs below a certain level by a certain value at compile time.

Of course, the above is just my wishful thinking.

The purpose of the feature is to make it work without bugs in NAPI, WASM, and not to have logs that are not needed.

And just in case it's confusing, we'll mention the When I refer to flags in the text, I mean argument values for something, not rust feature flags. Sure, it could be a rust feature flag, but I think it has limited functionality.

sunrabbit123 avatar Oct 16 '23 01:10 sunrabbit123

Yeah, feature flags are quite limited. We may create our own macro for logging which invokes macros from tracing. If we do so, we will have much more detailed control, even with cargo feature flags.

cargo feature:

  • stc_logger/log-type-creation
  • stc_logger/info (maybe)

kdy1 avatar Oct 16 '23 04:10 kdy1

Can you guys guide me on how to implement this? @kdy1 @sunrabbit123

moaoa avatar Oct 23 '23 15:10 moaoa

What guide do you want? I didn't understand what you were talking about.


https://docs.rs/log/latest/log/

btw, The following structure also looks good.

sunrabbit123 avatar Oct 30 '23 09:10 sunrabbit123