log4j.rootcategory=info doesn't exist - log4j

I need to Edit the log4j.properties file and change the log level from INFO to ERROR on log4j.rootCategory but log4j.rootcategory=info doesn't exist
rootLogger.level = info
rootLogger.appenderRef.stdout.ref = console
appender.console.type = Console
appender.console.name = console
appender.console.target = SYSTEM_ERR
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{yy/MM/dd HH:mm:ss} %p %c{1}: %m%n%ex

Related

Different log levels in different places

I have a bunch of classes in com.example. I want my logfile to capture debug logging and my console to capture info only.
I am using log4j2.
Here is my log4j2.properties file.
name=PropertiesConfig
property.filename = logs
# configure both the appenders
# CONSOLE APPENDER
appender.console.type = console
appender.console.name = consoleAppender
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss.SSS} [%-5level] [%t] %c{1} - %msg%n
# LOGFILE appender
appender.logfile.type = File
appender.logfile.name = logfileAppender
appender.logfile.fileName=extract.log
appender.logfile.layout.type=PatternLayout
appender.logfile.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
logger.example.name = com.example
logger.example.level = debug
logger.example.additivity = true
logger.example.appenderRef.logfile.ref = logfileAppender
logger.example.appenderRef.console.ref = consoleAppender
# configure the loggers, starting from the root logger.
rootLogger.level = info
Which logs to debug at both.
I try this...
name=PropertiesConfig
property.filename = logs
# configure both the appenders
# CONSOLE APPENDER
appender.console.type = console
appender.console.name = consoleAppender
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss.SSS} [%-5level] [%t] %c{1} - %msg%n
# LOGFILE appender
appender.logfile.type = File
appender.logfile.name = logfileAppender
appender.logfile.fileName=extract.log
appender.logfile.layout.type=PatternLayout
appender.logfile.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
logger.example.name = com.example
logger.example.level = debug
logger.example.additivity = true
logger.example.appenderRef.logfile.ref = logfileAppender
logger.info.name = com.example
logger.info.level = info
logger.info.additivity = true
logger.info.appenderRef.console.ref = consoleAppender
# configure the loggers, starting from the root logger.
rootLogger.level = info
But then nothing logs to console.
any ideas?
I also faced with this problem and when I add
rootLogger.appenderRef.console.ref=consoleAppender
rootLogger.appenderRef.rolling.ref=RollingFile
in the end of my log4j2. It's worked. The consoleAppender and RollingFile are the name of the appender.console.name and appender.rolling.name
This is the end of my log4j2 configure:
loggers=console, rolling
logger.console.name=console
logger.console.level=info
logger.console.additivity=false
logger.console.appenderRef.console.ref=consoleAppender
logger.rolling.name=com.viking
logger.rolling.level=info
logger.rolling.additivity=false
logger.rolling.appenderRef.rolling.ref=RollingFile
rootLogger.level=info
rootLogger.additivity=false
rootLogger.appenderRef.console.ref=consoleAppender
rootLogger.appenderRef.rolling.ref=RollingFile

How can I make log4js on cygwin write exactly what I want to file?

