log4j2 - IfAccumulatedFileSize property doesn't work - log4j2

I use log4j 2 for logging in me application.
I have 3 requirements:
logs files should consume not more then some amount of disk space - for example 800KB
size of each logs files should be less then some amount - for example 100KB
name of each log file should have date in it
Sometimes there would be a lot of logs during the day, sometimes there would be no logs during the day.
So this is example of what I want to see on date 13 september 2022:
test.log - 0KB
test-2022-09-12-1.log - 50KB
test-2022-09-10-1.log - 50KB
test-2022-09-09-1.log - 50KB
test-2022-09-09-2.log - 100KB
test-2022-09-08-1.log - 75KB
test-2022-09-08-2.log - 100KB
test-2022-09-08-3.log - 100KB
test-2022-09-08-4.log - 100KB
test-2022-09-08-5.log - 100KB
test-2022-09-07-1.log - 75KB
so together it takes 800KB. And when test.log became no empty, file test-2022-09-07-1.log would be deleted.
I use this configuration:
- name: ErrorLoggerAppender
append: true
filename: '${log-path}/test.log'
filePattern: '${log-path}/test-%d{yyyy-MM-dd}-%i.log'
PatternLayout:
Pattern: 'ERROR >>> %l %n%d{ISO8601} [%m] %n'
Policies:
SizeBasedTriggeringPolicy:
size: 100KB
TimeBasedTriggeringPolicy:
interval: 1
modulate: true
DefaultRolloverStrategy:
max: 20
Delete:
basePath: '${log-path}/'
IfFileName:
glob: '*/*.log'
IfAccumulatedFileSize:
exceeds: 800KB
Filters:
- LevelRangeFilter:
minLevel: ERROR
maxLevel: ERROR
onMatch: ACCEPT
But IfAccumulatedFileSize property doesn't work. 20 log files appear in the directory - each with size of 100KB. And If I remove "max: 20" there would be 7 files because 7 is default.
Is there are something wrong in my configuration? How can I achieve what I want?

Related

Ionic/Cordova File plugin fails with to write file when downloading a large number of documents in succession on iOS device

The problem as the user sees it:
User has long list of documents they need to download to iOS device (200+)
User starts the download, with each file downloaded in succession.
At the end of the download queue, they discover that one of the files fails (and its always one of two specific files that are 25MB+)
They retry the job (which only downloads the failed document) and it succeeds
What I'm seeing as a developer:
My app pulls down the document as a blob
When I inspect the blob (within my Typescript app code), it has a size > 0
I call this.file.writeFile(directoryPath, fileName, blob, {replace: true}), which calls the Ionic File wrapper around Cordova File Plugin
However, when I look at the blob in write of FileWriter.js, it has a size of zero
This all results in the error spitting out as:
{"type":"error","bubbles":false,"cancelBubble":false,"cancelable":false,"lengthComputable":false,"loaded":0,"total":0,"target":{"fileName":"","length":0,"localURL":"cdvfile://localhost/persistent/downloaded-assets/9ce34f8a-6201-4023-9f5b-de6133bd5699/{{redacted}}","position":0,"readyState":2,"result":null,"error":{},"onwritestart":null,"onprogress":null,"onwriteend":null,"onabort":null}}
What I'm getting from this is that somewhere between calling file.writeFile on the Ionic File wrapper in my typescript code and the FileWriter.write method in the Cordova package, my blob is getting corrupted, lost, or emptied somehow.
It's difficult to debug as that layer in-between these two points is minified in the xCode debugger, so it would also be nice to hear some suggestions about how I might be able to debug this myself better.
Do we have any idea what might be going on here? Is it a memory issue on iOS? Does Cordova timeout over multiple repeated requests?
A few things to note:
The full list of files download fine every time on I try within the iOS xCode simulator. This is leading me to believe it might be a memory issue, but I'm not sure.
The failure always happens after about 200 files, and on one of two files that are 25-30MB+
As far as debugging goes, the earliest I can see my blob reduced to 0 is here https://github.com/apache/cordova-plugin-file/blob/4a92bbbea755aa9e5bf8cfd160fb9da1cd3287cd/www/FileWriter.js#L107 (though I might be debugging incorrectly)
EDIT - After a little more digging, I was able to see exactly where the Ionic plugin went wrong:
The code I used:
private writeFileInChunks(writer: FileWriter, file: Blob) {
console.log('SIZE OF FILE AT START', file.size);
const BLOCK_SIZE = 1024 * 1024;
let writtenSize = 0;
function writeNextChunk() {
const size = Math.min(BLOCK_SIZE, file.size - writtenSize);
console.log('CALCULATED SIZE:', size);
const chunk = file.slice(writtenSize, writtenSize + size);
console.log('SIZE OF CHUNK TO WRITE', chunk.size)
writtenSize += size;
writer.write(chunk);
}
return getPromise<any>((resolve, reject) => {
writer.onerror = reject as (event: ProgressEvent) => void;
writer.onwrite = () => {
if (writtenSize < file.size) {
writeNextChunk();
} else {
resolve();
}
};
writeNextChunk();
});
}
The output for the failed document:
SIZE OF FILE AT START: 34012899
CALCULATED SIZE: 1048576
SIZE OF CHUNK TO WRITE: 0
On retry:
SIZE OF FILE AT START: 34012899
CALCULATED SIZE: 1048576
SIZE OF CHUNK TO WRITE: 1048576
CALCULATED SIZE: 1048576
SIZE OF CHUNK TO WRITE: 1048576
...
...
...
CALCULATED SIZE: 458467
SIZE OF CHUNK TO WRITE: 458467
So for whatever reason, after a large number of previous downloads, that file.slice step results in an empty/corrupted blob.
Any ideas on how to correct this?
Ran another test with some expanded logging:
private writeFileInChunks(writer: FileWriter, file: Blob) {
...
function writeNextChunk() {
const size = Math.min(BLOCK_SIZE, file.size - writtenSize);
console.log('CALCULATED SIZE:', size);
console.log('WRITTEN SIZE', writtenSize);
console.log('SUMS TO:', writtenSize + size)
console.log('FILE SIZE BEFORE SLICE:', file.size);
const chunk = file.slice(writtenSize, writtenSize + size);
console.log('SIZE OF CHUNK TO WRITE', chunk.size);
writtenSize += size;
writer.write(chunk);
}
...
...
}
Output came to:
CALCULATED SIZE: 1048576
WRITTEN SIZE: 0
SUMS TO: 1048576
FILE SIZE BEFORE SLICE: 34012899
SIZE OF CHUNK TO WRITE 0
Further confirming the issue

