Customized access log (Apache Tomcat 7.0.8) remains zero kb - tomcat-valve

I'm trying to create a shorten/customized version of AccessLog (naming it Stats_log)
to log out few items (HTTP code, response time, request type) from the request.
So i've copied my full AccessLogValve and edited it to match my needs.
after restarting the server, the new log is created but it remains zero(!) 0kb.
can anyone point out what am I doing wrong here?
The weird thing is that the customized log works for me (using the same settings) in my testing ENV which is running Apache Tomcat 7.0.2. (while the PROD environment is 7.0.8).
Any suggestions?
here are the Valve settings as appear in the server.xml file:
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="172.30.21.244_**access_log**." suffix=".txt" pattern="%h %l %u %t "%r" %s %b" resolveHosts="false"/>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_stats_log." suffix=".txt" fileDateFormat="yyyy-MM-dd.HH" pattern="%U,%s,%D,%{Internal-Status-Code}o" resolveHosts="false"/>
Thanks in advance!

The following actions have resolved this:
1) it seems that my copy & paste somehow added a line brake (\n).
2) moved the customized AccessLogValve under to be under .
That's made the trick :)

Related

Spring Boot 3: Can't set logging.pattern.console in application.yaml

I'm trying to add a "correlation-id" to the logs that are written by my Spring-Boot application.
For that I've taken the spring-boot logback default value and added it to my application.yaml, which looks like this:
logging:
pattern:
console: ${CONSOLE_LOG_PATTERN:-%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd'T'HH:mm:ss.SSSXXX}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}
But now my application isn't starting anymore and fails with:
Could not copy file '/my-project/src/main/resources/config/application.yaml' to '/my-project/build/resources/main/config/application.yaml'.
Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): startup failed:
SimpleTemplateScript62.groovy: 1: Unexpected input: '(' # line 1, column 10.
out.print("""spring:
Putting "" around the pattern doesn't help
replacing ":-" with ":" doesn't make a difference
Removing all the variables (and putting "" around the pattern) works
Setting the pattern as an environment variable works too
Is there something missing in my approach? I would prefer to have this change in my application.yaml instead of an environment variable so that not everyone needs to configure it locally to have the same log output as it is expected on production.
I'm using Spring-Boot 3.0.2 with gradle 7.6

Handle c-dns and s-dns values in access log

I'm using Spring boot 2.1.10 and I want to customize embedded tomcat access logs. I'm using this pattern in the application.yml file;
pattern: "[ACCESS] %{id}i %{x-forwarded-for}i %{client-ip}i %{server-ip}i %{dd.MM.yyyy}t %{HH:mm:ss}t %U %s %s %m %T %B %{user-agent}i"
The problem is, I cannot get C-DNS and S-DNS values. When I look at the tomcat documentation in this url, usage listed like this;
The following format tokens are supported:
C-DNS - Remote hostname (or IP address if enableLookups for the connector is false)
S-DNS - Local hostname
I tried it like this : %{c-dns}i or %{c-dns} or {c-dns} or c-dns nothing worked.
Do you have any suggestions?
I found the proper way with writing my own configuration class. Guide : Baeldung

Spring Log4j RollingFileAppender change folder

my log was running correctly with RollingFileAppender but I need compress generated files and move to folder "${app.log}\Backup". Attach log4j properties:
log4j.appender.appDebug=org.apache.log4j.RollingFileAppender
log4j.appender.appDebug.file=${app.log}\\app_exe.log
log4j.appender.appDebug.MaxFileSize=100MB
log4j.appender.appDebug.maxBackupIndex=10
log4j.appender.appDebug.layout=org.apache.log4j.PatternLayout
log4j.appender.appDebug.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} {%-15.15t} [%-5p] %m %n
log4j.appender.appDebug.Threshold = DEBUG
Add below :
log4j.appender.appDebug.rollingPolicy=org.apache.log4j.rolling.FixedWindowRollingPolicy
log4j.appender.appDebug.rollingPolicy.maxIndex=5
log4j.appender.appDebug.triggeringPolicy=org.apache.log4j.rolling.SizeBasedTriggeringPolicy
log4j.appender.appDebug.triggeringPolicy.MaxFileSize=10000

Load language file during joomla (2.5) system plugin installation

I'm having a real hard time showing a localized string during the installation of a system plugin (in Joomla 2.5). The "normal" way with localized strings in the xml file doesn't seem to work, (see this other question: Language based installation description).
I now tried the way proposed there, to show the description via the install scripts. This kind of works (I can echo text successfully), however, I also can't localize there - when debugging the language it shows that the plugin.sys.ini is not loaded yet; I tried to manually load the file, but had no success with loading any of my plugin language files.
This is what I got so far (in a file named setupscripts.php):
<?php // no direct access
defined('_JEXEC') or die('Restricted access');
class plgsystemmyplgnameInstallerScript {
static function loadLanguage() {
$lang =& JFactory::getLanguage();
$lang->load('plg_system_myname', JPATH_ADMINISTRATOR);
}
function install($parent)
{
self::loadLanguage();
echo JTEXT::_("PLG_MYNAME_TEST_TEXT");
}
function uninstall($parent)
{
self::loadLanguage();
echo JText::_('PLG_MYNAME_UNINSTALL_TEXT');
}
function update($parent)
{
self::loadLanguage();
echo JText::_('PLG_MYNAME_UPDATE_TEXT');
}
function preflight($type, $parent) {}
function postflight($type, $parent) {
self::loadLanguage();
echo JText::_('PLG_MYNAME_INSTALL_TEXT');
}
}
But I only get ??PLG_MYNAME_TEST_TEXT?? ??PLG_MYNAME_INSTALL_TEXT?? (language debugging is turned on) during installation... weirdly enough, the language debug feature at the bottom of the page under "untranslated strings" shows "None" (where do the question marks then come from if not from a tried but failed translation???).
Tried some variations of it (with .sys at the end of the plugin name, since I actually think the setup strings should be in the .sys.ini file, without the second parameter (leaving it default), but no luck - no error, nothing in the log (in fact my log file isn't existing, probably there was no entry yet? can one set the log level with Joomla?). But never is there any file loaded (nothing changes under "loaded language files".
Anybody got an idea how to load the language properly?
Is there something special to consider when loading languages during setup? Why is there no error message if loading the languages fails? Do I maybe have to install the language files to a special location to get them recognized during installation? My current xml looks like this:
<extension version="2.5" type="plugin" group="system" method="upgrade">
<name>PLG_MYNAME</name>
<!-- ... author, copyright, version, .. -->
<scriptfile>setupscripts.php</scriptfile>
<files>
<filename plugin="myname">myname.php</filename>
<filename>setupscripts.php</filename>
<filename>index.html</filename>
<folder>sql</folder>
</files>
<!-- ... install->sql->file ... -->
<!-- ... uninstall->sql->file ... -->
<!-- ... update->schemas->schemapath ... -->
<languages [folder="admin"]>
<language tag="en-GB">en-GB.plg_system_myname.ini</language>
<language tag="en-GB">en-GB.plg_system_myname.sys.ini</language>
<!-- ... other languages ... -->
</languages>
<!-- ... config->fields->fieldset->field ... -->
</extension>
(the square brackes around folder="admin" are supposed to indicate that I tried both with and without this attribute. It doesn't change anything).
It only works on installation if you also copy the files to the admin language folder. If you look at the core extensions you will see that they do both. It's really a bug but that's the work around.
Finally I found out how to really do it. A thorough search in the google Joomla dev group brought up this very similar question.
Basically, the language files need to reside in a separate language folder it seems, and the files section also needs to reference them. My xml now looks like this:
<!-- ... everything else stayed the same, except: -->
<files>
<filename plugin="myplg">myplg.php</filename>
<filename>index.html</filename>
<folder>language</folder>
<folder>sql</folder>
</files>
<languages folder="language">
<language tag="en-GB">en-GB/en-GB.plg_system_myplg.ini</language>
<language tag="en-GB">en-GB/en-GB.plg_system_myplg.sys.ini</language>
<!-- .. other languages ... ->
</languages>
<!-- ... rest of the xml file ... -->
The language files are now all in separate subfolders... they get copied to the exact same location as before (administrator/language//...), but now the description from the XML is also localized!
I find it very weird that there are so many ways to specify language files, which all basically work except for the one corner case of the installation...
Hope this will help other people struggling with this!

HTML 5 Cache manifest gets cached itself

I have a problem of that it seems that the cache.manifest file gets cached itself. Meaning every changes to the file are not being noted by (Mobile) Safari, so it will never update and always show the last cached files.
I tried to avoid it using an .htaccess file in the same directory as the cache.manifest file:
ExpiresActive On
ExpiresDefault "access"
That didn't help so I changed cache.manifest in a php file that contains the following headers:
header("Expires: Mon, 26 Jul 1990 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header('Content-Type: text/cache-manifest');
Anyone have other ideas of how I can make sure the cache file itself will get retrieved if possible?
Works on: Safari (Desktop), Chrome (Samsung Galaxy Tab v10.1), Firefox
Fails on: Chrome, Safari (iOS)
Renamed the cache.manifest.php back to cache.manifest and added the following lines to the .htaccess
<IfModule mod_expires.c>
Header set Cache-Control "public"
ExpiresActive on
# cache.manifest needs re-requests in FF 3.6 (thx Remy ~Introducing HTML5)
ExpiresByType text/cache-manifest "access plus 0 seconds"
</IfModule>
If I change the revision comment within the cache.manifest and refresh it on Safari (iOS) it still shows me the old file. I am clueless.
According to the HTML5 documentation, if an application cache manifest file is byte-for-byte the same as a previous one, regardless of HTTP cache headers for expiry/etc, it is considered to not require an update.
At the bottom of your cache manifest file, you need to include a comment at the bottom of the file with the timestamp of the most recently modified file, e.g.:
# last modified: Thu, 30 Jun 2011 01:19:46 GMT
This will break up the byte-for-byte identicalness, even if the list of files remains the same but a few are updated.
As alluded to in other answers, cache manifests are a real pain to deal with.
I've tweaked a PHP manifest "build" script for my HTML5 notepad app.
Tested and working on Chrome, Firefox, IE8+, Android and iOS.
It's open source and available here: https://github.com/JasonHanley/note5/blob/master/build.php
I also use the ExpiresByType text/cache-manifest "access plus 0 seconds" in my .htaccess and I believe that is necessary in addition to generated manifest timestamps.
I've just stumbled onto this one myself, and in a similar vein to SimpleCoders suggestion I'd suggest that if you are using Apache you can generate the cache.manifest using Server Side Includes, eg:
CACHE MANIFEST
# <!--#flastmod file="index.html"-->
# <!--#flastmod file="whatever.js"-->
# <!--#flastmod file="whatever.css"-->
whatever.js
whatever.css
That way, whenever any of those files are updated, the manifest will change automatically. You may also need to enable includes for that file and disable caching, eg: Apache config something like:
Alias /whatever /var/www/whatever
<Directory /var/www/whatever>
Options +Includes
AddHandler server-parsed .manifest
</Directory>
CacheDisable /whatever/ihealth.manifest
Check your server logs to make sure you're returning the file with a "200 Okay" rather than a "304 Not Modified".
The cache manifest is a terrible piece of technology.
The browser is not caching the manifest; instead, it's just failing to recognize that it has changed which is what you are observing. Try adding a random comment or two to your manifest (prepend comments with #) and then see if it works.
Just modifying files that the manifest references won't trigger the browser to redownload the manifest. If this is what you were hoping for, then try this: Use a PHP file to generate your manifest. Of course, use header to set the proper MIME type. After you have echoed out all of your resources, echo out the hash of the timestamp of all of those resources. That way, if one of them is modified, the manifest file changes. This is what I'm using:
// Collect a list of resources we need to check (customize to your needs)
$files = array(
"/scripts/script1.js",
"/scripts/script2.js",
"/scripts/script3.js",
"/scripts/script4.js",
"/css/style.css"
);
$filetime = 0;
foreach ($files as $file) {
$filetime += filemtime($file);
}
// This echoes out the hash of the filetimes as a comment
echo "#" . sha1($filetime);

Resources