Comments (3)
Additional info, after more testing: appears to be related to the .targetMaxLogFiles
setting and how it gets applied. Sometimes rolling allows more files, sometimes not (deleting files, even though count is still well under target max).
I have a test run in front of me where the max files is set to 15, and after logging system init, there are 11 files. The app runs for a while, generating more data, then observe log directory and (a) it has generated 6 new rolled log files, but (b) there are only 13 files.
So started with 11, added 6 (11 + 6 = 17 files involved).
But when those 6 rolled files were added, 4 old files were dropped (11 + 6 added - 4 dropped = 13 left).
With my .targetMaxLogFiles = 15
I expected to see 15 files (11 + 6 new - 2 dropped = 15).
My guess is that dropping old files is (as the parameter name suggests) done in a fuzzy-batching kind of way where once the code sees the number of log files is getting "too many" it deletes "some" files. Not a predictable number. Just "some" to get the count back under the target maximum.
But... if that's what's happening, it's pretty severe as I found in an additional test case:
I initialized the autorotating file destination with:
let file = AutoRotatingFileDestination(writeToFile: LogFactory.logsFileURL(named: config.filename), shouldAppend: true)
file.targetMaxFileSize = config.suggestedMaxFileBytes // 300k
file.targetMaxLogFiles = config.suggestedMaxFiles // 10 files
Since I set my values after the constructor, the constructor should initially have set things up with defaults, which (looking at the code) are 10 files each 1 mb (1024k).
BUT... that produced a VERY unexpected result:
At APP LAUNCH
At: /var/mobile/Containers/Data/Application/23B87F74-3D06-4BE7-A270-FA188D03A9B8/Documents/logs:
backup.log | 48942 (49 KB) 2020-11-02 11:06:07
backup_2020-11-02_110607.log | 16729 (17 KB) 2020-11-02 10:57:37
At LOGS INIT start
At: /var/mobile/Containers/Data/Application/23B87F74-3D06-4BE7-A270-FA188D03A9B8/Documents/logs:
backup.log | 48942 (49 KB) 2020-11-02 11:06:07
backup_2020-11-02_110607.log | 16729 (17 KB) 2020-11-02 10:57:37
At LOGS INIT end
At: /var/mobile/Containers/Data/Application/23B87F74-3D06-4BE7-A270-FA188D03A9B8/Documents/logs:
backup.log | 762 (762 bytes) 2020-11-02 11:35:25
backup_2020-11-02_113525.log | 48942 (49 KB) 2020-11-02 11:06:07
Rather than keeping the two starting log files, it kept one and deleted the other. If the default params are to keep 10 1mb files, how could XCGLogger have decided this was right ??
from xcglogger.
Added info:
-
there are multiple log streams going to the logs directory (a general.log, a backup.log, a database.log, etc... all creating their own rolled files). I'm not certain, given code read, that the AutoRotatingFileDestination.archivedFileURLs() function is handling this right. Might be counting too many files. Unclear. I may be wrong.
-
Possibly related to #1: I'm not specifying an identifier when creating the AutoRotatingFileDestination(). This may be causing issues as identifier appears to be stored in extended attributes of file in filesystem, and reading this back is the means of identifying which files are "part of the same set" in determining if there's too many files and deletes are needed. As I have multiple file sources all going to the same directory, and all with blank (default) .identifier property, I think this means all the files will get counted as part of every "rotate and archive" set, rather than being based on filename, which is what I'd expected.
-
I was not specifying a maxTimeInterval parameter in creating the AutoRotatingFileDestination. This caused the (somewhat odd) default of 10 minutes to be used. (Who needs to start a new log every 10 min??). So this was causing force-rotate-on-startup effect as it was often 10 minutes between one run and another, given me futzing with code and writing new test stuff in between.
from xcglogger.
My problems were ultimately due to not using critical parameter values.
I have added code documentation that would have helped me, and created a pull requests from it (no changes other than code comments). Pull request: #311
from xcglogger.
Related Issues (20)
- Crash on FileDestination.write
- Crash-protocol witness for XCGLogger.DestinationProtocol.process(logDetails: XCGLogger.LogDetails) -> () in conformance XCGLogger.BaseDestination : XCGLogger.DestinationProtocol in XCGLogger <compiler-generated> HOT 1
- Is there a way to generate files and write them the first time you debug? HOT 1
- log level implementation incomplete? HOT 2
- How to display the test results with XCGLogger and XCUITest
- Hi, when I use logger to output logs to the console, the logs are not displayed completely, but the output to the file is normal. Where can I set it?
- Cannot convert value of type '(UnsafeMutableRawBufferPointer) -> Int' to expected argument type '(UnsafeMutablePointer<_>) -> _'
- Module Stability (Swift 5.1) HOT 3
- #file becomes #filePath in Swift 5.3, #file will now just be the fileName HOT 3
- framework not found Log HOT 1
- The end of the file log has "[m" HOT 2
- Type of Logger
- Crash on Linux
- XcodeColorsLogFormatter not working HOT 3
- Has it been updated for more than a year? HOT 1
- file size
- Version 4.0 does not work with Xcode 13 anymore HOT 1
- How Can I color with font HOT 1
- Supporting Windows platforms?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xcglogger.