Skip to content

Conversation

HofiOne
Copy link
Collaborator

@HofiOne HofiOne commented Apr 12, 2023

system(), darwin-oslog(), darwin-oslog-stream() sources: Added 2 darwin OSLog based sources darwin-oslog() and darwin-oslog-stream().

'darwin-oslog()' replaced the earlier file source based solution with a native OSLog framework based one, and is automatically used in the system() source on darwin platform if the darwinosl plugin is presented.

This plugin available only on macOS 10.15 Catalina and above, the first version that has the OSLog API.

darwin-oslog

This is a native OSLog Framework based source to read logs from the local store of the unified logging system on darwin OSes.
For more info, see https://developer.apple.com/documentation/oslog?language=objc

The following parameters can be used for customization:

  • filter-predicate
  • go-reverse
    • boolean value, setting to yes will provide a reverse-ordered log list (from latest to oldest)
    • default value: no
  • do-not-use-bookmark
    • boolean value, setting to yes will prevent syslog-ng from continuing to feed the logs from the last remembered position after a (re-)start, which means, depending on the other settings, the feed will always start from the end/beginning of the available log list
    • default value: no, which means syslog-ng will attempt to continue feeding from the last remembered log position after a (re-)start
  • max-bookmark-distance
    • integer value, maximum distance in seconds that far an earlier bookmark can point backward, e.g. if syslog-ng was stopped for 10 minutes and max-bookmark-distance is set to 60 then syslog-ng will start feeding the logs only from the last 60 seconds at startup, 9 minutes of logs 'will be lost'
    • default value: 0, which means no limit
  • read-old-records
    • boolean value, controls if syslog-ng should start reading logs from the oldest available at first start (or if no bookmark can be found)
    • default value: yes
  • fetch-delay
    • integer value, controls how much time syslog-ng should wait between reading/sending log messages, this is a fraction of a second, where wait_time = 1 second / n, so, e.g. n=1 means that only about 1 log will be read and sent in each second, and n=1 000 000 means only 1 microsecond (the allowed minimum value now!) will be the delay between read/write attempts
      (Use with care, though lower delay time can increase log feed performance, at the same time could lead to a heavy system load!)
    • default value: 10 000
  • fetch-retry-delay
    • integer value, controls how many seconds syslog-ng will wait before a repeated attempt to read/send once it's out of available logs
    • default value: 1
  • log-fetch-limit
    • Warning: This option is now disabled due to an OSLog API bug (https://openradar.appspot.com/radar?id=5597032077066240), once it's fixed it will be enabled again
    • integer value, that limits the number of logs syslog-ng will send in one run
    • default value: 0, which means no limit

NOTE: the persistent OSLog store is not infinite, depending on your system setting usually, it keeps about 7 days of logs on disk, so it could happen that the above options cannot operate the way you expect, e.g. if syslog-ng was stopped for about more then a week it could happen that will not be able to restart from the last saved bookmark position (as that might not be presented in the persistent log anymore)

darwin-oslog-stream

This is a wrapper around the OS command line "log stream" command that can provide a live log stream feed.
Unlike in the case of darwin-oslog() the live stream can contain non-persistent log events too, so take care, there might be a huge number of log events every second that could put an unusual load on the device running syslog-ng with this source.
Unfortunately, there's no public API to get the same programmatically, so this one is implemented using a program() source.

Possible parameters:

  • params
    • a string that can contain all the possible params the macOS log tool can accept, please see, log --help stream for full reference, and man log for more details.

      IMPORTANT: the parameter --style is used internally (defaults to ndjson), so it cannot be overridden, please use other sysylog-ng features (templates, rewrite rules, etc.) for final output formatting

    • default value: --type log --type trace --level info --level debug, you can use `def-osl-stream-params` for referencing it if you wish to keep the defaults when you add your own

Signed-off-by: Hofi hofione@gmail.com

@HofiOne HofiOne force-pushed the Native-macOS-system-source-4212 branch from 1d73574 to 0da1cef Compare April 12, 2023 12:51
@HofiOne HofiOne linked an issue Apr 13, 2023 that may be closed by this pull request
@HofiOne HofiOne force-pushed the Native-macOS-system-source-4212 branch 3 times, most recently from 1e3f048 to 4b8bec2 Compare April 15, 2023 20:51
@czanik
Copy link
Collaborator

czanik commented Apr 18, 2023

Tested both drivers on my MacBook, including some of the parameters, and they worked as expected. My favorite parameter was: read-old-records(no), as this way syslog-ng did not try to read millions of logs from mid March :-)

