Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id D611D20049C for ; Fri, 11 Aug 2017 21:39:13 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id D46C616DE00; Fri, 11 Aug 2017 19:39:13 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 2621316DDF6 for ; Fri, 11 Aug 2017 21:39:12 +0200 (CEST) Received: (qmail 51079 invoked by uid 500); 11 Aug 2017 19:39:12 -0000 Mailing-List: contact log4j-user-help@logging.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Log4J Users List" Reply-To: "Log4J Users List" Delivered-To: mailing list log4j-user@logging.apache.org Received: (qmail 51069 invoked by uid 99); 11 Aug 2017 19:39:12 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Aug 2017 19:39:12 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 771491A1685 for ; Fri, 11 Aug 2017 19:39:11 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.972 X-Spam-Level: X-Spam-Status: No, score=0.972 tagged_above=-999 required=6.31 tests=[SPF_SOFTFAIL=0.972] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id iMsyUc2NCpS0 for ; Fri, 11 Aug 2017 19:39:10 +0000 (UTC) Received: from mail.staldal.nu (109-74-4-102-static.serverhotell.net [109.74.4.102]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id C5D405F2F1 for ; Fri, 11 Aug 2017 19:39:09 +0000 (UTC) Received: from [127.0.0.1] (localhost.localdomain [127.0.0.1]) by mail.staldal.nu (Postfix) with ESMTP id 0B0B481601CA for ; Fri, 11 Aug 2017 21:39:03 +0200 (CEST) Subject: Re: Fwd: Add json object to log4j2 when is JSONLayout To: log4j-user@logging.apache.org References: From: =?UTF-8?Q?Mikael_St=c3=a5ldal?= Organization: Apache Software Foundation Message-ID: <17248834-427d-7fce-aee4-7b61f3ff7ce1@apache.org> Date: Fri, 11 Aug 2017 21:39:02 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit archived-at: Fri, 11 Aug 2017 19:39:14 -0000 Note that if we add such option to JsonLayout, then all log messages passed to that layout need to be well-formed JSON, otherwise the output will not be well-formed JSON. We would make it easy for the user to shoot himself in the foot. I think it would be better to create a new subclass of Message, JsonMessage, and let JsonLayout handle such messages specially and output as a nested JSON structure (instead as a quoted and escaped string as today). However, how do we represent a JSON structure without adding dependency on Jackson or other 3rd party JSON library? Message subcasses are in log4j-api, and we do not want log4j-api to depend on any such library. Or maybe we should put this new JsonMessage in log4j-core? Or maybe put it in a new log4j-json module? Should we also have XmlMessage for XmlLayout? What about YamlLayout? On 2017-08-11 16:56, Gary Gregory wrote: > Hello, > > The JSON layout outputs the log event in JSON, the event message is just a > string in that event, in this case, it is escaped following the JSON rules > to remain a string. > > If you want a JSON object back out of the event message you will have to > parse it out of that string. > > Feel free to provide a PR on GitHub if you want to add an option to allow > for a JSON object as the log message. I am not sure if it would be accepted > though as it is quite different from the current design. > > Thoughts from the community? > > Gary > > > On Aug 11, 2017 07:53, "Jeus Geek" wrote: > > i will show JSON object as a JSON object in log4j2 when is that configed > JSONLayout . > > JSON object: > > {"line_id": 12,"play_name":"Jeus"} > > import org.apache.logging.log4j.LogManager;import > org.apache.logging.log4j.Logger; > public class Main { > > private static final Logger LOGGER = LogManager.getLogger(Main. > class); > > public static void main(String[] args) { > > > String message = "{\"line_id\": 12,\"play_name\": \"Jeus\"}"; > LOGGER.info(message); > > } > } > > output is: > > { > "timeMillis":1502361394238, > "thread":"main", > "level":"INFO", > "loggerName":"com.jeus.logger.json.loggerjson.Main", > "message":"{\"line_id\": 12,\"play_name\": \"Jeus\"}", > "endOfBatch":false, > "loggerFqcn":"org.apache.logging.log4j.spi.AbstractLogger", > "contextMap":[ > > ], > "threadId":1, > "threadPriority":5, > "source":{ > "class":"com.jeus.logger.json.loggerjson.Main", > "method":"main", > "file":"Main.java", > "line":62 > } > } > > but i will show message as a json object same this: > > "message":{"line_id": 12,"play_name":"Jeus"}, > > you can see more detail about my problem in stackOverflow > object-to-log4j2-when-is-jsonlayout?noredirect=1#comment78217774_45611509> > > > thank you for attention > --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org For additional commands, e-mail: log4j-user-help@logging.apache.org