Upload File with unknown size OneDrive

So I am uploading a file to one drive using a resumable file upload session. However I cannot know the size of the file before uploading. I know that google allows uploading of files with content ranges like
Content-Range: 0-128/*
I would assume OneDrive would also allow it as it is even specified in RFC2616
Content-Range = "Content-Range" ":" content-range-spec
content-range-spec = byte-content-range-spec
byte-content-range-spec = bytes-unit SP
byte-range-resp-spec "/"
( instance-length | "*" )
byte-range-resp-spec = (first-byte-pos "-" last-byte-pos)
| "*"
instance-length = 1*DIGIT
The header SHOULD indicate the total length of the full
entity-body, unless this length is unknown or difficult to
determine. The asterisk "*" character means that the
instance-length is unknown at the time when the response was
generated.
But after reading the OneDrive documentation I found it says
Example: In this example, the app is uploading the first 26 bytes of a
128 byte file.
The Content-Length header specifies the size of the current request.
The Content-Range header indicates the range of bytes in the overall
file that this request represents.
The total length of the file is
known before you can upload the first fragment of the file. HTTP
Copy PUT https://sn3302.up.1drv.com/up/fe6987415ace7X4e1eF866337
Content-Length: 26 Content-Range: bytes 0-25/128
<bytes 0-25 of the file>
Important: Your app must ensure the total
file size specified in the Content-Range header is the same for all
requests. If a byte range declares a different file size, the request
will fail.
Maybe I'm just reading the documentation wrong or it only applies to this example but before I go and build a entire uploader I would just like clarification if this is allowed for OneDrive
My Question is
Does OneDrive allow uploading of files with unknown sizes?
Thanks in advance for your help
For anyone else wondering, no you can't, file uploads must specify a size.

multiple file upload with maximum size in yii2

i am trying to upload multiple file at once,
my max_upload_size = 20 it works fine for total post size less than 20MB
[['fileUpload'], 'file','maxFiles' => 6]
but when i upload file greter than 20MB it shows me error message
i also handel exception in controller , but program execution not entring in controolers action
help me to solve this problem
You have to change following settings in php.ini file
; Maximum allowed size for uploaded files.
upload_max_filesize = 80M // set this as per your requirement
; Must be greater than or equal to upload_max_filesize
post_max_size = 80M // // set this as per your requirement
max_execution_time = 60 // time is in seconds
After modifying you need to restart your HTTP server to use apply configuration.

What to do about huge stacktrace.log file in grails

The project I'm working on has a stacktrace.log file that is over 160GB in space. This is killing my hardrive space. What can I do to avoid this.
You should use rolling file appender so that the log file does not grow that huge size.
Use configuration like:
rollingFile name:'stacktrace', file:'stacktrace.log',
maxFileSize:'100MB', maxBackupIndex:5
Here every log file will be maximum 100 MB. You can control how many previous file will be existed by 'maxBackupIndex'.
You can empty the existing huge file by(in linux)
cat /dev/null > /path/to/file/stacktrace.log

How to use MapFish print module for GeoServer-GeoWebCache layer?

I am in the process of developing a webGIS application using GeoServer (2.1.1), GeoWebCache(1.2.6), OpenLayers(2.11), GeoExt. All my layers are served as wms through GeoWebCache. A sample definition for any layer is as follows:
var My_Layer = new OpenLayers.Layer.WMS( "My_Layer",
"http://my-ip + my-port/geoserver/gwc/service/wms",
{layers: 'layer-name',transparent: "true",format: "image/png",
tileSize: new OpenLayers.Size(256,256),
tilesOrigin : map.maxExtent.left + ',' + map.maxExtent.bottom },
{ isBaseLayer: false, visibility:false} );
Everything was working fine, till this point. But, when I planned to move a bit ahead and tried implementing MapFish Printing module...... the output pdf is blank!!! I am getting the following error message:
java.io.IOException: Error (status=400) while reading the image
from........
I have searched a lot. According to this one option is to access my layers as TMS layer. But I don't want a static image layer, instead of a GeoServer WMS map layer.
Again another option found here is using OpenLayers.Control.ExportMap().
But that restricts using different scales, since my data extent is too big . As a result at a specific scale if user wants to take a print of the entire map area(may be in an A0 paper), which is not visible fully in the Openlayers div, this can not solve the purpose.
So the question is how can I accomplish this, without using a TMS or GeoWebCache layer?
Edit # 1 :
Sorry I am late, as I was out of office. Following is my config.yaml file. I feel there is no error, this can print my WMS layers, coming directly from GeoServer.
dpis: [75, 150, 300]
outputFormats:
- pdf
scales:
- 10000
- 25000
- 50000
- 100000
hosts:
- !localMatch
dummy: true
- !ipMatch
ip: www.camptocamp.org
- !dnsMatch
host: labs.metacarta.com
port: 80
- !dnsMatch
host: terraservice.net
port: 80
- !dnsMatch
host: sigma.openplans.org
- !dnsMatch
host: demo.mapfish.org
layouts:
A4 portrait:
metaData:
title: 'Arunava TopoMap PDF'
author: 'Arunava print module'
subject: 'Map layout'
keywords: 'map,print'
creator: 'Arunava'
mainPage:
pageSize: A4
rotation: true
items:
- !text
text: '${mapTitle} ${now MM.dd.yyyy}'
fontSize: 20
spacingAfter: 30
- !map
spacingAfter: 30
width: 440
height: 600
- !scalebar
type: bar
maxSize: 100
barBgColor: white
fontSize: 8
align: right
- !text
font: Helvetica
fontSize: 9
align: right
text: '1:${scale}'
footer: *commonFooter
A2 portrait:
metaData:
title: 'Arunava TopoMap PDF'
author: 'Arunava print module'
subject: 'Map layout'
keywords: 'map,print'
creator: 'Arunava'
mainPage:
pageSize: A2
rotation: true
items:
- !text
text: '${mapTitle} ${now MM.dd.yyyy}'
fontSize: 20
spacingAfter: 30
- !map
spacingAfter: 30
width: 880
height: 1200
- !scalebar
type: bar
maxSize: 100
barBgColor: white
fontSize: 8
align: right
- !text
font: Helvetica
fontSize: 9
align: right
text: '1:${scale}'
footer: *commonFooter
Without further debugging, the 400 error is too vague for much help. From experience, I can tell you I've seen an issue before where the geowebcache server doesn't like serving the wms layer you are requesting. Mapfish tries to do weird things with different tile sizes (and you eventually get a 10% threshold error). Does your log show the image it was requesting? Can you go to that tile in our browser to see what the server actually says? This is how I eventually exposed my issues.
For easier debugging, I've also created a seperate mapfish log to make it easier to find my mapfish issues. Use the Geoserver admin screen to figure out which logging profile you are using, then in that log4j.properties file, add a seperate file appender for mapfish, and direct all org.mapfish activity to it. This makes debugging much easier.
And FINALLY, my own personal crusade: in your config.yaml, don't use outputFormats: [pdf],
instead, use formats: ['pdf'].
Even though all the docs describe outputFormat (and that's what required in the client "spec"), the actual server config is uses the 'formats' variable. I've submitted a patch to make this more clear in the docs, but until then, let's this note be a guide. If you want to get into the image output, this is key.

Resources