On Mon, Jan 10, 2022 at 11:34 AM Mark Thomas <ma...@apache.org> wrote:
>
> I went to look at the source code and found something I'd completely
> forgotten about. Tomcat exposes several properties that you can use in
> logging.properties. They are:
>
> classloader.webappName
> classloader.hostName
> classloader.serviceName
>
> There are several ways you could make use of those.

You're the one who added this feature 7 years ago ;)

Rémy

> Mark
>
>
> On 10/01/2022 08:59, Makarov Alexey wrote:
> > Thank you, Mark!
> >
> > Excuse me, I forgot describe deployment. Formatter implemented as
> > library (log-formatter.jar). I specified classpath to this library in
> > setenv.sh:
> >
> > echo "Setting parameters from $CATALINA_BASE/bin/setenv.sh"
> > echo "_______________________________________________"
> >
> > export CLASSPATH="$CATALINA_BASE/lib/log-formatter-1.0.jar:$CLASSPATH"
> >
> > echo "_______________________________________________"
> > echo ""
> >
> > Logging configured globally in ${catalina.base}/conf/logging.properties
> > file:
> >
> > ...
> > org.apache.tomee.jul.formatter.AsyncConsoleHandler.level = FINE
> > org.apache.tomee.jul.formatter.AsyncConsoleHandler.formatter =
> > my.log.formatter.OneLineFormatter
> > org.apache.tomee.jul.formatter.AsyncConsoleHandler.encoding = UTF-8
> >
> > ...
> >
> > Looks like, I cannot access to ServletContext directly... Maybe there
> > any other way, to get servlet context from InitialContext or application
> > name from LogManager property:
> >
> > java.util.logging.LogManager.getLogManager().getProperty(...)
> >
> > Do you know desired property or how to list LogManager properties?
> >
> > 10.01.2022 12:53, Mark Thomas пишет:
> >> Use ServletContext.getContextPath()?
> >>
> >> If you have a more complex deployment you might want to preface it
> >> with ServletContext.getVirtualServerName()
> >>
> >> Mark
> >>
> >> On 10/01/2022 05:00, Makarov Alexey wrote:
> >>> Hello! I want to print application name in my log files. As I know, I
> >>> must implemet custom log formatter. How I can get application name?
> >>> import java.util.logging.Formatter;
> >>> import java.util.logging.LogRecord;
> >>> public class MyCustomLogFormatter extends Formatter {
> >>>      @Override
> >>>      public String format(LogRecord record) {
> >>>         String webappName = ...;
> >>>         return String.format("%s/n", webappName); // only application
> >>> name for testing
> >>>      }
> >>> }
> >>> I use Tomcat 9.0.
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> >> For additional commands, e-mail: users-h...@tomcat.apache.org
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> > For additional commands, e-mail: users-h...@tomcat.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to