Re: Application name in log record

2022-01-10 Thread Makarov Alexey

Thanks, Mark!I'll keep it on mind.


11.01.2022 12:43, Mark Thomas пишет:

On 10/01/2022 13:20, Makarov Alexey wrote:
Thank you, but this properties is not work or something wrong. I get 
"${classloader.webappName}", "${classloader.hostName}", or 
"${classloader.serviceName}" in catalina.out when I try to use this 
properties. But if I try to use "${catalina.base}" all fine (property 
is translate to "/opt/tomcat", my install directory).


public class MyCustomLogFormatter extends Formatter {
  @Override
  public String format(LogRecord record) {
 String webappName = LogManager.getLogManager()
   .getProperty(OneLineFormatter.class.getName() + 
".webappName"); // ".hostName", ".serviceName", ".catalinaBase"


 return String.format("%s/n", webappName); // only 
application name for testing

  }
}

in $CATALINA_BASE/conf/logging.properties:

my.log.formatter.MyCustomLogFormatter.webappName = 
${classloader.webappName}

my.log.formatter.MyCustomLogFormatter.hostName = ${classloader.hostName}
my.log.formatter.MyCustomLogFormatter.serviceName = 
${catalina.serviceName}

my.log.formatter.MyCustomLogFormatter.catalinaBase = ${catalina.base}




The short answer is yes. Sorry for not mentioning that before.

The longer answer is that the main thing that JULI does is to extent 
java.util.logging to make it class loader aware. In j.u.l logging 
loggers are uniquely identified by name. In JULI, they are uniquely 
identified by name and class loader. This is so you can have loggers 
with the same name in different web applications without them 
interfering. You can also have per class loader configuration.


The three additional properties I listed above are provided by the web 
application class loader so they only work in per web application 
logging.properties.


Mark

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



Re: Application name in log record

2022-01-10 Thread Mark Thomas

On 10/01/2022 13:20, Makarov Alexey wrote:
Thank you, but this properties is not work or something wrong. I get 
"${classloader.webappName}", "${classloader.hostName}", or 
"${classloader.serviceName}" in catalina.out when I try to use this 
properties. But if I try to use "${catalina.base}" all fine (property is 
translate to "/opt/tomcat", my install directory).


public class MyCustomLogFormatter extends Formatter {
  @Override
  public String format(LogRecord record) {
     String webappName = LogManager.getLogManager()
   .getProperty(OneLineFormatter.class.getName() + 
".webappName"); // ".hostName", ".serviceName", ".catalinaBase"


     return String.format("%s/n", webappName); // only application 
name for testing

  }
}

in $CATALINA_BASE/conf/logging.properties:

my.log.formatter.MyCustomLogFormatter.webappName = 
${classloader.webappName}

my.log.formatter.MyCustomLogFormatter.hostName = ${classloader.hostName}
my.log.formatter.MyCustomLogFormatter.serviceName = ${catalina.serviceName}
my.log.formatter.MyCustomLogFormatter.catalinaBase = ${catalina.base}




The short answer is yes. Sorry for not mentioning that before.

The longer answer is that the main thing that JULI does is to extent 
java.util.logging to make it class loader aware. In j.u.l logging 
loggers are uniquely identified by name. In JULI, they are uniquely 
identified by name and class loader. This is so you can have loggers 
with the same name in different web applications without them 
interfering. You can also have per class loader configuration.


The three additional properties I listed above are provided by the web 
application class loader so they only work in per web application 
logging.properties.


Mark

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



Re: Application name in log record

2022-01-10 Thread Makarov Alexey
Thank you, but this properties is not work or something wrong. I get 
"${classloader.webappName}", "${classloader.hostName}", or 
"${classloader.serviceName}" in catalina.out when I try to use this 
properties. But if I try to use "${catalina.base}" all fine (property is 
translate to "/opt/tomcat", my install directory).


public class MyCustomLogFormatter extends Formatter {
 @Override
 public String format(LogRecord record) {
    String webappName = LogManager.getLogManager()
  .getProperty(OneLineFormatter.class.getName() + 
".webappName"); // ".hostName", ".serviceName", ".catalinaBase"


    return String.format("%s/n", webappName); // only application 
name for testing

 }
}

in $CATALINA_BASE/conf/logging.properties:

my.log.formatter.MyCustomLogFormatter.webappName = ${classloader.webappName}
my.log.formatter.MyCustomLogFormatter.hostName = ${classloader.hostName}
my.log.formatter.MyCustomLogFormatter.serviceName = ${catalina.serviceName}
my.log.formatter.MyCustomLogFormatter.catalinaBase = ${catalina.base}


Shall I try to create per-application logging.properties ?


10.01.2022 15:27, Mark Thomas пишет:
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.

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



Re: Application name in log record

2022-01-10 Thread Rémy Maucherat
On Mon, Jan 10, 2022 at 11:34 AM Mark Thomas  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



Re: Application name in log record

2022-01-10 Thread Mark Thomas
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.

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



Re: Application name in log record

2022-01-10 Thread Makarov Alexey

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



Re: Application name in log record

2022-01-09 Thread 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