• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why isn't SpringBoot writing to the log in Ubuntu 20.04?

 
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,

This log problem has been going on for several days.

To get the log file from the SpringBoot application to be successfully written to on Ubuntu 20.04, I've tried re-creating AWS instances multiple times, extremely carefully setting everything up.

The SpringBoot application itself is fine, it runs OK. It returns expected results quickly.

However, regardless of what I do, it will not write to its "ws.log" file.

What's maddening is that the EXACT same SpringBoot configuration works fine on Windows Server 2019 (and always has).

Here is the logging.file.name I hard-coded (for testing) into SpringBoot's application.properties:
logging.file.name=/var/lib/tomcat9/logs/ws.log

And, here is the directory entry for ws.log after doing multiple things in the REST service that do logging:

/var/lib/tomcat9/logs
-rwxrwxrwx  1 tomcat adm         0 Jan 22 13:45 ws.log

I've tried changing owners, groups, and, as you see, above, as yet another test, I even did a "chmod 777" on ws.log thinking possibly it could be a permissions problem. Nope, nothing I did made a bit of difference.

As a simple test, in one of the SpringBoot's Controllers. I wrote some simple Java code to write to that same file (avoiding the logger for this test). This did work (surprisingly to me), but of course that's doesn't explain why SpringBoot isn't writing to the ws.log file.

However, even with all these tests, rebuilds, and endless config attempts, I cannot get the SpringBoot application to write to the log file itself.

There is also nothing in the other Tomcat logs like catalina.out that has any entries about logging or anything specific.

I would greatly appreciate any suggestions.

Thanks,

-- mike
 
Saloon Keeper
Posts: 27816
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If memory serves, Spring Boot logs by default to stdout and I just redirect that. Less trouble and more flexible than setting a logfile internally.

A stand-alone copy of typically Tomcat uses JULI to log to stdout and the catalina script redirects stdout to TOMCAT_HOME/logs/catalina.out. However, Spring Boot runs Tomcat as embedded JavaBean object and almost certainly injects its own logging into the Tomcat bean.

All of that by way of background. Now the real questions:

1. Are you SURE that the logger your app is using is the same logger that Spring Boot is using? Do you need an slf4j bridge to make it so?

2. Do you have sufficiently high logging levels enabled for the app?
 
Tim Holloway
Saloon Keeper
Posts: 27816
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, here's a possible idea: check the system logs with the journalctl utility and see if Spring Boot is sending its logs there.
 
Bartender
Posts: 1359
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried to use logback-spring.xml file to configure logging?
I remember I ran in some logging issues when running a spring boot application as Windows service via wrapper - nothing anyway like you, i.e no logs at all
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tim for your suggestion about journalctl.

When I search for my test webapp (renamed for public posting below), I get these errors over and over. I have no idea what "Failed to clear soft references" and how or how these errors occur.

