I try to set the Logger Level with the VM Options in Intellij, but it doesn't work.
According to the documentation Docu, I tried the following:
-Dlog4j2.level=DEBUG
But it has no effect!
But when I try to load a different log4j2.xml file the property -Dlog4j.configuration={path to file} works.
Why are the property for the log level ignored?
Related
Is it possible to add a custom variable to the internalLogFile attribute in the nlog.config file, like ProjectName in internalLogFile="c:\logs\${gdc:ProjectName}\internal-nlog.txt"?
I tried this:
<nlog internalLogFile="c:\logs\${gdc:ProjectName}\internal-nlog.txt">
...
</nlog>
and
private static void ConfigureLogging(IServiceCollection services)
{
GlobalDiagnosticsContext.Set("ProjectName", "some-project-name");
LogManager.LoadConfiguration("nlog.config");
services.AddLogging(loggingBuilder =>
{
loggingBuilder.AddConfiguration(Config.GetSection("Logging"));
loggingBuilder.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Debug);
loggingBuilder.AddNLog();
});
}
But LoadConfiguration throws an error (caught as first-chance exception in VS, so it's actually silently ignored):
System.IO.IOException: The directory name is invalid. : 'c:\logs\${gdc:ServiceRunnerFolder}'
I stepped through NLog code and it seems it only calls ExpandFilePathVariables to expand some known environment variables before setting the filename.
Is there a way to use a custom variable for this filename, without creating environment variables?
Never mind, I found the docs, it seems it's not possible as of NLog 5:
When you configure NLog using Configuration File, you can enable
internal logging by setting the following attribute on the
element:
internalLogFile="file.txt" - adding
internalLogFile cause NLog to write its internal debugging messages to
the specified file. This includes any exceptions that may be thrown
during logging.
Note: only a few layouts are supported, as the
internal log needs to be as stable as possible.
NLog 4.6+: Environment
Variables are also supported: e.g. %appdata% or %HOME%
NLog 4.6+:
Supports renderers (without options): ${currentdir}, ${basedir},
${tempdir}
NLog 4.7.1+: Supports renderer (without options):
${processdir}
NLog 5.0+: Supports renderers (without options):
${commonApplicationDataDir}, ${userApplicationDataDir},
${userLocalApplicationDataDir}
Instead of using ${gdc} and GlobalDiagnosticsContext.Set("ProjectName", "some-project-name"); then just update the InternalLogger directly:
var projectName = "some-project-name";
NLog.Common.InternalLogger.LogFile = $"c:\logs\{some-project-name}\internal-nlog.txt";
See also: https://github.com/NLog/NLog/wiki/Internal-Logging#example-with-internal-logging-from-code
I have a Spring Boot properties with three properties files:
I have a class that uses values defined in application-local.properties file, which I thought would get used because application-properties has `spring.profiles.active=local
When I start up in IntelliJ, I see this in the console logs:
Loaded config file 'file:.../build/resources/main/application.properties' (classpath:/application.properties)
2016-12-18 20:10:17.596 DEBUG 29999 --- [ restartedMain] o.s.b.c.c.ConfigFileApplicationListener : Loaded config file 'file:.../build/resources/main/application-local.properties' (classpath:/application-local.properties)`
Skipped (empty) config file 'file:...build/resources/main/application-local.properties' (classpath:/application-local.properties) for profile local
It says it skipped the empty config file, but when I inspect 'build/resources/main/application-local.properties' then I see the values in there.
However, the following class does not have the properties when I run it from within IntelliJ as a Spring Boot Application. It throws a null pointer because these are null:
#Value("${myapp.ApiKey}")
private String apiKey;
#Value("${myapp.ApiSecret}")
private String apiSecret;
#Value("${myapp.user}")
private String user;
In the Application Configuration I tried using Active Profiles, Program Arguments, and Environment Variables.
However, if I run from the command line as:
java -jar -Dspring.active.profiles=local build/libs/myjar-0.0.1-SNAPSHOT.jar
then it works just fine. I am sure this was working previously, but not sure if the IntelliJ version was the same. Any tips on how to make the correct version of my application.properties get used?
Which spring boot version are you using? If you're using the latest this should be
-Dspring.profiles.active=local
http://docs.spring.io/spring-boot/docs/current/reference/html/howto-properties-and-configuration.html#howto-set-active-spring-profiles
I have trouble running my functional test from IntelliJ IDE. When I run the functional test, I got the following error message:
java.lang.IllegalStateException: No reports dir has been configured, you need to set in the config file or via the build adapter.
at geb.Browser.getReportGroupDir(Browser.groovy:899)
at geb.Browser.cleanReportGroupDir(Browser.groovy:932)
at geb.spock.GebSpec.methodMissing(GebSpec.groovy:56)
at geb.spock.GebReportingSpec.setupSpec(GebReportingSpec.groovy:37)
Based on my research, all I need to do is to add the following code in GebConfig.groovy:
reportsDir = new File("target/runtime_reports_dir")
I added the line to GebConfig.groovy and rebuild the project, but still running into the same issue. Is there any other fix to this error?
Adding reportsDir = 'target/geb-reports' to your GebConfig shoud fix this, can you show me your GebConfig file?
There is also another fix for it, your test class extends GebReportingSpec, you can chage it to GebSpec and it should also work.
I had this same issue, while having the reportsDir correctly configured in the GebConfig
Adding the resources folder (where my GebConfig is located) as "Test Sources Root" did the trick for me
To mark the folder as "Test Sources Root":
Right click in the folder
Mark Directory as
Test Sources Root
Happy testing!
I am using service Logger (workbench Logger) to log in Eclipse RCP.
I have used it many locations where it is used for logging INFO, WARNING and ERROR as well.
I had set eclipse.log.level = ERROR in the launch configuration (tab) of the product file. Now I expect it to log only ERROR logs in the log file.
But when I am launching from the product file it is logging all the INFO logs also. My understanding is wrong on eclipse.log.level? or anything else has to be done?
Since this is a system property you set it with
-Declipse.log.level=ERROR
in the 'VM arguments' section of the 'Arguments' tab on the launch configuration.
I would like to change the log directory from MULE_HOME/logs to MULE_HOME/logs/apps. The only place I have found that refers to a file path is in MULE_HOME/conf/wrapper.conf. Editing the wrapper.logfile does allow me to relocate the mule_ee.log file, which seems to be the Mule application log, but I'd like to include Mule application logs there, too. If I create an application called FOO and deploy it to the runtime environment, it will create a file called MULE_HOME/logs/mule-app-FOO.log, but changing the location seems to be difficult short of completely messing things up writing custom log4j2 XML files.
If you have Mule version 3.6+, then it is recommended to use log4j2.xml instead of log4j.xml.... Using log4j2 you can change the path and get your application log ... a simple example would be :-
<RollingFile name="RollingFile" fileName="${env:MULE_HOME}/logs/${sys:CustomapplicationName}.log"
filePattern="${env:MULE_HOME}/logs/${sys:CustomapplicationName}-%d{yyyy-MM-dd}-%i.log"> <!-- CustomapplicationName is set at mule-app.properties or in VM argument in Run As Configure as -DCustomapplicationName=Log4j -->
<PatternLayout>
<pattern>%d{dd/MMM/yyyy HH:mm:ss,SSS}- %c{1}: %m%n</pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="120 KB" />
</Policies>
<DefaultRolloverStrategy max="1" />
</RollingFile>
Just put this above code in your log4j2.xml in src/main/resource folder
Here in above you can see that, you have configured your path of your log files by mentioning here:-
<RollingFile name="RollingFile" fileName="${env:MULE_HOME}/logs/apps/${sys:CustomapplicationName}.log"
filePattern="${env:MULE_HOME}/logs/apps/${sys:CustomapplicationName}-%d{yyyy-MM-dd}-%i.log">
where ${sys:CustomapplicationName} is the System variable set in mule-app.properties as following :-
CustomapplicationName=yourApplicationName
Right way is to have log4j properties / xml file for FOO application and have that define the desired path for FOO application log. This way will ensure mule_ee.log is not messed up and at the same time other applications too will have their own log files which will be easy to manage and easy to introspect specific application log in case of errors / exceptions
Define location in log4j.properties file.