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

Ralph Goers commented on LOG4J2-2971:
-------------------------------------

Sorry for taking so long to see your reply. I'm a little confused now at what 
you want. First, I am not sure why the code block you show above didn't work. 
You most certainly can do
{code:java}
private Level logLevel = Level.ERROR;{code}
If you want to assign a value to logLevel based on the value of the --level 
option you simply need to do
{code:java}
logLevel = Level.getLevel(opt.toUpperCase());{code}
exactly as you would for an enum - except that the value of logLevel will be 
null if no match is found while an Enum would generally throw an exception 
without a custom method.

> Level as Enum
> -------------
>
>                 Key: LOG4J2-2971
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2971
>             Project: Log4j 2
>          Issue Type: New Feature
>            Reporter: Caleb Cushing
>            Priority: Major
>
> Tried to write this code with picocli only to be surprised when it didn't 
> work.
> {code:java}
> @CommandLine.Option( 
>  names = { "--level"},
>  defaultValue = "error",
>  showDefaultValue = CommandLine.Help.Visibility.ALWAYS,
>  description = "enable debug logging"
> )
> private Level logLevel = Level.ERROR;{code}
> this means that picocli and many libraries wouldn't be able to simply 
> generate options. In this case I'll have to do quite a bit more work to tell 
> picocli all the possible values.
> perhaps a new API enum could be introduced and method overloading could be 
> used to use it.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to