Jan 22 14:36:48 ip-172-31-22-119 tomcat9[1272]: Failed to clear soft references from ObjectStreamClass$Caches for web application [mywebapp]
Jan 23 06:16:49 ip-172-31-22-119 tomcat9[530]: Deploying web application archive [/var/lib/tomcat9/webapps/mywebapp.war]
Jan 23 06:17:12 ip-172-31-22-119 tomcat9[530]: SLF4J: Ignoring binding found at [jar:file:/var/lib/tomcat9/webapps/mywebapp/WEB-INF/lib/logback-classic-1.2.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
Jan 23 06:17:19 ip-172-31-22-119 tomcat9[530]: Deployment of web application archive [/var/lib/tomcat9/webapps/mywebapp.war] has finished in [29,390] ms

---

But, wait ...

These "soft references" are occurring with Tomcat overall.

If change the command to $ journalctl | grep "soft*", I get this:

Jan 22 13:59:51 ip-172-31-22-119 tomcat9[530]: Failed to clear soft references from ObjectStreamClass$Caches for web application [ROOT]
Jan 22 13:59:52 ip-172-31-22-119 tomcat9[530]: Failed to clear soft references from ObjectStreamClass$Caches for web application [mywebapp]

--

Perhaps this is the problem, but I don't understand exactly how to fix it since the webapp works fine on Windows:

Jan 23 06:32:39 ip-172-31-22-119 tomcat9[1345]: SLF4J: No SLF4J providers were found.
Jan 23 06:32:39 ip-172-31-22-119 tomcat9[1345]: SLF4J: Defaulting to no-operation (NOP) logger implementation
Jan 23 06:32:39 ip-172-31-22-119 tomcat9[1345]: SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.
Jan 23 06:32:39 ip-172-31-22-119 tomcat9[1345]: SLF4J: Class path contains SLF4J bindings targeting slf4j-api versions 1.7.x or earlier.
Jan 23 06:32:39 ip-172-31-22-119 tomcat9[1345]: SLF4J: Ignoring binding found at [jar:file:/var/lib/tomcat9/webapps/mywebapp/WEB-INF/lib/logback-classic-1.2.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
Jan 23 06:32:39 ip-172-31-22-119 tomcat9[1345]: SLF4J: See https://www.slf4j.org/codes.html#ignoredBindings for an explanation.
Jan 22 13:59:52 ip-172-31-22-119 tomcat9[530]: Failed to clear soft references from ObjectStreamClass$Caches for web application [host-manager]
Jan 22 13:59:52 ip-172-31-22-119 tomcat9[530]: Failed to clear soft references from ObjectStreamClass$Caches for web application [manager]
Jan 22 14:00:06 ip-172-31-22-119 kernel: Performance Events: unsupported p6 CPU model 85 no PMU driver, software events only.
Jan 22 14:00:06 ip-172-31-22-119 kernel: PCI-DMA: Using software bounce buffering for IO (SWIOTLB)
Jan 22 14:00:06 ip-172-31-22-119 kernel: software IO TLB: mapped [mem 0x00000000bbfea000-0x00000000bffea000] (64MB)
Jan 22 14:00:09 ip-172-31-22-119 dhclient[405]: For info, please visit https://www.isc.org/software/dhcp/
Jan 22 14:00:13 ip-172-31-22-119 rsyslogd[481]: [origin software="rsyslogd" swVersion="8.2001.0" x-pid="481" x-info="https://www.rsyslog.com"] start
Jan 22 14:10:19 ip-172-31-22-119 rsyslogd[481]: [origin software="rsyslogd" swVersion="8.2001.0" x-pid="481" x-info="https://www.rsyslog.com"] exiting on signal 15.

---

I've re-installed Tomcat and Ubuntu 20.04 about five times, carefully, and I got these errors every time.

I'm not sure the "Failed to clear soft references" is even the problem.

What's additionally weird is that one of the times I created the AWS Ubuntu 20.04 instance, the logging was working.

Should I try another version of Tomcat 9? Not exactly sure how to do that on Linux.

Look forward to your insights and suggestions.

Thanks,

-- mike
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've tried adding various combinations of SLF4j dependencies to my pom.xml (which isn't needed in Windows), but still no go. Spring won't write. I have no idea why Ubuntu Linux is ignoring the basic Spring logging per the systemctl entries.

Also updated to Spring 2.7.8 (unsure if 3.0.2 SpringBoot would cause other problems) as a test.

These SLF4j items are in the SpringBoot's External Libraries, with no apparent way to remove them (or if I even should)...

>Maven: org.slf4jjcl-over-sif4j:1.7.36
>Maven: org.sif4j:jul-to-slf4j:1.7.36
>Maven: org.slf4i:sIf4j-api:1.7.36

Thanks,

-- mike
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Claude Moore wrote:Have you tried to use logback-spring.xml file to configure logging?
I remember I ran in some logging issues when running a spring boot application as Windows service via wrapper - nothing anyway like you, i.e no logs at all



Spring is creating the output log file; it's just not writing to it.

Is that the problem you had?

Well, I need to create my 20.04 instance yet again since my ~ directory seems to randomly become a file that I can't make a directory again.

This is fun....

Thanks,

-- mike
 
Tim Holloway
Saloon Keeper
Posts: 27816
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q: Have you tried running with the Oracle JDK? While OpenJDK is supposed to be fully-compliant these days, different implementations can lead to different results. and, ironically, sometimes the "official" product has a bug loophole that a third-party does not. A second glance indicates that the soft references messages are warnings about potential memory leaks, and not directly functional, though they may indicate that you are mixing Java 8/earlier and Java 9/later components.

A quick check indicates that as of 2018, OpenJDK was reporting this error in some cases, so try the Oracle JDK and see if it helps. Not even sure you're using OpenJDK on Windows, although I think has been ported there.

Note also that "~" is not a filename, it's a shell shortcut for $HOME a/k/a Properties("user.home"). It will not expand in code, whether Java or otherwise, so it only works as a shell parameter.

You might also want to get Maven to dump dependencies so we can see what versions of your libraries are in play. A rough guess on the SLF4J messages seem to indicate that SLF4J is routing logs to the Twilight Zone and very likely because of library version conflicts.
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:Q: Have you tried running with the Oracle JDK? While OpenJDK is supposed to be fully-compliant these days, different implementations can lead to different results. and, ironically, sometimes the "official" product has a bug loophole that a third-party does not. A second glance indicates that the soft references messages are warnings about potential memory leaks, and not directly functional, though they may indicate that you are mixing Java 8/earlier and Java 9/later components.

A quick check indicates that as of 2018, OpenJDK was reporting this error in some cases, so try the Oracle JDK and see if it helps. Not even sure you're using OpenJDK on Windows, although I think has been ported there.

Note also that "~" is not a filename, it's a shell shortcut for $HOME a/k/a Properties("user.home"). It will not expand in code, whether Java or otherwise, so it only works as a shell parameter.

You might also want to get Maven to dump dependencies so we can see what versions of your libraries are in play. A rough guess on the SLF4J messages seem to indicate that SLF4J is routing logs to the Twilight Zone and very likely because of library version conflicts.



What's weird is that both Mac and Windows work perfectly.

I am developing on the Mac using Corretto 11.

I just updated to latest Corretto 11 (Jan, 2023) and recompiled and copied WAR to Ubuntu. No difference.

JVM Version on Linux: 11.0.17+8-post-Ubuntu-1ubuntu220.04

It doesn't look like Linux will work for us. I was hoping to save some $$$ over Windows AWS hosting, but Windows works so well it may be worth it. Maybe.

Thanks Tim.
 
Tim Holloway
Saloon Keeper
Posts: 27816
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have absolutely no idea why Linux is such a problem for you. I've used it for all my apps for donkey's years. In fact, I have not touched Windows since TurboTax went web-based.

Admittedly, I have historically preferred the Oracle JDK over OpenJDK, but the first few years of open-source Java were pretty rough, especially for JEE. OpenJDK is now pretty mature, however.

As longtime moderator of the Tomcat forum, I've almost never seen as someone with many OS-related Tomcat problems as you've been having, and most of them were problems with getting Windows to run Tomcat as a service. I really wonder about the state of your test machine, and you've already admitted to doing things that aren't blessed by JEE, but still...
 
Tim Holloway
Saloon Keeper
Posts: 27816
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One more thing. You tend to reference installed Tomcat and Spring Boot interchangeably. I do not believe you have to install Tomcat to build a Spring boot app. I'm almost 100% certain that Spring Boot downloads its own copy of Tomcat, whose version and configuration are totally unrelated to any stand-alone copies of Tomcat you have installed. Which causes me confusion.

Finally, I recommend you might try this. Do a git clone of the project at https://gogs.mousetech.com/mtsinc7/gourmetj-springboot and follow the instructions in the README. It won't be fully functional unless you define a database for it to talk to, and if you'd like, I can supply one for you, but you should at least be able to see it logging properly to the console or journal, even if it gets mad when it doesn't find a database.

Foootnote: The above app expects Java 11 or higher.
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:I have absolutely no idea why Linux is such a problem for you. I've used it for all my apps for donkey's years. In fact, I have not touched Windows since TurboTax went web-based.

Admittedly, I have historically preferred the Oracle JDK over OpenJDK, but the first few years of open-source Java were pretty rough, especially for JEE. OpenJDK is now pretty mature, however.

As longtime moderator of the Tomcat forum, I've almost never seen as someone with many OS-related Tomcat problems as you've been having, and most of them were problems with getting Windows to run Tomcat as a service. I really wonder about the state of your test machine, and you've already admitted to doing things that aren't blessed by JEE, but still...



My DEV machine, and Windows production server all work PERFECTLY with the exact same configuration that fails on Linux.

I have ZERO problems with Tomcat. Except on Linux.

Hope that clarifies.

Thanks Tim.
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:One more thing. You tend to reference installed Tomcat and Spring Boot interchangeably. I do not believe you have to install Tomcat to build a Spring boot app. I'm almost 100% certain that Spring Boot downloads its own copy of Tomcat, whose version and configuration are totally unrelated to any stand-alone copies of Tomcat you have installed. Which causes me confusion.

Finally, I recommend you might try this. Do a git clone of the project at https://gogs.mousetech.com/mtsinc7/gourmetj-springboot and follow the instructions in the README. It won't be fully functional unless you define a database for it to talk to, and if you'd like, I can supply one for you, but you should at least be able to see it logging properly to the console or journal, even if it gets mad when it doesn't find a database.

Foootnote: The above app expects Java 11 or higher.




We deploy our webapps to the installed Tomcat directory where we have SSL configuration installed.

Searching for Tomcat in Linux only shows our installed version.

I have no idea what you're talking about.

Thanks Tim.
 
Tim Holloway
Saloon Keeper
Posts: 27816
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That makes no sense at all! You don't deploy Spring Boot apps into a Tomcat applications directory, Spring Boot is a stand-alone Java Application! They call it Spring Boot, precisely because it runs without a separate webapp server.

You can build a Spring Boot project to produce a WAR file instead of the standard JAR, but then it is no longer a Spring Boot app and all you've done is build a WAR the hard way. And yes, there's a reason why Spring Boot can produce WARs as well as JARs, but it's a special case.

No wonder you've got such a mess. Either run as Spring Boot or build a traditional WAR. They have vastly different configurations and needs and mixing them can only cost time, money, and peace of mind.
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:That makes no sense at all! You don't deploy Spring Boot apps into a Tomcat applications directory, Spring Boot is a stand-alone Java Application! They ca;; it Spring Boot, precisely because it can run without a separate webapp server.

You can build a Spring Boot project to produce a WAR file instead of the standard JAR, but then it is no longer a Spring Boot app and all you've done is build a WAR the hard way. And yes, there's a reason why Spring Boot can produce WARs as well as JARs, but it's a special case.

No wonder you've got such a mess. Either run as Spring Boot or build a traditional WAR. They have vastly different configurations and needs and mixing them can only cost time, money, and peace of mind.



It's a WAR file, Tim.

Everything works fine and has for years. No mess, Tim.

Example: https://www.baeldung.com/spring-boot-war-tomcat-deploy

Please close this chat.

Thanks.
 
Tim Holloway
Saloon Keeper
Posts: 27816
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just a reminder that the title of this thread is "Why isn't SpringBoot writing to the log in Ubuntu 20.04?". If you hadn't explictly said "Spring Boot" I wouldn't have been so confused.
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:Just a reminder that the title of this thread is "Why isn't SpringBoot writing to the log in Ubuntu 20.04?". If you hadn't explictly said "Spring Boot" I wouldn't have been so confused.



Sorry for that confusion. Since I have never used SpringBoot except for WAR file deployment other deplooyment types didn't occur to me.

Thanks for pointing this out.

- mike
 
Tim Holloway
Saloon Keeper
Posts: 27816
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK. The primary use case for Spring Boot these days, I think, is to create "no-server" applications that can be containerized. Rather than one webapp server containing multiple webapps, you'd have a container system running multiple containers, each of which contains a complete embedded webapp server/webapp in the form of a Spring Boot executable JAR. The container manager then redirects the network ports to ensure that there are no conflicts, and typically there's a reverse proxy server somewhere that consolidates them into a single network presence. That is, in fact, what I do.

The advantage of the container approach is that it's easier to deploy and can be done elastically, ramping parallel containers up/down to meet workloads.

The problem with generating a WAR from a Spring Boot project is that the Spring Boot application source code contains a number of files and file locations that have no meaning on a WAR-deployed webapp. And I've never tried using Spring Boot's WAR-generation feature to know how it resolves that conflict. Definitely there is an impact on how Spring Security would interact and how logging works - especially since a stand-alone Tomcat would log Tomcat itself via one logging system and the webapp is responsible separately for its own logging instead of having a consolidated log like stand-alone Spring Boot would.
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I noticed that on both the Mac and On Windows, I also have the same entries in the Log (catalina.out):

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.


Yet in both these environments, Mac and Windows Server, the SpringBoot logging (SLF4J) is working fine.

This evidence makes me think there is a permissions issue on that ws.log file or something else going on.

There is nothing else in the logs of note except for, with every Tomcat app, that it failed to clear soft references. No idea how to fix that, either.

Below, I have documented every step I do to install Tomcat on a fresh Linux instance  including the setenv.sh step to get the logging directory itself (Note: I've also tried a hard-coded path from SpringBoot without the setenv.sh in $CATALINA_HOME/bin with no luck either.)

Fresh Linux AWS install steps:

----------------------
Basic Server Setup:
----------------------
Pick t3.large AWS Ubuntu 20.04 or 22.04 LTS image
Set Disk space, 50 GB
Associate Security Group already defined
Create Elastic IP and associate with running instance

>>> Create Instance <<<

----------------------------------------------------
Inside Running AWS Instance:
----------------------------------------------------
Do initial SW update: sudo apt update && sudo apt upgrade -y

----------------------------------------------------
Java JDK Install in case need to write ad-hoc code
----------------------------------------------------
sudo apt install openjdk-11-jdk-headless

-------------------
Install Tomcat 9:
-------------------
$ sudo apt install tomcat9 tomcat9-admin

-------------------------------
See that Tomcat was installed:
-------------------------------
$ss -ltn

----------------------------------------
Enable Tomcat Server
----------------------------------------
$ sudo apt install tomcat9 tomcat9-admin

----------------------------------------
Allow traffic to/from any port
----------------------------------------
$sudo ufw allow from any to any port 9443 proto tcp

------------------------
Set up ROOT USER Linux
------------------------
$sudo passwd root

-------------------------------------
Tomcat Access & SSL Certificate Tasks
-------------------------------------
Install pre-defined tomcat-users.xml
Install pre-defined server.xml
Install pre-defined keyStore.jks

(SSL setup works perfectly.)

Verify you can now reach the Tomcat admin page "It works" on the encrypted port, 9443.
(this works perfectly.)

----------------------
Set correct timezone:
----------------------

----------------------------------------------------------
TOMCAT LOG STEPS DIRECTORY SET UP
(BELOW)
----------------------------------------------------------
Create environment variables in .bashrc for CATALINA_BASE
----------------------------------------------------------
export CATALINA_HOME=/usr/share/tomcat9
export CATALINA_BASE=/usr/share/tomcat9

------------------------------------------------------------------
Create setenv.sh file in $CATALINA_BASE/bin with this content:
------------------------------------------------------------------
CATALINA_OPTS="${CATALINA_OPTS} -DLOG_DIR=/var/lib/tomcat9/logs"

---------------------------------------------------------------
As Root - Copy SpringBoot WAR File into /var/lib/tomcat/webapps
---------------------------------------------------------------
#mv /home/ubuntu/theApp.war /var/lib/tomcat9/webapps

Note that the webapp deploys as expected.
Note that methods in the web app are callable and work.

Note that the Web App WAR file has (in Spring's application.properties):
logging.file.name = ${LOG_DIR}/ws.log

Note that in the catalina.out tha this LOG_DIR was correctly read by Tomcat on startup.

(as noted above, I also tried logging.file.name= with just a full hard-coded disk path but that did not work either.)

**********************************************************
But *** Note that the log file is not being written to ***
Log Directory: /var/lib/tomcat9/logs
**********************************************************

drwxrws---  2 tomcat adm      4096 Jan 19 15:53 .
drwxrwxr-x 11 root   syslog   4096 Jan 19 15:52 ..

**********************************************************
-rw-r-----  1 tomcat adm         0 Jan 19 15:53 ws.log  
-rw-r-----  1 tomcat adm    113391 Jan 19 15:53 catalina.2023-01-19.log
**********************************************************
-rw-r-----  1 syslog adm     36156 Jan 19 15:53 catalina.out
-rw-r-----  1 tomcat adm      3747 Jan 19 15:53 localhost.2023-01-19.log
-rw-r-----  1 tomcat adm      2002 Jan 19 15:54 localhost_access_log.2023-01-19.txt

---------------------------
OTHER TEST DONE
---------------------------
As another test, I wrote some simple code in one of the WebApp's Controllers to use a FileWriter to try to write to the ws.log file from inside the app deployed in Tomcat.
That worked!

So, it seems that the log file ws.log, shown above, is "write-able" from the deployed web app.

So, still very confusing what could be going on here given that the exact same web app works as expected on Mac and Windows Server and the log file itself is write-able from within the app.

As always, would appreciate any insights or concrete steps to take.

-- mike

 
Tim Holloway
Saloon Keeper
Posts: 27816
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did a quick check on what it takes to make a "Spring Boot WAR" and it's not an automatic process. You have to make changes to both the Java code and the POM, and in particular you have to switch off the element that would otherwise pull in a (useless!) separate copy of Tomcat into the WAR itself. And incidentally, some indicate that a Spring Boot WAR is significantly more bloated than a vanilla WAR. I'm not sure why it's apparently such a popular process unless either people are suffering Buyer's Remorse over Spring Boot or they're testing on Spring Boot and deploying production to stand-alone Tomcat (shudder!)

Nonetheless, if that's what you want, so be it. Your primary problem here is that Tomcat does not log from webapplications. Tomcat maintains the server logs, typically in TOMCAT_HOME/logs. Incidentally, you don't actually have to set CATALINA_HOME and CATALINA_BASE to launch Tomcat. And you only need to set both if they refer to separate directories - a common binary and multiple app container instances. Which is why I use the pseudo-path "TOMCAT_HOME" when I talk about Tomcat.

Every web application in JEE is expected to maintain its own logging system which is distinct from the logging systems of any of the other webapps and from the Tomcat server. Tomcat's logger is JULI-based, but mostly I use log4j as the logger for my webapps. Others have their own preferences. Your application thus defines its own logfile locations, message formats, log levels, log destinations (e.g., rolling logs and email alerts) and so forth.

So if you were expecting to set logging for your webapp at the JVM or Tomcat level, it ain't gonna happen.

For a vanilla webapp, like, say, the CodeRanch JForum software, you'd just need to include log4j and slf-log4j in the POM, create a /WEB-INF/classes/log4j.[properties/xml] config file in your WAR and Bob's your uncle.

Unfortunately, Spring Boot doesn't work quite that way since Tomcat is part of the Spring Boot app itself. As a result, Spring Boot mucks around with logging internals and gets information from sources not expected by stand-alone systems. As a result, I cannot tell you what it's going to do on my current payscale, although, as I recall it did say it was routing log messages to Outer Space for lack of a better configuration.

Which means that I can explain and I can suggest, but I cannot speak with authority. I know how to setup logging for vanilla webapps, and I know how to setup logging in freestanding Spring Boot, but I can only guess what a hybrid may do.
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your post makes sense except that, as I've said over and over, SpringBoot logs fine in Windows Server and on the Mac. And, this same logging approach has been used by our team other times.

There was one time I had setup Tomcat on Ubuntu where the webapp WAS writing to the log file. Same basic setup but there was some step I did that I have not done since.

Thanks,
 
Tim Holloway
Saloon Keeper
Posts: 27816
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. If it's running under stand-alone Tomcat, you're no longer Spring Boot. You may have built from a Spring Boot project, but if it's a WAR, it's not a Spring Boot product. Spring Boot produces JARs. You cannot safely deploy a Spring Boot JAR directly into Tomcat, even if you rename it to be a WAR or even change the POM to produce a WAR. As I said, there are things you have to switch off in the POM and source code changes required to the app, or you'll get a corrupt WAR.

If something works at one place or one time but it's violating basic principles, that's no guarantee it will work at all times and in all places. It's just that you were lucky — so far.
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:No. If it's running under stand-alone Tomcat, you're no longer Spring Boot. You may have built from a Spring Boot project, but if it's a WAR, it's not a Spring Boot product. Spring Boot produces JARs. You cannot safely deploy a Spring Boot JAR directly into Tomcat, even if you rename it to be a WAR or even change the POM to produce a WAR. As I said, there are things you have to switch off in the POM and source code changes required to the app, or you'll get a corrupt WAR.

If something works at one place or one time but it's violating basic principles, that's no guarantee it will work at all times and in all places. It's just that you were lucky — so far.



Yep, our SpringBoot app and other apps like it have been working for years in Tomcat with zero issues or logged problems (Windows and Mac).

https://www.baeldung.com/spring-boot-war-tomcat-deploy

Thanks Tim.
 
Tim Holloway
Saloon Keeper
Posts: 27816
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A True Story.

Long ago I worked on the OS support team of a large mainframe-based corporation. At the heart of our systems was a "master control program" that acted like a batch router and processor for various processes and reporting related to mortgages and mortgage servicing.

One of the essential functions within it was a simple compression/decompression module. At the time it was proven that, while crude compared to something like LZW compression, it gave significant savings over storing data and moving it around in RAM - both in space and in CPU resources.

It had, however, one fatal flaw.

The author of this function terminated the compression/decompression operation by the detection of a sentinel byte following the last data byte. That, in and of itself is no problem, but they were allocating a data buffer based on the actual size of the data, so the sentinel byte was being jammed in in an area of RAM that didn't belong to it.

It worked for many years. Until one day IBM shipped an OS mod that altered the memory management system. Now the buffers were ending at page boundaries and the sentinel byte was written to a different page — which didn't exist. The result was that the whole system bombed on a page fault error.

Our first clue was when the 7th-largest bank in the nation called us at 3AM to let us know that the software we'd licensed to them at what were undoubtedly criminally high rates (back then, you didn't run cheap software on expensive computers) wasn't working anymore. I was packing for an emergency flight to Chicago when the word came in that the problem was now manifesting on our in-house clients as well. And we had more than 100 of them. The fix was, fortunately fairly simple (just allocate a proper buffer), though I'm not sure how we got it to our licensed clients quickly, since that was before the Internet and our normal distributions required cutting tapes and shipping them off to the airport.

Moral of the story. If you violate basic rules, you can be lucky and you can be lucky for a long time. But Murphy's always waiting. And you probably won't like it when Murphy's Law kicks in. I personally prefer a placid life, so I'd rather prevent than do a panic repair.

As an aside, I myself cheated on my first personal (pre-IBM) computer and was calling functions in the machine's ROM directly. Then the CPU card blew and I had a warranty replacement. With different version of the ROM code. All my hard-coded calls in my apps failed utterly since everything had moved. Lesson learned.
 
reply
    Bookmark Topic Watch Topic
  • New Topic