How can I change the log level on the fly with tracing? - rust

As a developer I would like to adjust the log level on the fly. For example, I don't want to log debug! events when everything is going fine, but when something happens, I would like to adjust the log level without restarting the application to change the log level. I check the documentation and can't find an example there, so I want to know if it is possible to do that.
// how can I change the max_level of subscriber after it was initialised?
let subscriber = tracing_subscriber::fmt().with_max_level(Level::INFO).finish();
tracing::subscriber::set_global_default(subscriber);
debug!("some log message");

You can use reload handler exactly for this. Save remote handler in some global state and call it to change log level. See example under "Reloading a Filtered layer"

Use log4rs instead. It reads configs from a file which you can change on the fly.
I use it in one of my projects, it works like a charm.

Related

How to filter uvm_info messages by type_id?

I need to filter all the uvm_info log messages by the type_id defined in it. For example, if I want to display only the uvm_info messages from a driver or a monitor, how can I effectively do it?
The UVM does not provide a mechanism to do this very easily. You would have to set the verbosity of everything to UVM_NONE from the top-level down, then go back and turn on just the messages from the drivers and monitors.
Finding al the drivers and monitors might also be difficult unless you gave specific component names, like starting with "drv" and "mon". Then you could use uvm_root::find_all("drv*",comps); and set the verbosity of those components in comps back to UVM_FULL.
It might be easier just to take the entire log file and filter the results you want using a (sed/awk/perl/python) script
How about a custom report catcher?
https://verificationacademy.com/verification-methodology-reference/uvm/docs_1.1d/html/files/base/uvm_report_catcher-svh.html
You can put this in your base test or top, then perhaps control this using a plusarg. A rudimentary example is here:
https://edaplayground.com/x/b4Fx
I think I am quite late to answer this question, however some time ago I wrote a program to filter UVM logs: https://github.com/Loneknight73/uvmlogfilter .
You can filter on, e.g., severity, id, time, component hierarchy and the message text.
That should help anyone who needs to filter verbose UVM logs.

Logstash Shipper configuration for Jira

I am running Jira and Confluence within my company. I would like the logfiles to be shipped to Kibana.
This is very easy to do but I do not want to rewrite the Grok filters. I cannot imagine that nobody has done this already.
Does anybody have an example of a logstash shipper configuration. Most of the logging like catalina.log is standard.
Please help me with examples
One would think that Java application logs only come in one form, but my experience is that there often are subtle differences. Sometimes the thread name is in square brackets and sometimes in parentheses, sometimes the thread name goes first and other times after the logger name, and so on. This gets more painful as you attempt to parse more than one type of log.
Instead of messing with various filters to join multiline messages and grok all the fields I strongly favor using the Log4j layout in github.com/logstash/log4j-jsonevent-layout to produce JSON-based logs that Logstash can read directly without any filters. Apart from not having to maintain filters you get all fields from each log event. Since I don't know what your catalina.log looks like I can't say what you'd be missing by parsing its contents instead of using the JSON layout.
The drawback is that it's a bit more work deployment-wise. You obviously have to deploy the layout jar file itself, but it has a couple of dependencies of its own (net.minidev:jsonsmart and commons-lang:commons-lang) that you need to make available too.

log4net configuration: Can I refer to the same layout in several appenders?

I want to send log messages to several files (i.e. different appenders) based upon some property of the message.
The problem is that each appender needs to specify quite a verbose layout (that contains a compication conversionPattern and a couple of converters). I have ended up duplicating this configuration in each appender. This works but is not ideal as it makes the config much longer than I would like as well as the pain of having to update 3 complicated bit of configuration when the layout changes.
I want to be able to define the layout once and have all my appenders refer back to that one definition (in the same way that several loggers can refer to the same appender). But perhaps there is a better way to achieve my goal of reducing duplication in the configuration?
My google-foo is weak and I could not find an answer. Can anyone here help?
TIA.
I am sorry but unless you are ready to code your own Layout class there is currently no way to skip on the copy-pasted configuration.
You can inherit from the LayoutSkeleton to get started, and either build your layout in code or use an alternate configuration file (I don't think that log4net would be kind to a dangling layout configuration in its config file)

Android Studio Log

Is it possible to view just the log output generated by my application. I know I can use Log.i etc. but that only applies to items specifically logged. Often during an exception, I struggle just to read the text as the logs keep filling up with system events
If you only want to filter on your application's specific log events, simply enter the package name of your app into the filter (the search box) for the LogCat. Additionally, change the log level to Error (to avoid seeing informative messages).

Using log4net to create logfiles that can be viewed with SvcTraceViewer.exe

What is the best way to log to a file using log4net that has the correct format (correct XML, correct timestamp format, custom data in correct format, correct attributes, basically the exact same way as XmlWriterTraceListener does it) so it can be viewed in the Service Trace Viewer Tool (SvcTraceViewer.exe)?
If I wanted to this then I would write my custom layout. I did not (yet) look at the details but I would write a class that derives from XmlLayoutBase. I need some more time to look at the details...
You could also write your own appender but I think in this case it makes more sense to write a layout class.
Edit: Maybe writing your own appender is a good idea. In that case you could use the System.ServiceModel.Diagnostics.DiagnosticTrace class. Not sure yet though if that is the way to go. I do not have much time right now, but I will look into this.
Not an answer, but I asked a question earlier today about logging and WCF and one of the things I wanted to know was about Service Trace Viewer. All of the examples that I have seen describe the XML files consumed by Service Trace Viewer being generated via System.Diagnostics TraceSources and the System.Diagnostics XmlFileListener. Anyway, if I get any answers in my post you might find them useful.
Here is an idea:
You could write a custom log4net Appender and have it write messages (indirectly) to the XmlWriterTraceListener. Inside the Append method you simply send the message to System.Diagnostics.
Here is one example of a custom Appender.
In the example, Append is overridden. It is passed a LoggingEvent class/structure. For your purposes (to get the log4net output routed to an output format that can be read by SvcTraceViewer), you could write your output to System.Diagnostics (having first configured it to log to the XmlWriterTraceListener). You could either write using Trace.Write* methods, Trace.Trace* methods, or by TraceSources.
For TraceSources, you could consider the TraceSource name to be the same as the logger name (which is available in the LoggingEvent class/structure). So, you could configure a TraceSource in your app.config file for each log4net logger name that you want to go into the xml file. Your Append logic then might look something like this:
protected override void Append(LoggingEvent le)
{
TraceSource ts = new TraceSource(le.LoggerName); // Not sure of logger name field in LoggingEvent
ts.TraceEvent(LogLevelToTraceEventType(le.Level), 0, le.FormattedMessage);
}
This might give you what you want. Note that I have not actually done this, so I cannot say if it is a good idea or not, but it certainly seems like it would work.
Sorry for being brief, but am trying to finish this before have to leave.

Resources