The PHP IDS system expose uses Monolog to store logs into MongoDB. The following is how it stores a log:
{
"message": "Executing on data 4f2793132469524563fa9b46207b21ee",
"context": [
],
"level": NumberLong(200),
"level_name": "INFO",
"channel": "audit",
"datetime": "1441721696",
"extra": [
]
}
I want to use the auto-delete function in Mongo, and I need the datetime
field to store in ISOdate format, like this:
"datetime":ISODate("2015-09-08T17:43:25.678Z")
I look at the class Mongo
in \Expose\Log\Mongo();
and this is the part responsible for storing the datetime
in seconds format
public function log($level, $message, array $context = array())
{
$logger = new \Monolog\Logger('audit');
try {
$handler = new \Monolog\Handler\MongoDBHandler(
new \MongoClient($this->getConnectString()),
$this->getDbName(),
$this->getDbCollection()
);
} catch (\MongoConnectionException $e) {
throw new \Exception('Cannot connect to Mongo - please check your server');
}
$logger->pushHandler($handler);
$logger->pushProcessor(function ($record) {
$record['datetime'] = $record['datetime']->format('U');
return $record;
});
return $logger->$level($message, $context);
}
I have changed the $record['datetime'] into this
//$record['datetime'] = $record['datetime']->format('U');
$record['datetime'] = new \MongoDate();;
but the time isn't store as ISOdate but this:
"datetime": "[object] (MongoDate: 0.84500000 1441721683)"
Can anyone tell me how to store the datetime
in ISODate format?