Skip to content

Commit 939709d

Browse files
committed
adds syslog example
1 parent 1101142 commit 939709d

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

appengine/standard/logging/phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<filter>
2727
<whitelist>
2828
<file>index.phpfile>
29+
<file>syslog.phpfile>
2930
whitelist>
3031
filter>
3132
phpunit>

appengine/standard/logging/syslog.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
3+
$user_is_authorized = !empty($_GET['authorized']);
4+
5+
# [START syslog]
6+
if ($user_is_authorized) {
7+
syslog(LOG_INFO, 'Authorized access');
8+
echo 'true';
9+
} else {
10+
syslog(LOG_WARNING, 'Unauthorized access');
11+
echo 'false';
12+
}
13+
# [END syslog]

appengine/standard/logging/test/loggingTest.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function testSomeLogs()
6161
include __DIR__ . '/../index.php';
6262
$result = ob_get_contents();
6363
ob_end_clean();
64-
// Make sure it looks like Shakespeare.
64+
6565
$this->assertContains('127.0.0.1', $result);
6666
$this->assertContains('log-status-1', $result);
6767
$this->assertContains('log-method-1', $result);
@@ -70,4 +70,24 @@ public function testSomeLogs()
7070
$this->assertContains('applog-message-1', $result);
7171
$this->assertContains($d2->format('c'), $result);
7272
}
73+
74+
public function testSyslog()
75+
{
76+
// not authorized
77+
ob_start();
78+
include __DIR__ . '/../syslog.php';
79+
$result = ob_get_contents();
80+
ob_end_clean();
81+
82+
$this->assertEquals('false', $result);
83+
84+
// authorized
85+
$_GET['authorized'] = 1;
86+
ob_start();
87+
include __DIR__ . '/../syslog.php';
88+
$result = ob_get_contents();
89+
ob_end_clean();
90+
91+
$this->assertEquals('true', $result);
92+
}
7393
}

0 commit comments

Comments
 (0)