-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Separate audit logs from server logs. #27443
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,8 +67,9 @@ public static function init() { | |
* @param string $app | ||
* @param string $message | ||
* @param int $level | ||
* @param string conditionalLogFile | ||
*/ | ||
public static function write($app, $message, $level) { | ||
public static function write($app, $message, $level, $conditionalLogFile = null) { | ||
$config = \OC::$server->getSystemConfig(); | ||
|
||
// default to ISO8601 | ||
|
@@ -110,8 +111,13 @@ public static function write($app, $message, $level) { | |
'user' | ||
); | ||
$entry = json_encode($entry); | ||
$handle = @fopen(self::$logFile, 'a'); | ||
@chmod(self::$logFile, 0640); | ||
if (!is_null($conditionalLogFile)) { | ||
$handle = @fopen($conditionalLogFile, 'a'); | ||
@chmod($conditionalLogFile, 0640); | ||
} else { | ||
$handle = @fopen(self::$logFile, 'a'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wow, did we really do a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yah. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hm what would happen if we keep the handle open until the request ends? I can only guess how that behaves when multiple processes write log messages. hmmm monolog also uses the file handle for the whole request (unless you call so we should be able to optimize our log writing ... @mrow4a ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. quoting official php documentation: (http://php.net/manual/en/function.fwrite.php)
(http://php.net/manual/en/function.fseek.php)
I'd keep the file opened and lock the file when writing (we can't guarantee the log entry to have less than 1k). In addition I've read somewhere the writes over NFS aren't atomic, so that another reason to lock the file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wouldn't that block other requests from writing log messages until the lock is released? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, but hopefully it won't be dramatic. The flow would be: open file to append and when we want to write a log entry, lock the file for writing - write - unlock. There is no need to open and close the file over and over. We could add an option to use locks or not over the log file if there is a noticeable performance impact. I expect some overhead, but hopefully not much. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm I fear locking will kill performance. What does google say? The log4php guys have a benchmark ... it is from 2009, but we could rerun it on todays php to see the numbers: https://www.grobmeier.de/performance-ofnonblocking-write-to-files-via-php-21082009.html running 4 scripts in parralel in the browser with 100000 loops in my vm with php 5.6 on debian produces:
so I think locking is the way to go ... in a different pr. @sharidas sorry for highjacking .. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, it's outside of scope for this PR. No need to change it right now. |
||
@chmod(self::$logFile, 0640); | ||
} | ||
if ($handle) { | ||
fwrite($handle, $entry."\n"); | ||
fclose($handle); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense that the "global" logger (aka, this class) tells the specific loggers where they have to write? Is it useful for any other logger (syslog, for example)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
impact on syslog - this was one of my questions above: #27443 (comment)
Not to complain if so, but necessay to know and document.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICT the syslog logger will ignore the logfile condition and always log to syslog.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Raises the question: shall this be enabled for syslog too, would that make sense?
In any case it needs a note in config.sample.php and/or the documentation.
aka:
Not applicapable when using syslog
, orThis also splits logs when using syslog
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@butonic can you check if logging to syslog will ignore logfile conditions?
This is important regarding proper documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd move the checks for the different logs files directly into the ownCloud log and keep the same "interface" for all the loggers. Basically, the ownCloud logger would read the log.conditions configuration and initialize itself properly (if possible).