You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Dave Howes (JIRA)" <ji...@apache.org> on 2016/08/11 08:49:20 UTC

[jira] [Commented] (LOG4J2-1509) Log4j2 JSONLayout is not parseable on OSX

    [ https://issues.apache.org/jira/browse/LOG4J2-1509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15416895#comment-15416895 ] 

Dave Howes commented on LOG4J2-1509:
------------------------------------

Could this code in AbstractJacksonLayout be the culprit? 

{code}
abstract class AbstractJacksonLayout extends AbstractStringLayout {

    protected static final String DEFAULT_EOL = "\r\n";
    protected static final String COMPACT_EOL = Strings.EMPTY;
{code}

perhaps DEFAULT_EOL should be set to System.getProperty("line.separator"); ?

> Log4j2 JSONLayout is not parseable on OSX
> -----------------------------------------
>
>                 Key: LOG4J2-1509
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1509
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Layouts
>    Affects Versions: 2.6.2
>         Environment: Darwin DaveH.local 15.4.0 Darwin Kernel Version 15.4.0: Fri Feb 26 22:08:05 PST 2016; root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64
> Java version "1.8.0_51"
> Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
> Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
>            Reporter: Dave Howes
>            Priority: Minor
>
> When I use the JSONLayout with 'complete=true' to write to a file, the resulting file cannot be parsed by either json.simple or Gson
> Two things appear out of the ordinary to me
> 1) the terminating "]" always has a blank line inserted before it in to the file.
> 2) Windows style CR-LF seem to be being used for the line separators.
> The JSON is written to the file is as follows :
> {panel}
> [^M
> {
>   "timeMillis" : 1470831244334,
>   "thread" : "main",
>   "level" : "DEBUG",
>   "loggerName" : "daveLoggingCalculatorService",
>   "message" : "LoggingCalculatorService Entering add ",
>   "endOfBatch" : false,
>   "loggerFqcn" : "org.apache.logging.slf4j.Log4jLogger",
>   "contextMap" : {
>     "id" : "5ca2d4d5-756b-4a79-80d2-dba255fa4536",
>     "loginId" : "Paul Kossoff"
>   },
>   "threadId" : 1,
>   "threadPriority" : 5
> }^M
> , {
>   "timeMillis" : 1470831244406,
>   "thread" : "main",
>   "level" : "DEBUG",
>   "loggerName" : "dave.LoggingCalculatorService",
>   "message" : "LoggingCalculatorService Exiting add",
>   "endOfBatch" : false,
>   "loggerFqcn" : "org.apache.logging.slf4j.Log4jLogger",
>   "contextMap" : {
>     "id" : "5ca2d4d5-756b-4a79-80d2-dba255fa4536",
>     "loginId" : "Paul Kossoff"
>   },
>   "threadId" : 1,
>   "threadPriority" : 5
> }^M
> ^M
> ]^M
> {panel}
> Both parsers fail at the line immediately preceding the terminating "]" - at first sight it would appear that a line with only a ^M on it is identified as being the end of stream when reading using a java.io.BufferedReader.
> The following code produces the following stacktrace:
> {code}
> List<LinkedTreeMap> logContent = (List<LinkedTreeMap>)gson.fromJson(new FileReader(LOG_FILE_NAME), Object.class);
> {code}
> {panel}
> com.google.gson.JsonSyntaxException: java.io.EOFException: End of input at line 32 column 1
> 	at com.google.gson.Gson.fromJson(Gson.java:813)
> 	at com.google.gson.Gson.fromJson(Gson.java:741)
> 	at .....
> {panel}
> If I manually remove the ^M from the file, but leave the empty line, the file can be parsed correctly.
> I'm not sure if this is a problem in the JSON parsers, the log4j2 JSONAppender, or my ability to process files correctly in java .
> log4j2.yaml
> {panel}
> Configuration:
>   status: warn
>   Appenders:
>     Console:
>       name: Console
>       target: SYSTEM_OUT
>       JSONLayout:
>         Properties: true
>         Complete: true
>         Charset: ISO-8859-1
>     File:
>       name: File
>       fileName: "test.log"
>       JSONLayout:
>         Properties: true
>         Complete: true
>         Charset: ISO-8859-1
>        
>   Loggers:
>     Root:
>       level: debug
>       AppenderRef:
>         - ref: Console
>         - ref: File 
> {panel}
> pom.xml ( dependencies section )
> {panel}
> 	<properties>
> 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
> 			<slf4j.version>1.7.6</slf4j.version>
> 	  		<log4j.version>2.6.2</log4j.version> 
> 	</properties>
> 	<dependencies>
> 		<dependency>
> 			<groupId>junit</groupId>
> 			<artifactId>junit</artifactId>
> 			<version>4.12</version>
> 			<scope>test</scope>
> 		</dependency>
> 		<dependency>
> 			<groupId>org.aspectj</groupId>
> 			<artifactId>aspectjrt</artifactId>
> 			<version>1.8.7</version>
> 		</dependency>
> 		<dependency>
> 			<groupId>org.mockito</groupId>
> 			<artifactId>mockito-all</artifactId>
> 			<version>1.10.19</version>
> 		</dependency>
> 		<dependency>
> 			<groupId>com.google.code.gson</groupId>
> 			<artifactId>gson</artifactId>
> 			<version>2.2.4</version>
> 		</dependency>
> 		
> 		
>   <dependency>
>     <groupId>org.slf4j</groupId>
>     <artifactId>slf4j-api</artifactId>
>     <version>${slf4j.version}</version>
>   </dependency>
>   <!-- Binding for Log4J -->
>   <dependency>
>     <groupId>org.apache.logging.log4j</groupId>
>     <artifactId>log4j-slf4j-impl</artifactId>
>     <version>${log4j.version}</version>
>   </dependency>
>   <!-- Log4j API and Core implementation required for binding -->
>   <dependency>
>     <groupId>org.apache.logging.log4j</groupId>
>     <artifactId>log4j-api</artifactId>
>     <version>${log4j.version}</version>
>   </dependency>
>   <dependency>
>     <groupId>org.apache.logging.log4j</groupId>
>     <artifactId>log4j-core</artifactId>
>     <version>${log4j.version}</version>
>   </dependency>		
> <dependency>
>     <groupId>com.fasterxml.jackson.core</groupId>
>     <artifactId>jackson-core</artifactId>
>     <version>2.8.1</version>
> </dependency>		
> <dependency>
>     <groupId>com.fasterxml.jackson.core</groupId>
>     <artifactId>jackson-databind</artifactId>
>     <version>2.8.1</version>
> </dependency>
> <dependency>
>     <groupId>com.fasterxml.jackson.dataformat</groupId>
>     <artifactId>jackson-dataformat-yaml</artifactId>
>     <version>2.5.0</version>
> </dependency>		
> 		
> 		<dependency>
> 			<groupId>org.powermock</groupId>
> 			<artifactId>powermock-core</artifactId>
> 			<version>1.6.5</version>
> 		</dependency>
> 		<dependency>
> 			<groupId>org.powermock</groupId>
> 			<artifactId>powermock-api-mockito</artifactId>
> 			<version>1.6.5</version>
> 		</dependency>
> 		<dependency>
> 			<groupId>org.powermock</groupId>
> 			<artifactId>powermock-module-junit4</artifactId>
> 			<version>1.6.5</version>
> 		</dependency>
> 	</dependencies>
> {panel}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org