How to log using log4j to local file system inside a Spark application that runs on YARN?

It looks like you’ll need to append to the JVM arguments used when launching your tasks/jobs. Try editing conf/spark-defaults.conf as described here spark.executor.extraJavaOptions=-Dlog4j.configuration=file:/apps/spark-1.2.0/conf/log4j.properties spark.driver.extraJavaOptions=-Dlog4j.configuration=file:/apps/spark-1.2.0/conf/log4j.properties Alternatively try editing conf/spark-env.sh as described here to add the same JVM argument, although the entries in conf/spark-defaults.conf should work. If you are still not getting any joy, you can explicitly … Read more

Configure logging for the MongoDB Java driver

You need to set a couple of system properties before loading any of the MongoDB Java driver classes: // Enable MongoDB logging in general System.setProperty(“DEBUG.MONGO”, “true”); // Enable DB operation tracing System.setProperty(“DB.TRACE”, “true”); After doing that the driver will use the standard Java logging framework to log messages. Unfortunately, as far as I can tell … Read more

Log4j formatting: Is it possible to truncate stacktraces?

You can use a EnhancedPatternLayout in log4j to format your stacktraces. See http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/EnhancedPatternLayout.html, specifically the section about the “throwable” pattern in the pattern table. Note that support for the %throwable{n} support is rather new and requires at least log4j 1.2.16 (which is the latest at time of writing) For tracking purposes, this is the ticket … Read more

catalina.out rolling with Tomcat 6.0

Fixed it, turns out the standard logging configuration defines a file logger and also a console logger. The file logger goes to the daily catalina log, and the console logger writes to catalina.out. Fix was to change in conf/logging.properties: .handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler to .handlers = 1catalina.org.apache.juli.FileHandler That stops anything getting written to catalina.out

Can I get parameter names/values procedurally from the currently executing function?

I realize people linked to other questions which mentioned PostSharp, but I couldn’t help posting the code that solved my problem (using PostSharp) so other people could benefit from it. class Program { static void Main(string[] args) { Trace.Listeners.Add(new TextWriterTraceListener(Console.Out)); new MyClass().MyMethod(44, “asdf qwer 1234”, 3.14f, true); Console.ReadKey(); } } public class MyClass { public … Read more

Log4j config – different logs to different files

Log4J makes a distinction between loggers, which are responsible for generating log messages, and appenders, which are responsible for sending those messages somewhere (a file, the console, a database, etc.). Loggers form a hierarchy, the root logger is the parent of the logger named admin, which is the parent of admin.component1, etc., and you can … Read more

Naming Python loggers

I typically don’t use or find a need for class-level loggers, but I keep my modules at a few classes at most. A simple: import logging LOG = logging.getLogger(__name__) At the top of the module and subsequent: LOG.info(‘Spam and eggs are tasty!’) from anywhere in the file typically gets me to where I want to … Read more

Spring Boot, logback and logging.config property

I found a solution and I understood why Spring doesn’t use my logging.config property defined in the application.properties file. Solution and explanation When initializing logging, Spring Boot only looks in classpath or environment variables. The solution I used was to include a parent logback.xml file that included the right logging config file according to the … Read more