Giter Site home page Giter Site logo

Comments (2)

MFlisar avatar MFlisar commented on May 25, 2024 1

I just made an update and extracted some logic of the daily setup into a base class that can be reused by new setups.

Check out the current existing implemtations:

override fun getFileKey(data: FileLogger.Event.Data, lastPath: String): String {
date.time = data.time
val key = timeFormatter.format(date)
return key
}

override fun getFileKey(data: FileLogger.Event.Data, lastPath: String): String {
if (fileIndex == null) {
// we must find out what the highest existing log file index currently is
fileIndex =
getAllExistingLogFiles().lastOrNull()?.let { getKeyFromFile(it).toIntOrNull() }
?: 1
}
if (lastPath.isEmpty()) {
return fileIndex.toString()
}
val bytes = File(lastPath).takeIf { it.exists() }?.length()
if ((bytes ?: 0L) >= maxFileSizeInBytes) {
fileIndex = fileIndex!! + 1
}
return fileIndex.toString()
}

Suggestion

I do pass in FileLogger.Event.Data to the getFileKey function now, this allows you to decide which file name is the correct one based on this data, it should contain everything you need to make your decision. The base setup will create log files based on the file key like following:

I would do following:

  • create your own setup implementation
  • derive a key from the class name
  • be aware, that the logging implemention in the background will close/open log files whenever the key changes - everthing is done on a backgroud thread, still keep that in mind

I don't know why you really need files for each class, maybe think about using multiple instances of FileLoggers and add some filter to them 'FileLogger(setup, filter = ...)`?

from lumberjack.

AlexandruDev avatar AlexandruDev commented on May 25, 2024

Thank you @MFlisar, I managed to create a different log file for the activity responsible with the incoming/outgoing calls and a separate one for the entire app.

I'l close this.

from lumberjack.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.