I want to limit the length of the *inferior-ensime-server-...* buffer to a few thousand lines.
This looks promising, from https://stackoverflow.com/a/11255400/1007926, but does not work in this case:
(add-hook 'compilation-filter-hook 'comint-truncate-buffer)
(setq comint-buffer-maximum-size 2000)
Is there an ENSIME server buffer hook that I can use in place of 'compilation-filter-hook?
Maybe these hooks can be used to truncate the buffer occasionally:
https://github.com/ensime/ensime-emacs/blob/master/ensime-mode.el
you can always supply your own logback.xml file by customising ensime-server-logback and then doing your own filtering.
https://github.com/ensime/ensime-emacs/blob/aafff027f40ea58e22538272edd0a5b676821978/ensime-vars.el#L85
It worked for me, I did a M-x customize-group ensime-server and then, in ensime-server-logback I had to set the path to the logback.xml as a string: "/home/user/.sbt/0.13/plugins/logback.xml". This is my logback:
<configuration>
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
<resetJUL>true</resetJUL>
</contextListener>
<appender name="file" class="ch.qos.logback.core.FileAppender">
<file>it.log</file>
<append>false</append>
<encoder>
<pattern>%d{HH:mm:ss.SSS} %-5level %X{akkaSource} %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="WARN">
<appender-ref ref="file" />
</root>
<logger name="org.ensime" level="WARN" />
<logger name="akka" level="WARN" />
</configuration>
Related
I am using logback.xml for logging. I want to disable the logs from 3rd party jars/SDKs. For this I used the log level="OFF" for that jar, but still the logs are getting logged. Next I tried using the same log level for one of my files in codebase, I was able to disable the logs for my file.
Below is my logback config :
'''
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern> Some pattern </pattern>
</encoder>
</appender>
<logger name="<sdk file path>" level="OFF"/> !--- This doesn't work ---!
<logger name="<file from my codebase>" level="OFF"/> !--- This works ---!
<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
'''
A library can use any name it likes for a logger so the name will not necessarily match the path of the library.
The %logger field in the pattern gives the name of the logger so you will see the actual name in the logging output. If you see output that you want to suppress, use the name from the log (or a prefix) in the logger element.
I would also recommend setting the root to the lowest level and then increasing the level for the specific libraries that you are interested in.
<logger name="myloggername" level="DEBUG"/>
<root level="ERROR">
<appender-ref ref="STDOUT"/>
</root>
I have the following log4net config
<?xml version="1.0" encoding="utf-8" ?>
<log4net xmlns="urn:log4net">
<appender name ="RollingFile" type="log4net.Appender.RollingFileAppender">
<file value="C:\temp\Generator.log" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maximumFileSize value="500KB" />
<maxSizeRollBackups value="10" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date{DATE} %level %thread %logger - %message%newline" />
</layout>
</appender>
<appender name ="GenerationErrors" type="log4net.Appender.FileAppender">
<file type="log4net.Util.PatternString" value="c:\temp\GenerationErrors.log" />
<appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date{DATE} %level %thread %logger - %message%newline" />
</layout>
</appender>
<root>
<appender-ref ref="RollingFile" />
<level value="INFO" />
</root>
<logger name ="GPA.Module.Generate">
<level value="INFO" />
<appender-ref ref="GenerationErrors" />
</logger>
<logger name="PmuManagement">
<level value="INFO" />
<appender-ref ref="GenerationErrors" />
</logger>
</log4net>
The first appender logs all errors for all of my processes and the second only logs a certain group of errors, as required.
I need to be able to delete the contents of the second log file on the fly however this isn't currently possible as the programme needs constant access to it to run (if you try and make any changes you get the "this file is in use by another programme" error.
Is there a way for log4net to only need access to the file when errors need to be written to it?
Or is there a more generic way to stop services/programmes needing access to file temporarily and allowing access again shortly after?
Thanks
I found this question here Intermittent log4net RollingFileAppender locked file issue and the answer is what I needed. I simply added <lockingModel type="log4net.Appender.FileAppender+MinimalLock" /> to my second appender.
I'm new to logback and I'm trying to stop a SiftingAppender programmatically.
Here is my appender:
<appender name="FILE-APPENDER" class="ch.qos.logback.classic.sift.SiftingAppender">
<!-- MDC value -->
<discriminator>
<key>fileName</key>
<defaultValue>log_file</defaultValue>
</discriminator>
<sift>
<appender name="ROLLING-FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<append>true</append>
<file>{fileName}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- daily rollover. Make sure the path matches the one in the file element or else
the rollover logs are placed in the working directory. -->
<fileNamePattern>${fileName}-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxFileSize>1MB</maxFileSize>
<maxHistory>30</maxHistory>
<totalSizeCap>1GB</totalSizeCap>
</rollingPolicy>
<encoder>
<charset>UTF-8</charset>
<pattern>[%p] [%d{yy/MM/dd HH:mm:ss}] %c [%X{akkaSource}] : %msg%n</pattern>
</encoder>
</appender>
</sift>
</appender>
Root Logger:
<root level="INFO">
<appender-ref ref="FILE-APPENDER"/>
<appender-ref ref="ANOTHER-APPENDER"/>
</root>
At some point in the application I need to stop logging to file, here is my scala code:
val context: LoggerContext = LoggerFactory.getILoggerFactory.asInstanceOf[LoggerContext]
val root = LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME).asInstanceOf[Logger]
root.getAppender("FILE-APPENDER").stop()
The code gets executed with no problem, but I still can see logs in the file.
If I don't use SiftingAppender and instead use only RollingFileAppender it works perfectly.
Is there anything that I'm missing here?
I am using log4j2 to log to the console and file as in this xml file
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%highlight{%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - Line %L: %msg%n}"/>
</Console>
<File name="MyFile" fileName="all.log" immediateFlush="true" append="false">
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - Line %L: %msg%n"/>
</File>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="Console" level="error"/>
<AppenderRef ref="MyFile" level="info"/>
</Root>
</Loggers>
</Configuration>
The problem is only the first line in the netbeans console appears in red while the remaining lines are black as in the following picture.
Any help will be appreciated
Update:I tried the project with eclipse and all lines appeared in black
I have some problems using Logback with my Akka (2.3.9) application. In order to log to stdout and in the logfile, I specified the logback.xml with all appenders:
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="5 seconds" debug="true">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<target>System.out</target>
<encoder>
<pattern>%X{akkaTimestamp} %-5level %logger{36} %X{sourceThread} - %msg%n</pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>./akka.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>./akka.log.%d{yyyy-MM-dd-HH}</fileNamePattern>
</rollingPolicy>
<encoder>
<pattern>%X{akkaTimestamp} %-5level %logger{36} %X{sourceThread} - %msg%n</pattern>
</encoder>
</appender>
<logger name="proc" level="INFO">
<appender-ref ref="FILE"/>
<appender-ref ref="STDOUT"/>
</logger>
<logger name="akka.actor" level="INFO">
<appender-ref ref="FILE"/>
<appender-ref ref="STDOUT"/>
</logger>
<root level="INFO">
<appender-ref ref="FILE"/>
<appender-ref ref="STDOUT"/>
</root>
</configuration>
After that I use logging in my Actor:
val log = Logging(context.system, classOf[MyActor])
override def receive: Receive = {
case MyEvent(event) =>
log.info("Message received for processing.")
}
The problem is, in SBT everything is fine: I can see all log events in the created logfile.
When I make JAR-File with sbt-assembly and start this jar file (java -jar event-assembly-0.1.1-SNAPSHOT.jar). The app writes log entries to STDOUT but not in the file!
I have no idea how I can fix that. I tried with "lsof", the java process has no open log-files.
I don't know what's wrong but you could do the following:
Check if your logback.xml is in the jar-file
Try to start your application with java -Dlogback.configurationFile=/path/to/logback.xml -jar event-assembly-0.1.1-SNAPSHOT.jar
So, how I found out, the sbt-assembly removed some logback-binaries from the result jar (it was settings in my Build.scala). After I changed the MergingStrategy to preserve the first logback occurrence in the result build, all works correctly.