@HofiOne HofiOne force-pushed the Native-macOS-system-source-4212 branch from 4b8bec2 to 79acf07 Compare April 20, 2023 08:49
@HofiOne HofiOne marked this pull request as ready for review April 20, 2023 09:26
HofiOne added a commit to HofiOne/syslog-ng that referenced this pull request Apr 20, 2023
Signed-off-by: Hofi <hofione@gmail.com>
HofiOne added a commit to HofiOne/syslog-ng that referenced this pull request Apr 20, 2023
Signed-off-by: Hofi <hofione@gmail.com>
@HofiOne HofiOne force-pushed the Native-macOS-system-source-4212 branch from 6189a4e to f171bfc Compare April 20, 2023 09:40
HofiOne added a commit to HofiOne/syslog-ng that referenced this pull request Apr 20, 2023
Signed-off-by: Hofi <hofione@gmail.com>
@HofiOne HofiOne force-pushed the Native-macOS-system-source-4212 branch from f171bfc to 22f24a4 Compare April 20, 2023 15:49
HofiOne added a commit to HofiOne/syslog-ng that referenced this pull request Apr 24, 2023
Signed-off-by: Hofi <hofione@gmail.com>
@HofiOne HofiOne force-pushed the Native-macOS-system-source-4212 branch from 22f24a4 to 2b832f0 Compare April 24, 2023 08:52
HofiOne added a commit to HofiOne/syslog-ng that referenced this pull request Apr 25, 2023
Signed-off-by: Hofi <hofione@gmail.com>
@HofiOne HofiOne force-pushed the Native-macOS-system-source-4212 branch from 2b832f0 to a11ba9d Compare April 25, 2023 10:46
@syslog-ng syslog-ng deleted a comment from kira-syslogng Apr 25, 2023
@syslog-ng syslog-ng deleted a comment from kira-syslogng Apr 25, 2023
HofiOne added a commit to HofiOne/syslog-ng that referenced this pull request Apr 25, 2023
Signed-off-by: Hofi <hofione@gmail.com>
@HofiOne HofiOne force-pushed the Native-macOS-system-source-4212 branch from a11ba9d to 6fad7a7 Compare April 25, 2023 11:42
@syslog-ng syslog-ng deleted a comment from kira-syslogng Apr 25, 2023
@syslog-ng syslog-ng deleted a comment from kira-syslogng Apr 25, 2023
@HofiOne
Copy link
Collaborator Author

HofiOne commented Apr 25, 2023

@kira-syslogng test this please;

@HofiOne HofiOne force-pushed the Native-macOS-system-source-4212 branch 4 times, most recently from 5e2b652 to ed0fb7d Compare January 11, 2024 12:00
Copy link
Collaborator

@kovgeri01 kovgeri01 left a comment

Choose a reason for hiding this comment

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

I created the issue #4786 that stands for adding the generic metrics (or some of the metrics) here to the LogThreadedSourceDriver as it would be potentially quite huge of a change impacting multiple modules.As for the code and the documentation it is fine by me. (Also it looks like that based on our discussions that the ObjC exception only escapes the catch clause when compiled in debug mode, and youve made it so that an actual error will be shown inside the configuration file if the predicate has invalid syntax)

With this I approve youre PR hopefully @bazsi @alltilla it is fine by you

Signed-off-by: Hofi <hofione@gmail.com>
…port

Signed-off-by: Hofi <hofione@gmail.com>
Signed-off-by: Hofi <hofione@gmail.com>
- This is a wrapper around the OS command line "log stream" command that can provide live log stream feed, unfortunately, there's no public API to get the same programmatically
- darwin-oslog defaults are not duplicated anymore
- Added default filter predicate to darwin-oslog
Signed-off-by: Hofi <hofione@gmail.com>
Signed-off-by: Hofi <hofione@gmail.com>
… C++ and ObjC modules that could lead further libtool issues

Note, the original error was

libtool: link: unable to infer tagged configuration
libtool:   error: specify a tag with '--tag'

though the --tag CC is already presented in the config files
Needs further investigation, but for now this will solve the issue in most of the cases.

Signed-off-by: Hofi <hofione@gmail.com>
…ctly

- forcing usage of clang for ObjC code now both in autotools and cmake compilations

Signed-off-by: Hofi <hofione@gmail.com>
…-worker

Signed-off-by: Hofi <hofione@gmail.com>
…changes

Signed-off-by: Hofi <hofione@gmail.com>
…e Makefile

Signed-off-by: Hofi <hofione@gmail.com>
Signed-off-by: Hofi <hofione@gmail.com>
Signed-off-by: Hofi <hofione@gmail.com>
Signed-off-by: Hofi <hofione@gmail.com>
…g parsing phase

NOTE: This one still cannot prevent syslog-ng to crash on certain filter predicate parsing issues, this I consider as an Apple bug, anyway, it crashes at least immediately during config parsing not at runtime now :S

Signed-off-by: Hofi <hofione@gmail.com>
… darwin-oslog-stream source

- Release note is updated as well

Signed-off-by: Hofi <hofione@gmail.com>
@HofiOne HofiOne force-pushed the Native-macOS-system-source-4212 branch from ed0fb7d to 05d03a5 Compare January 11, 2024 21:20
@HofiOne HofiOne merged commit c08f282 into syslog-ng:master Jan 11, 2024
@HofiOne HofiOne deleted the Native-macOS-system-source-4212 branch January 11, 2024 21:57
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.

Native macOS system() source support to syslog-ng
6 participants