I have a node.js project on cygwin, which I test with mocha.
My logger is log4js.
I have an appender to get log4js to write to file, but I don't know how to get it to write it exactly as I want.
Must-haves:
A different file for each time mocha runs (it's OK if mocha clobbers the old log files)
Unix line endings
Nice-to-have:
No color encodings in the file (I can get around this when mocha is run with -C, but ideally there would be something in log4js-config.js.)
How do I do this?
My current setup is as follows.
My log4js-config.js:
var log4js = require('log4js');
var log4js_config = {
"appenders": [{
"type": "console",
"layout": {
"type": "pattern",
"pattern": "%[%d{yyyy-MM-ddThh:mm:ss.SSS} [pid=%x{pid}] %p %c -%] %m",
"tokens": {pid: function(){return process.pid;}}
}
},{
"type": "file",
"filename": "jxg_log.log",
"layout": {
"type": "pattern",
"pattern": "%d{yyyy-MM-ddThh:mm:ss.SSS} [pid=%x{pid}] %p %c - %m",
"tokens": {pid: function(){return process.pid;}}
}
}],
replaceConsole: true
};
log4js.configure(log4js_config, {});
exports.logging = log4js;
My test file is:
var assert = require("assert");
var logger = require('../src/log4js-config').logging.getLogger('Mocha-Test');
describe('Array', function(){
describe('#indexOf()', function(){
it('should return -1 when the value is not present', function(){
logger.debug("logger debug line 1");
assert.equal(-1, [1,2,3].indexOf(5));
assert.equal(-1, [1,2,3].indexOf(0));
logger.debug("logger debug last line");
})
})
})
(For the purposes of this question, there is no code under test. I run mocha with ./node_modules/mocha/bin/mocha.)
The log file that is output is this:
2014-11-24T13:45:00.012 [pid=90652] INFO console - %m
2014-11-24T13:45:00.018 [pid=90652] INFO console - %m
2014-11-24T13:45:00.019 [pid=90652] INFO console - Array
2014-11-24T13:45:00.020 [pid=90652] INFO console - #indexOf()
2014-11-24T13:45:00.021 [pid=90652] DEBUG Mocha-Test - logger debug line 1
2014-11-24T13:45:00.021 [pid=90652] DEBUG Mocha-Test - logger debug last line
2014-11-24T13:45:19.090 [pid=90180] INFO console - %m
2014-11-24T13:45:19.093 [pid=90180] INFO console - %m
2014-11-24T13:45:19.095 [pid=90180] INFO console - Array
2014-11-24T13:45:19.095 [pid=90180] INFO console - #indexOf()
2014-11-24T13:45:19.096 [pid=90180] DEBUG Mocha-Test - logger debug line 1
2014-11-24T13:45:19.096 [pid=90180] DEBUG Mocha-Test - logger debug last line
2014-11-24T13:50:13.716 [pid=88476] INFO console - %m
2014-11-24T13:50:13.720 [pid=88476] INFO console - [0m[0m
2014-11-24T13:50:13.721 [pid=88476] INFO console - [0m Array[0m
2014-11-24T13:50:13.722 [pid=88476] INFO console - [0m #indexOf()[0m
2014-11-24T13:50:13.722 [pid=88476] DEBUG Mocha-Test - logger debug line 1
2014-11-24T13:50:13.723 [pid=88476] DEBUG Mocha-Test - logger debug last line
Note three mocha runs here; the third time, I left out the -C to show the color encoding.
I can't show the line endings directly in the question, but there's this:
$ file jxg_log.log
jxg_log.log: ASCII text, with CRLF line terminators, with escape sequences
So, again: how can I overwrite the log file on subsequent runs, output unix newlines, and suppress the color codes?

How to log to different appenders from one Controller w/Grails & log4j

I have a controller where I would like to log to different appenders based on the level. So for examaple general usage would be written to a INFO usage.log. Certain events I determine should go to a WARN warning.log.
Here's a portion of my log4j config…
appenders {
file name: "usageAppender",
file: " /usr/local/logs/cs-wst/usage.log"
file name: "warningAppender",
file: " /usr/local/logs/cs-wst/warning.log"
}
info usageAppender: 'grails.app'
When I do this and run a statement like this in my controller log.info("request method fired") the line does show up in usage.log, but I'm having trouble getting other levels to work. I would like to run these two statements in the controller
log.info("request method fired")
…
log.warn("invalid credentials")
And have them logged to the appropriate file. Can anyone help?
Reference the code below;
appenders {
appender new DailyRollingFileAppender(
name: 'dailyerrorAppender',
threshold: org.apache.log4j.Level.DEBUG,
datePattern: "'.'yyyy-MM-dd", // See the API for all patterns.
fileName: "./error",
layout: pattern(conversionPattern:'%d [%t] %-5p %c{2} %x - %m%n')
)
appender new DailyRollingFileAppender(
name: 'dailywarnAppender',
threshold: org.apache.log4j.Level.WARN,
datePattern: "'.'yyyy-MM-dd", // See the API for all patterns.
fileName: "./warn",
layout: pattern(conversionPattern:'%d [%t] %-5p %c{2} %x - %m%n')
)
}
environments {
development{
debug dailyerrorAppender:"errors", additivity: false
warn dailywarnAppender:"warns", additivity: false
}
qa{
debug dailyerrorAppender:"errors", additivity: false
warn dailywarnAppender:"warns", additivity: false
}
production{
debug dailyerrorAppender:"errors", additivity: false
warn dailywarnAppender:"warns", additivity: false
}
}
def errorLog = Logger.getLogger("errors")
errorLog.debug("your error messages")
def warnLog = Logger.getLogger("warns")
warnLog.warn("your warn messages")

Log4j Logs are not coming in the pattern I have specified in log4j.properties

I am trying to log messages to console using Log4j.
I have a class like below
public class Demo {
private static Employee employee=null;
private static Logger logger=Logger.getRootLogger();
public static void main(String[] args) {
PropertyConfigurator.configure("log4j.properties");
if(employee!=null){
System.out.println(employee);
}else{
logger.warn("Employee object is null in Demo class main method in if(){} statement");
}
}
}
I have log4j.properties file in the Project folder. If I keep log4j.properties file in classpath I am getting file not found exception , so I kept it in Project folder.My project in eclipse is like below
log4j.properties file is as below
log4j.rootLogger=DEBUG, lntLogger
log4j.appender.lntLogger=org.apache.log4j.ConsoleAppender
log4j.appender.lntLogger.layout=org.apache.log4j.PatternLayout
log4j.appender.CA.layout.ConversionPattern=%-4r [%t] %-5p %c - %m --date %d{dd MMM yyyy} %n
Now I am expecting output in the format %-4r [%t] %-5p %c - %m --date %d{dd MMM yyyy} %n
But I am getting Only my message in the console like
Employee object is null in Demo class main method in if(){} statement
Now my question is why my log is not coming in the format what I have specified in properties file.
In log4j.properties file change 4th line to
log4j.appender.lntLogger.layout.ConversionPattern=%-4r [%t] %-5p %c - %m --date %d{dd MMM yyyy} %n

log4j.xml show com.foo, but hide com.foo.bar

I have the following log4j.xml configuration:
<log4j:configuration>
<appender name = "CONSOLE" class = "org.apache.log4j.ConsoleAppender">
<param name = "Target" value = "System.out"/>
<param name = "Threshold" value = "DEBUG"/>
</appender>
<category name = "com.foo">
<appender-ref ref = "CONSOLE"/>
</category>
</log4j:configuration>
This displays every log in com.foo.* . I want to disable logging in com.foo.bar.* . How do i do this.
By raising the threhold on the com.foo.bar logger:
<category name = "com.foo.bar">
<priority value="WARN"/>
</category>
This logger will be used in preference to the com.foo one, and has a higher threshold will only lets through WARN or higher.

Resources