Coder Social home page Coder Social logo

Comments (11)

7max avatar 7max commented on July 2, 2024

Can you evaluate the following forms and paste the output?

(log:config)
(list
   (find :bordeaux-threads *features*)
   log4cl-impl::*watcher-thread*
   (slot-value (log4cl-impl::current-hierarchy) 
               'log4cl-impl::watch-tokens)      
   (log4cl-impl::effective-appenders log4cl-impl:*root-logger*))

from log4cl.

avodonosov avatar avodonosov commented on July 2, 2024

done, see here: http://paste.lisp.org/display/130667

from log4cl.

7max avatar 7max commented on July 2, 2024

A few things to try

1. Does this workaround fix it?

(log:config :daily log-file :immediate-flush)

If above workaround does not work, something is really strange going on. Can you then do (trace finish-output) and issue some log statements, there should be calls to finish-output on the log file after every log statement.. They look like so in my Slime

0: (FINISH-OUTPUT #<SB-SYS:FD-STREAM for "file /home/max/projects/lisp/log4cl/tests/file.txt" {108635DAF3}>)

Note you will also be getting them for console stream too.

If above work workaround does work, can you do the following two experiments:

2 Check that hierarchy watcher is in fact doing its thing.

(trace log4cl-impl::watch-token-check)

... there should be a bunch of output in *inferior-lisp* buffer showing that its being called every second, the argument being the file appender

(untrace) to remove it

3 Verify finish-output gets called

  1. Reconfigure to remove console-appender, with just file (log:config :sane :daily log-file)
  2. (trace finish-output)
  3. Do a loop issuing a bunch of log statements in a loop like so (dotimes (i 2000) (log:info "iteration ~d" i))

There should be (finish-output) for the log file, either in REPL, or in the *inferior-lisp* (from the watcher thread auto-flushing)..

You need to adjust the number of log messages in the loop, so that outputting them takes longer then 2-3 seconds, so that autoflusher thread has a chance to run...

If there are no FINISH-OUTPUT shown in *inferior-lisp* something is definitely screwed up with log4cl logic

If FINISH-OUTPUT do show up, but it still seems like last few messages are getting buffered, how do you test it? do you "tail -f" the log file? Also what is the filesystem.

from log4cl.

avodonosov avatar avodonosov commented on July 2, 2024

The workaround helps. I am not performing the remaining experiments, because the reason is obvious: my program exits and the hierarchy watcher do not have chance to flush the log statements issued during the last 1 second.

(Note, the issue is only with two last log statements, and the key point that the program exits after it's work is done).

from log4cl.

avodonosov avatar avodonosov commented on July 2, 2024

Maybe :auto-flush should be the default? I do not remember that I had such issues with log4j. Either they do autoflush, or set Runtime.addShutdownHook, but shutdown hooks are not guaranteed to execute if JVM crashes, so autoflush seems more reliable.

from log4cl.

7max avatar 7max commented on July 2, 2024

Ok I seem to understand the problem now, if your program does (exit) before autoflusher had a chance to run, then FINISH-OUTPUT probably never gets called.

The reason autoflush is not default like with Log4J, is that I feel Log4CL default setting is better solution then Log4J with immediateFlush turned off.. It gives almost the same performance as Log4J, but unlike it ensures that there is no stale statements in the log file older then log4cl-impl::*hierarchy-watcher-heartbeat* seconds.. Obviously with exception of the corner case we had just discovered, of a program exiting before that time.

Since Lisp is generally used with long-running processes, I'd like to keep the default that provides best performance, and try to fix the process exiting special case.

from log4cl.

avodonosov avatar avodonosov commented on July 2, 2024

Well, it's a questionable solution, but I do not insist (I just use :immediate-flush in my config). Feel free to close the issue.

Some ideas:
Maybe a function like log:flush may be added to the public API which ensures everything is written?
One could add it in the end of his MAIN function (in unwind-protect).

Also, maybe instead of looping with 1 second interval, some wait/signal scheme will be more reliable and, hopefully, will have the same performance. I mean bordeaux-threads:condition-wait, bordeaux-threads:condition-notify.

from log4cl.

7max avatar 7max commented on July 2, 2024

I'd like to also point out, that log file switch at midnight happens when log statement is issued, and the current day is different from the day when previous log statement was issued.

For the short-running script program, it will be unlikely that program runs exactly at midnight and issues two log statements on different days, so log switch will not happen..

You can fix it by giving adding the %Y%m%d to the file name, which will use timestamp in the current log file name, althought this makes it difficult to tail -f the current log file, as you need to figure out the current one.

I think its possible to fix it, by checking the file modification time when we first open the file, and checking if we need to rename the log file at that time, so I'll try to fix this in the next version.

from log4cl.

avodonosov avatar avodonosov commented on July 2, 2024

Thanks for the info, I already had some suspicions about this. But it didn't bothered me too much.

from log4cl.

7max avatar 7max commented on July 2, 2024

I like the public API idea, will likely be called log:flush-all-appeders

from log4cl.

7max avatar 7max commented on July 2, 2024

LOG4CL:FLUSH-ALL-APPENDERS API added in version v1.1.0.

Under SBCL it is called from EXIT-HOOKS

from log4cl.

Related Issues (20)

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.