Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ulsp: add a logger class #477

Merged
merged 1 commit into from
Sep 17, 2024
Merged

ulsp: add a logger class #477

merged 1 commit into from
Sep 17, 2024

Conversation

Jafaral
Copy link
Member

@Jafaral Jafaral commented Sep 16, 2024

This adds a general logging class that I hope to move to the library. For now keeping it and using it in ulsp.

example run

./ulsp --socket 12345 --logfile ulsp.log 

@Jafaral Jafaral requested a review from Don-Ward September 16, 2024 05:46
Copy link
Collaborator

@Don-Ward Don-Ward left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are probably as many ways to write a logger class as there are authors of such classes. Many choices are a matter of style (and here is not really the place to debate them). We can probably take the experience we get from using this class and feed it into the creatiion of a library logging class. The two changes I would ask for is that the more important/critical messages are immediately flushed, to avoid any danger of them being lost. The second change is to make the class thread safe so logging messages that are the result of a single use of the class come out together rather than being interspersed with other concurrent logging usage: there are already comments in the ulsp source about using threads, so we might as well get this right to start with.

@Jafaral Jafaral force-pushed the ulsp-log branch 2 times, most recently from bd82141 to 7aa1b37 Compare September 16, 2024 22:07
@Jafaral
Copy link
Member Author

Jafaral commented Sep 16, 2024

@Don-Ward I agree. Those are good suggestions, but I'm trying to get something going in the short term. I updated the PR to allow defining debug classes/filters. I added a c command line option just as an example, with a couple of debug message use case for demonstration purposes. A log message will be printed if the log level is high enough for it to be printed, or it matches a calls/filter. Filter supports sub-classes too. Ex:

jafar@jtr:ulsp$ ./ulsp --socket 12345 -s --debugfilter "db:path"
[debug:db:path]  /home/jafar/unicon/ipl/lib
[debug:db:path]  /home/jafar/unicon/uni/lib
[debug:db:path]  /home/jafar/unicon/uni/gui
[debug:db:path]  /home/jafar/unicon/uni/xml
[debug:db:path]  /home/jafar/unicon/uni/3d
[debug:db:path]  /home/jafar/unicon/plugins/lib
[debug:db:path]  /home/jafar/unicon/ipl/procs
[debug:db:path]  /home/jafar/unicon/uni/unidoc
^C
shutdown signal received! Server Shutting down...
jafar@jtr:ulsp$ ./ulsp --socket 12345 -s --debugfilter "db"
[debug:db]Looking in 1
[debug:db:path]  /home/jafar/unicon/ipl/lib
[debug:db:path]  /home/jafar/unicon/uni/lib
[debug:db:path]  /home/jafar/unicon/uni/gui
[debug:db:path]  /home/jafar/unicon/uni/xml
[debug:db:path]  /home/jafar/unicon/uni/3d
[debug:db:path]  /home/jafar/unicon/plugins/lib
[debug:db:path]  /home/jafar/unicon/ipl/procs
[debug:db:path]  /home/jafar/unicon/uni/unidoc
^C
shutdown signal received! Server Shutting down...
jafar@jtr:ulsp$ ./ulsp --socket 12345 -s --debugfilter "db" --loglevel 10
[info]Loading Database...
[debug:db]Looking in 1
[debug:db:path]  /home/jafar/unicon/ipl/lib
[debug:db:path]  /home/jafar/unicon/uni/lib
[debug:db:path]  /home/jafar/unicon/uni/gui
[debug:db:path]  /home/jafar/unicon/uni/xml
[debug:db:path]  /home/jafar/unicon/uni/3d
[debug:db:path]  /home/jafar/unicon/plugins/lib
[debug:db:path]  /home/jafar/unicon/ipl/procs
[debug:db:path]  /home/jafar/unicon/uni/unidoc
[info]Starting Unicon LSP in server mode at :12345

Signed-off-by: Jafar Al-Gharaibeh <[email protected]>
@Jafaral
Copy link
Member Author

Jafaral commented Sep 17, 2024

I made further updates, changing the filtering logic based on testing I did. I also changed "filter" to "class". Log level now much be 8+ for filters to work, I.e, debugging must be enabled. I added flush, but chose to ignore threads for now. The class is a bit thread "friendly" already, but it is good to add support so that each log is written out to all log destinations from one thread before processing a new log request.

jafar@mac16 ulsp % ./ulsp --socket 12345 --loglevel 8 --debug-class "db:path:package"
[info] Loading Database...
[debug3:db:path:package] Processing (main)
[debug3:db:path:package] Processing doptions
[debug3:db:path:package] Processing exception
[debug3:db:path:package] Processing lang

@Jafaral
Copy link
Member Author

Jafaral commented Sep 17, 2024

example log file

./ulsp --socket 12345 --loglevel 8 --debug-class "db:path" --logfile /tmp/ulsp.log

jafar@mac16 ulsp % cat /tmp/ulsp.log 
[2024/09/17 00:36:21][info] Loading Database...
[2024/09/17 00:36:21][debug2:db:path] Processing /Users/jafar/proj/unicon/ipl/lib
[2024/09/17 00:36:21][debug2:db:path] Processing /Users/jafar/proj/unicon/uni/lib
[2024/09/17 00:36:23][debug2:db:path] Processing /Users/jafar/proj/unicon/uni/gui
[2024/09/17 00:36:23][debug2:db:path] Processing /Users/jafar/proj/unicon/uni/xml
[2024/09/17 00:36:24][debug2:db:path] Processing /Users/jafar/proj/unicon/uni/3d
[2024/09/17 00:36:24][debug2:db:path] Processing /Users/jafar/proj/unicon/plugins/lib
[2024/09/17 00:36:24][debug2:db:path] Processing /Users/jafar/proj/unicon/ipl/procs
[2024/09/17 00:36:26][debug2:db:path] Processing /Users/jafar/proj/unicon/uni/unidoc
[2024/09/17 00:36:26][info] Starting Unicon LSP in server mode at 127.0.0.1:12345
[2024/09/17 00:36:31][notice] 
shutdown signal received! Server Shutting down...

@Don-Ward Don-Ward merged commit 6e291aa into uniconproject:master Sep 17, 2024
20 checks passed
ValG4 pushed a commit to ValG4/unicon that referenced this pull request Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants