I am running a PySpark job using Cloud Dataproc, and want to log info using the logging module of Python. The goal is to then push these logs to Cloud Logging.
From this question, I learned that I can achieve this by adding a logfile to the fluentd configuration, which is located at /etc/google-fluentd/google-fluentd.conf.
However, when I look at the log files in /var/log, I cannot find the files that contain my logs. I've tried using the default python logger and the 'py4j' logger.
logger = logging.getLogger()
logger = logging.getLogger('py4j')
Can anyone shed some light as to which logger I should use, and which file should be added to the fluentd configuration?
Thanks
tl;dr
This is not natively supported now but will be natively supported in a future version of Cloud Dataproc. That said, there is a manual workaround in the interim.
Workaround
First, make sure you are sending the python logs to the correct log4j logger from the spark context. To do this declare your logger as:
import pyspark
sc = pyspark.SparkContext()
logger = sc._jvm.org.apache.log4j.Logger.getLogger(__name__)
The second part involves a workaround that isn't natively supported yet. If you look at the spark properties file under
/etc/spark/conf/log4j.properties
on the master of your cluster, you can see how log4j is configured for spark. Currently it looks like the following:
# Set everything to be logged to the console
log4j.rootCategory=INFO, console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.target=System.err
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c: %m%n
# Settings to quiet third party logs that are too verbose
...
Note that this means log4j logs are sent only to the console. The dataproc agent will pick up this output and return it as the job driver ouput. However in order for fluentd to pick up the output and send it to Google Cloud Logging, you will need log4j to write to a local file. Therefore you will need to modify the log4j properties as follows:
# Set everything to be logged to the console and a file
log4j.rootCategory=INFO, console, file
# Set up console appender.
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.target=System.err
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c: %m%n
# Set up file appender.
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=/var/log/spark/spark-log4j.log
log4j.appender.file.MaxFileSize=512KB
log4j.appender.file.MaxBackupIndex=3
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.conversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c: %m%n
# Settings to quiet third party logs that are too verbose
...
If you set the file to /var/log/spark/spark-log4j.log as shown above, the default fluentd configuration on your Dataproc cluster should pick it up. If you want to set the file to something else you can follow the instructions in this question to get fluentd to pick up that file.
Related
I want to see the INFO level logs that Ignite prints during its running(so that it will help me on what Ignite is doing). I am using the following log4j.properties to make Ignite print INFO level logs,but the logs are not printed out.
Are there special configuration to make Ignite logs printed out?
Thanks.
log4j.rootCategory=INFO, stdout , R
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%p %d - [TS] %c %M(%L) - %m%n
log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.File=c:/ioc.ignite.log
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %d - [TS] %c %M(%L) - %m%n
log4j.logger.org.apache.ignite=INFO
log4j.logger.org.springframework=WARN
Please follow below steps:
e.g. if you are using log4j for logging
configure ignite/config/ignite-log4j.xml in gridLogger of IgniteConfiguration
e.g.
.........
uncomment "CONSOLE" appender in ignite/config/ignite-log4j.xml
copy ignite/libs/optional/ignite-log4j/log4j.jar and ignite/libs/optional/ignite-log4j/ignite-log4j.jar in ignite/libs/ folder
you can also set IGNITE_LOG_HOME environment variable to redirect the logs to any file
You should use <CLASSPATH>/config/ignite-log4j.xml file instead of log4j.properties.
Our view layer are made from JSF 2.1.4,Icefaces 3.3.When we are starting our application we are able to see all the logs in eclipse console is there any way to log all the icefaces logs into a file .
# configure the ice-faces logging
log4j.appender=org.apache.log4j.RollingFileAppender
log4j.appender.File=D:/icefaces.log
log4j.appender.layout=org.apache.log4j.PatternLayout
log4j.appender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} [%p] %c:%L - %m%n
log4j.appender.com.icesoft.faces.application.D2DViewHandler=FINEST
log4j.appender.com.sun.faces.config.ConfigureListener=FINEST
log4j.appender.org.icepush=FINEST
log4j.appender.org.icepush.application.PushRenderer=FINEST
log4j.appender.org.icepush.application.PortableRenderer=FINEST
log4j.appender.org.icefaces=FINEST
I have added the above code in my log4j.properties file, but it is not working I got from here here it is doing console appender, but I want FileAppender. Without specifying anything how it will decide what to log e.g I have configured other logs and it is logging, in the log4j.properties I have mentioned like
log4j.appender.defalut=org.apache.log4j.RollingFileAppender
log4j.appender.defalut.File=D:/xyz.log
log4j.appender.defalut.MaxFileSize=20MB
log4j.appender.defalut.MaxBackupIndex=5
log4j.appender.defalut.layout=org.apache.log4j.PatternLayout
log4j.appender.defalut.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} [%p] %c:%L - %m%n
i am new to log4j and i have the following log4j.properties file in my java application
i am working on this in websphere 6.1
log4j.properties file
log4j.rootLogger=info, console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.package_name=debug
However this is working if i am using only one project as part of my application.If there are multiple projects and i want to use logging facility,logger.isDebugEnabled() always return false.. can anybody suggest a solution for this?
Thanks in advance
Websphere use a classloader for default for each EAR. If you have several Web modules or EJB modules and several files for log4j, only one is loaded by the classloader.
See A Powerful, Easy-to-Use Logging System for configure log4j with several projects in a EAR.
# Set root logger level to INFO and appender to STDOUT.
log4j.rootLogger=INFO, STDOUT
#------------------------------------STDOUT-----------------------------------#
# STDOUT is set to be a ConsoleAppender.
log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
# STDOUT uses PatternLayout.
log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
log4j.appender.STDOUT.layout.ConversionPattern=%d %-5p (%c.java:%L).%M - %m%n
log4j.appender.STDOUT.Encoding=UTF-8
#-----------------------------------------------------------------------------#
# Specify the logging level for loggers from other libraries
log4j.logger.org.apache.commons.beanutils.BeanUtils=DEBUG
log4j.logger.org.apache.struts.action=DEBUG
log4j.logger.org.apache.struts.tiles=DEBUG
log4j.logger.org.apache.struts.util.ModuleUtils=DEBUG
log4j.logger.org.apache.struts.util.RequestUtils=DEBUG
log4j.logger.org.apache.struts.util.PropertyMessageResources=ERROR
log4j.logger.com.ibm._jsp=DEBUG
May you are missing the log4j.logger. prefix for each particular package.
See more of log4j in http://logging.apache.org/log4j/1.2/manual.html
I've just deployed my first app to CloudFoundry, and I use log4j. When I deploy the app to a local tomcat server, the logs print just fine as all is well. But, when I use the "vmc logs " command to get the logs from the instance on CloudFoundry, I only get the tomcat initialization logs and this message:
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Anything further that I've printed with log4j is not visible. System.out.println messages show up, but no log4j messages.
I've placed my log4j.properties file in my WEB-INF directory, and here are its contents:
# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=INFO, A1
# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender
# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-5p %-35c{1} %m%n
log4j.logger.org.springframework=WARN
My logger object is created as would probably be expected in my classes:
private static Logger log = Logger.getLogger(MyClass.class);
Any suggestions as to what configuration I'm missing to have my log4j logs show up in my CloudFoundry logs? Or am I retrieving them incorrectly?
Is Log4j set to output to STDOUT by default? 'vmc logs' will only return the contents of STDOUT, STDERR and the staging log files.
If you app is logging to a different file then use 'vmc file' to view the content.
i have the following log4j.properties file. what i want to do is log everything at the level INFO or above to the console. however, for anything that falls in the demo.* package, i want to log everything at the DEBUG level to a file. my log4j.properties below does not seem to work. what happens is that any DEBUG message from demo.* still gets output to the console. any idea what i am doing wrong?
how can i exclude demo.* from logging to the console?
log4j.rootLogger=INFO, C
log4j.logger.demo=DEBUG, R1
log4j.appender.C=org.apache.log4j.ConsoleAppender
log4j.appender.C.target=System.err
log4j.appender.C.layout=org.apache.log4j.PatternLayout
log4j.appender.C.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{2}: %m%n
log4j.appender.R1=org.apache.log4j.RollingFileAppender
log4j.appender.R1.File=output.log
log4j.appender.R1.MaxFileSize=5MB
log4j.appender.R1.MaxBackupIndex=5
log4j.appender.R1.layout=org.apache.log4j.PatternLayout
log4j.appender.R1.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{2}: %m%n
sorry, never mind. i solved it by setting the threshold of the console appender.
log4j.appender.C.threshold=INFO