Clement, note that lookups are implemented via plugins.
Hence, I presume, you can actually introduce your own os:pid lookup.
See how existing lookups are introduced as plugins in the code.
You can also check the Log4j manual for further details on how to introduce
your own plugins.

On Sat, Mar 27, 2021 at 12:04 AM Ralph Goers <ralph.go...@dslextreme.com>
wrote:

> It would be trivial to create a lookup that returns the pid but I am not
> sure I would want to create a lookup for just that OS value. If we did
> create a lookup it might be something like:
>
> ${web:servletContextName:-${os:pid}}
>
> If you want that please create a Jira issue with perhaps suggestions as to
> what keys it should support.
>
> Ralph
>
> > On Mar 26, 2021, at 3:20 PM, Clément Guillaume <cguilla...@hotpads.com>
> wrote:
> >
> > Interesting, that didn't work (because it was printing the exact string
> > "{${web:servletContextName}" when the servlet name was missing) but using
> > your approach I got something that works:
> >
> > %equals{${web:servletContextName}}{${web:servletContextName}}{%pid}
> >
> > I wonder if a simpler solution exists though.
> >
> > Thank you for your response.
> >
> > On Fri, Mar 26, 2021 at 5:27 AM Volkan Yazıcı <volkan.yaz...@gmail.com>
> > wrote:
> >
> >> Hello Clement,
> >>
> >> I am not an expert on *PatternLayout* and lookups, but I think I have a
> >> hypothesis about what is going wrong and how you can fix it.
> >>
> >> *${web:servletContextName:-${sys:user.name <http://user.name>}}* lookup
> >> works, because the substitute is again a *lookup*. Though
> >> *${web:servletContextName:-%pid}* lookup doesn't work, because the
> >> substitute is a *pattern*. I think the following would do the trick:
> >> *%equals{${web:servletContextName}}{}{%pid}*. Would you mind checking,
> >> please?
> >>
> >> Kind regards.
> >>
> >> On Thu, Mar 25, 2021 at 2:32 AM Clément Guillaume <
> cguilla...@hotpads.com>
> >> wrote:
> >>
> >>> Hello,
> >>>
> >>> I'm trying to make a log pattern showing the servlet context name or,
> if
> >>> missing, showing the process id.
> >>>
> >>> ${web:servletContextName} %msg
> >>> works well for servlet context name alone.
> >>>
> >>> %pid %msg
> >>> works well for process id alone.
> >>>
> >>> ${web:servletContextName:-${sys:user.name}} %msg
> >>> works well for servlet context name with fallback to username system
> >>> property ,
> >>>
> >>> ${web:servletContextName:-%pid} %msg
> >>> does work for servlet context name with fallback to process id.
> >>>
> >>> Am I missing something in my pattern?
> >>>
> >>> Thank you
> >>>
> >>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
>
>

Reply via email to