Return-Path: X-Original-To: apmail-logging-log4j-user-archive@www.apache.org Delivered-To: apmail-logging-log4j-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1B47E18824 for ; Wed, 26 Aug 2015 20:31:04 +0000 (UTC) Received: (qmail 90831 invoked by uid 500); 26 Aug 2015 20:31:03 -0000 Delivered-To: apmail-logging-log4j-user-archive@logging.apache.org Received: (qmail 90780 invoked by uid 500); 26 Aug 2015 20:31:03 -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 90769 invoked by uid 99); 26 Aug 2015 20:31:03 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 26 Aug 2015 20:31:03 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 4B5B2181AFF for ; Wed, 26 Aug 2015 20:31:03 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.9 X-Spam-Level: ** X-Spam-Status: No, score=2.9 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=3, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id bA84qqMAy4ml for ; Wed, 26 Aug 2015 20:30:50 +0000 (UTC) Received: from mail-la0-f68.google.com (mail-la0-f68.google.com [209.85.215.68]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with ESMTPS id 48118506F4 for ; Wed, 26 Aug 2015 20:30:50 +0000 (UTC) Received: by labqb2 with SMTP id qb2so4745324lab.1 for ; Wed, 26 Aug 2015 13:30:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=BoseQIkrThXgsQ2NLuF7EeDV22ZXv3fVFwqOBG2mQ8s=; b=0PzgL/7kSpqO0QbC06qUb1y1orNDVoIeYTrcDaMsISnCH7ymBlMJt+onsIxdtrXeXB RBpz0zimjg4YYKeB9tThwJjzD9T2UXa/O0rzPzv2gp8x8MejK0rBBeoDlQXKBfUm6irU TrVR/dq+kY6SpD/baWwUTwTe72RyTu1MGoBuPPfAViMuLUsUmq5xKjr2XUZcHsNkzv87 3t5FGQB0jqnLm5w+Kyd+Qcdo05xy3UWsKPtdbrrOl1AA5qu8O1AwQtECgPTKN8IU/IFW KFngy0bbu8wGabL3NBERxnDvOt8ki3CKnviQIlouP/ICtZUSuc0HIKt4pCeFyLRleYtY 4gzg== MIME-Version: 1.0 X-Received: by 10.112.189.161 with SMTP id gj1mr623677lbc.20.1440621042637; Wed, 26 Aug 2015 13:30:42 -0700 (PDT) Received: by 10.112.126.66 with HTTP; Wed, 26 Aug 2015 13:30:42 -0700 (PDT) In-Reply-To: References: Date: Wed, 26 Aug 2015 13:30:42 -0700 Message-ID: Subject: Re: custom levels via configuration From: Gary Gregory To: Log4J Users List Content-Type: multipart/alternative; boundary=001a11c36e4a80a2f2051e3cb9a0 --001a11c36e4a80a2f2051e3cb9a0 Content-Type: text/plain; charset=UTF-8 Start reading here: - Main site: https://logging.apache.org/log4j/2.x/ - Source code: https://logging.apache.org/log4j/2.x/source-repository.html - This ML Git is the source control system we use. Git master refers to the main branch of development with Git. Gary On Wed, Aug 26, 2015 at 12:54 PM, Nicholas Duane wrote: > Yes I am a true noob to java and linux and log4j. > > What is gitmaster? I assume related to github somehow? How can I see the > test you created? Is there a link you can provide? > > Thanks, > Nick > > > Date: Wed, 26 Aug 2015 12:34:45 -0700 > > Subject: Re: custom levels via configuration > > From: garydgregory@gmail.com > > To: log4j-user@logging.apache.org > > > > On Wed, Aug 26, 2015 at 11:46 AM, Gary Gregory > > wrote: > > > > > This: > > > > > > > > > > > > is only going to match: > > > > > > static Logger log = LogManager.getLogger(HelloWorld.class.getName()); > > > > > > if the class in unpackaged, which it looks it is based on this paste > but I > > > want to double check that you did not omit anything from the example. > > > > > > Are you using the latest version (2.3)?. > > > > > > I just added this test the other day to Git master: > > > > > > org.apache.logging.log4j.core.CustomLevelsTest > > > > > > And it shows that we can configure custom levels from a file and see > them > > > in code. > > > > > > So I am puzzled here. > > > > > > You could try the latest from Git master as well but I do not recall > any > > > fixes in this area. > > > > > > I wonder if the Appenders are processed by the configuration _before_ > the > > > custom levels... > > > > > > > My above suspicion was unfounded, see my new > > test org.apache.logging.log4j.core.CustomLevelsWithFiltersTest and feel > > free to provide a patch to test your desired behavior. This might be a > tall > > order if you are a true Java newbie ;-) > > > > Gary > > > > > > > > Gary > > > > > > > > > On Wed, Aug 26, 2015 at 11:19 AM, Nicholas Duane > wrote: > > > > > >> > > >> > > >> > > >> On to my next problem. I'm trying to define a custom level in > > >> configuration. Not sure if it's working or not. However, when I > attempt > > >> to get the level for that custom level I get back null, which I wasn't > > >> expecting. Here is the log4j2.xml config file: > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> %d %p %c{1.} [%t] %m%n > > >> > > >> > > >> onMismatch="NEUTRAL"/> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> Here is my code: > > >> > > >> import org.apache.logging.log4j.LogManager; > > >> import org.apache.logging.log4j.Logger; > > >> import org.apache.logging.log4j.Level; > > >> > > >> public class HelloWorld > > >> { > > >> static Logger log = > LogManager.getLogger(HelloWorld.class.getName()); > > >> > > >> public static void main(String[] args) > > >> { > > >> System.out.println("Hello, World"); > > >> log.info("hello this is an INFO message"); > > >> log.warn("hello this is a WARN message"); > > >> log.debug("hello this is a DEBUG message"); > > >> Level level = Level.getLevel("INFOM1"); > > >> if (level == null) > > >> System.out.println("Didn't find level INFOM1"); > > >> else > > >> log.log(level, "hello this is an INFOM1 message"); > > >> level = Level.getLevel("INFOP1"); > > >> if (level == null) > > >> System.out.println("Didn't find level INFOP1"); > > >> else > > >> log.log(level, "hello this is an INFOP1 message"); > > >> } > > >> } > > >> > > >> Any ideas? I obviously don't want to use Level.forName() as that will > > >> create the level if it doesn't exist and I want to ensure I'm pulling > the > > >> value from the configuration. > > >> > > >> Thanks, > > >> Nick > > >> > > >> > > > > > > > > > > > > > > > -- > > > E-Mail: garydgregory@gmail.com | ggregory@apache.org > > > Java Persistence with Hibernate, Second Edition > > > > > > JUnit in Action, Second Edition > > > Spring Batch in Action > > > Blog: http://garygregory.wordpress.com > > > Home: http://garygregory.com/ > > > Tweet! http://twitter.com/GaryGregory > > > > > > > > > > > -- > > E-Mail: garydgregory@gmail.com | ggregory@apache.org > > Java Persistence with Hibernate, Second Edition > > > > JUnit in Action, Second Edition > > Spring Batch in Action > > Blog: http://garygregory.wordpress.com > > Home: http://garygregory.com/ > > Tweet! http://twitter.com/GaryGregory > > -- E-Mail: garydgregory@gmail.com | ggregory@apache.org Java Persistence with Hibernate, Second Edition JUnit in Action, Second Edition Spring Batch in Action Blog: http://garygregory.wordpress.com Home: http://garygregory.com/ Tweet! http://twitter.com/GaryGregory --001a11c36e4a80a2f2051e3cb9a0--