PageRenderTime 55ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/Cake/Test/Case/Log/CakeLogTest.php

https://bitbucket.org/pyroka/hms
PHP | 676 lines | 470 code | 84 blank | 122 comment | 19 complexity | 1e28d6f8b4c01a20cce690c4efb35350 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /**
  3. * CakeLogTest file
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
  8. * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * Redistributions of files must retain the above copyright notice
  12. *
  13. * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
  15. * @package Cake.Test.Case.Log
  16. * @since CakePHP(tm) v 1.2.0.5432
  17. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  18. */
  19. App::uses('CakeLog', 'Log');
  20. App::uses('FileLog', 'Log/Engine');
  21. /**
  22. * CakeLogTest class
  23. *
  24. * @package Cake.Test.Case.Log
  25. */
  26. class CakeLogTest extends CakeTestCase {
  27. /**
  28. * Start test callback, clears all streams enabled.
  29. *
  30. * @return void
  31. */
  32. public function setUp() {
  33. parent::setUp();
  34. $streams = CakeLog::configured();
  35. foreach ($streams as $stream) {
  36. CakeLog::drop($stream);
  37. }
  38. }
  39. /**
  40. * test importing loggers from app/libs and plugins.
  41. *
  42. * @return void
  43. */
  44. public function testImportingLoggers() {
  45. App::build(array(
  46. 'Lib' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Lib' . DS),
  47. 'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
  48. ), App::RESET);
  49. CakePlugin::load('TestPlugin');
  50. $result = CakeLog::config('libtest', array(
  51. 'engine' => 'TestAppLog'
  52. ));
  53. $this->assertTrue($result);
  54. $this->assertEquals(CakeLog::configured(), array('libtest'));
  55. $result = CakeLog::config('plugintest', array(
  56. 'engine' => 'TestPlugin.TestPluginLog'
  57. ));
  58. $this->assertTrue($result);
  59. $this->assertEquals(CakeLog::configured(), array('libtest', 'plugintest'));
  60. CakeLog::write(LOG_INFO, 'TestPluginLog is not a BaseLog descendant');
  61. App::build();
  62. CakePlugin::unload();
  63. }
  64. /**
  65. * test all the errors from failed logger imports
  66. *
  67. * @expectedException CakeLogException
  68. * @return void
  69. */
  70. public function testImportingLoggerFailure() {
  71. CakeLog::config('fail', array());
  72. }
  73. /**
  74. * test config() with valid key name
  75. *
  76. * @return void
  77. */
  78. public function testValidKeyName() {
  79. CakeLog::config('valid', array('engine' => 'FileLog'));
  80. $stream = CakeLog::stream('valid');
  81. $this->assertInstanceOf('FileLog', $stream);
  82. CakeLog::drop('valid');
  83. }
  84. /**
  85. * test config() with invalid key name
  86. *
  87. * @expectedException CakeLogException
  88. * @return void
  89. */
  90. public function testInvalidKeyName() {
  91. CakeLog::config('1nv', array('engine' => 'FileLog'));
  92. }
  93. /**
  94. * test that loggers have to implement the correct interface.
  95. *
  96. * @expectedException CakeLogException
  97. * @return void
  98. */
  99. public function testNotImplementingInterface() {
  100. CakeLog::config('fail', array('engine' => 'stdClass'));
  101. }
  102. /**
  103. * Test that CakeLog autoconfigures itself to use a FileLogger with the LOGS dir.
  104. * When no streams are there.
  105. *
  106. * @return void
  107. */
  108. public function testAutoConfig() {
  109. if (file_exists(LOGS . 'error.log')) {
  110. unlink(LOGS . 'error.log');
  111. }
  112. CakeLog::write(LOG_WARNING, 'Test warning');
  113. $this->assertTrue(file_exists(LOGS . 'error.log'));
  114. $result = CakeLog::configured();
  115. $this->assertEquals(array('default'), $result);
  116. $testMessage = 'custom message';
  117. CakeLog::write('custom', $testMessage);
  118. $content = file_get_contents(LOGS . 'custom.log');
  119. $this->assertContains($testMessage, $content);
  120. unlink(LOGS . 'error.log');
  121. unlink(LOGS . 'custom.log');
  122. }
  123. /**
  124. * test configuring log streams
  125. *
  126. * @return void
  127. */
  128. public function testConfig() {
  129. CakeLog::config('file', array(
  130. 'engine' => 'FileLog',
  131. 'path' => LOGS
  132. ));
  133. $result = CakeLog::configured();
  134. $this->assertEquals(array('file'), $result);
  135. if (file_exists(LOGS . 'error.log')) {
  136. @unlink(LOGS . 'error.log');
  137. }
  138. CakeLog::write(LOG_WARNING, 'Test warning');
  139. $this->assertTrue(file_exists(LOGS . 'error.log'));
  140. $result = file_get_contents(LOGS . 'error.log');
  141. $this->assertRegExp('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Warning: Test warning/', $result);
  142. unlink(LOGS . 'error.log');
  143. }
  144. /**
  145. * explicit tests for drop()
  146. *
  147. * @return void
  148. **/
  149. public function testDrop() {
  150. CakeLog::config('file', array(
  151. 'engine' => 'FileLog',
  152. 'path' => LOGS
  153. ));
  154. $result = CakeLog::configured();
  155. $this->assertEquals(array('file'), $result);
  156. CakeLog::drop('file');
  157. $result = CakeLog::configured();
  158. $this->assertEquals(array(), $result);
  159. }
  160. /**
  161. * testLogFileWriting method
  162. *
  163. * @return void
  164. */
  165. public function testLogFileWriting() {
  166. if (file_exists(LOGS . 'error.log')) {
  167. unlink(LOGS . 'error.log');
  168. }
  169. $result = CakeLog::write(LOG_WARNING, 'Test warning');
  170. $this->assertTrue($result);
  171. $this->assertTrue(file_exists(LOGS . 'error.log'));
  172. unlink(LOGS . 'error.log');
  173. CakeLog::write(LOG_WARNING, 'Test warning 1');
  174. CakeLog::write(LOG_WARNING, 'Test warning 2');
  175. $result = file_get_contents(LOGS . 'error.log');
  176. $this->assertRegExp('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Warning: Test warning 1/', $result);
  177. $this->assertRegExp('/2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Warning: Test warning 2$/', $result);
  178. unlink(LOGS . 'error.log');
  179. }
  180. /**
  181. * test selective logging by level/type
  182. *
  183. * @return void
  184. */
  185. public function testSelectiveLoggingByLevel() {
  186. if (file_exists(LOGS . 'spam.log')) {
  187. unlink(LOGS . 'spam.log');
  188. }
  189. if (file_exists(LOGS . 'eggs.log')) {
  190. unlink(LOGS . 'eggs.log');
  191. }
  192. CakeLog::config('spam', array(
  193. 'engine' => 'FileLog',
  194. 'types' => 'info',
  195. 'file' => 'spam',
  196. ));
  197. CakeLog::config('eggs', array(
  198. 'engine' => 'FileLog',
  199. 'types' => array('eggs', 'info', 'error', 'warning'),
  200. 'file' => 'eggs',
  201. ));
  202. $testMessage = 'selective logging';
  203. CakeLog::write(LOG_WARNING, $testMessage);
  204. $this->assertTrue(file_exists(LOGS . 'eggs.log'));
  205. $this->assertFalse(file_exists(LOGS . 'spam.log'));
  206. CakeLog::write(LOG_INFO, $testMessage);
  207. $this->assertTrue(file_exists(LOGS . 'spam.log'));
  208. $contents = file_get_contents(LOGS . 'spam.log');
  209. $this->assertContains('Info: ' . $testMessage, $contents);
  210. $contents = file_get_contents(LOGS . 'eggs.log');
  211. $this->assertContains('Info: ' . $testMessage, $contents);
  212. if (file_exists(LOGS . 'spam.log')) {
  213. unlink(LOGS . 'spam.log');
  214. }
  215. if (file_exists(LOGS . 'eggs.log')) {
  216. unlink(LOGS . 'eggs.log');
  217. }
  218. }
  219. /**
  220. * test enable
  221. *
  222. * @expectedException CakeLogException
  223. */
  224. public function testStreamEnable() {
  225. CakeLog::config('spam', array(
  226. 'engine' => 'FileLog',
  227. 'file' => 'spam',
  228. ));
  229. $this->assertTrue(CakeLog::enabled('spam'));
  230. CakeLog::drop('spam');
  231. CakeLog::enable('bogus_stream');
  232. }
  233. /**
  234. * test disable
  235. *
  236. * @expectedException CakeLogException
  237. */
  238. public function testStreamDisable() {
  239. CakeLog::config('spam', array(
  240. 'engine' => 'FileLog',
  241. 'file' => 'spam',
  242. ));
  243. $this->assertTrue(CakeLog::enabled('spam'));
  244. CakeLog::disable('spam');
  245. $this->assertFalse(CakeLog::enabled('spam'));
  246. CakeLog::drop('spam');
  247. CakeLog::enable('bogus_stream');
  248. }
  249. /**
  250. * test enabled() invalid stream
  251. *
  252. * @expectedException CakeLogException
  253. */
  254. public function testStreamEnabledInvalid() {
  255. CakeLog::enabled('bogus_stream');
  256. }
  257. /**
  258. * test disable invalid stream
  259. *
  260. * @expectedException CakeLogException
  261. */
  262. public function testStreamDisableInvalid() {
  263. CakeLog::disable('bogus_stream');
  264. }
  265. protected function _resetLogConfig() {
  266. CakeLog::config('debug', array(
  267. 'engine' => 'FileLog',
  268. 'types' => array('notice', 'info', 'debug'),
  269. 'file' => 'debug',
  270. ));
  271. CakeLog::config('error', array(
  272. 'engine' => 'FileLog',
  273. 'types' => array('warning', 'error', 'critical', 'alert', 'emergency'),
  274. 'file' => 'error',
  275. ));
  276. }
  277. protected function _deleteLogs() {
  278. if (file_exists(LOGS . 'shops.log')) {
  279. unlink(LOGS . 'shops.log');
  280. }
  281. if (file_exists(LOGS . 'error.log')) {
  282. unlink(LOGS . 'error.log');
  283. }
  284. if (file_exists(LOGS . 'debug.log')) {
  285. unlink(LOGS . 'debug.log');
  286. }
  287. if (file_exists(LOGS . 'bogus.log')) {
  288. unlink(LOGS . 'bogus.log');
  289. }
  290. if (file_exists(LOGS . 'spam.log')) {
  291. unlink(LOGS . 'spam.log');
  292. }
  293. if (file_exists(LOGS . 'eggs.log')) {
  294. unlink(LOGS . 'eggs.log');
  295. }
  296. }
  297. /**
  298. * test backward compatible scoped logging
  299. */
  300. public function testScopedLoggingBC() {
  301. $this->_deleteLogs();
  302. $this->_resetLogConfig();
  303. CakeLog::config('shops', array(
  304. 'engine' => 'FileLog',
  305. 'types' => array('info', 'notice', 'warning'),
  306. 'scopes' => array('transactions', 'orders'),
  307. 'file' => 'shops',
  308. ));
  309. CakeLog::write('info', 'info message');
  310. $this->assertFalse(file_exists(LOGS . 'error.log'));
  311. $this->assertTrue(file_exists(LOGS . 'shops.log'));
  312. $this->assertTrue(file_exists(LOGS . 'debug.log'));
  313. $this->_deleteLogs();
  314. CakeLog::write('transactions', 'transaction message');
  315. $this->assertTrue(file_exists(LOGS . 'shops.log'));
  316. $this->assertFalse(file_exists(LOGS . 'transactions.log'));
  317. $this->assertFalse(file_exists(LOGS . 'error.log'));
  318. $this->assertFalse(file_exists(LOGS . 'debug.log'));
  319. $this->_deleteLogs();
  320. CakeLog::write('error', 'error message');
  321. $this->assertTrue(file_exists(LOGS . 'error.log'));
  322. $this->assertFalse(file_exists(LOGS . 'debug.log'));
  323. $this->assertFalse(file_exists(LOGS . 'shops.log'));
  324. $this->_deleteLogs();
  325. CakeLog::write('orders', 'order message');
  326. $this->assertFalse(file_exists(LOGS . 'error.log'));
  327. $this->assertFalse(file_exists(LOGS . 'debug.log'));
  328. $this->assertFalse(file_exists(LOGS . 'orders.log'));
  329. $this->assertTrue(file_exists(LOGS . 'shops.log'));
  330. $this->_deleteLogs();
  331. CakeLog::write('warning', 'warning message');
  332. $this->assertTrue(file_exists(LOGS . 'error.log'));
  333. $this->assertTrue(file_exists(LOGS . 'shops.log'));
  334. $this->assertFalse(file_exists(LOGS . 'debug.log'));
  335. $this->_deleteLogs();
  336. CakeLog::drop('shops');
  337. }
  338. /**
  339. * test scoped logging
  340. *
  341. * @return void
  342. */
  343. public function testScopedLogging() {
  344. if (file_exists(LOGS . 'shops.log')) {
  345. unlink(LOGS . 'shops.log');
  346. }
  347. if (file_exists(LOGS . 'error.log')) {
  348. unlink(LOGS . 'error.log');
  349. }
  350. if (file_exists(LOGS . 'debug.log')) {
  351. unlink(LOGS . 'debug.log');
  352. }
  353. $this->_resetLogConfig();
  354. CakeLog::config('shops', array(
  355. 'engine' => 'FileLog',
  356. 'types' => array('info', 'notice', 'warning'),
  357. 'scopes' => array('transactions', 'orders'),
  358. 'file' => 'shops',
  359. ));
  360. CakeLog::write('info', 'info message', 'transactions');
  361. $this->assertFalse(file_exists(LOGS . 'error.log'));
  362. $this->assertTrue(file_exists(LOGS . 'shops.log'));
  363. $this->assertTrue(file_exists(LOGS . 'debug.log'));
  364. $this->_deleteLogs();
  365. CakeLog::write('transactions', 'transaction message', 'orders');
  366. $this->assertTrue(file_exists(LOGS . 'shops.log'));
  367. $this->assertFalse(file_exists(LOGS . 'transactions.log'));
  368. $this->assertFalse(file_exists(LOGS . 'error.log'));
  369. $this->assertFalse(file_exists(LOGS . 'debug.log'));
  370. $this->_deleteLogs();
  371. CakeLog::write('error', 'error message', 'orders');
  372. $this->assertTrue(file_exists(LOGS . 'error.log'));
  373. $this->assertFalse(file_exists(LOGS . 'debug.log'));
  374. $this->assertFalse(file_exists(LOGS . 'shops.log'));
  375. $this->_deleteLogs();
  376. CakeLog::write('orders', 'order message', 'transactions');
  377. $this->assertFalse(file_exists(LOGS . 'error.log'));
  378. $this->assertFalse(file_exists(LOGS . 'debug.log'));
  379. $this->assertFalse(file_exists(LOGS . 'orders.log'));
  380. $this->assertTrue(file_exists(LOGS . 'shops.log'));
  381. $this->_deleteLogs();
  382. CakeLog::write('warning', 'warning message', 'orders');
  383. $this->assertTrue(file_exists(LOGS . 'error.log'));
  384. $this->assertTrue(file_exists(LOGS . 'shops.log'));
  385. $this->assertFalse(file_exists(LOGS . 'debug.log'));
  386. $this->_deleteLogs();
  387. CakeLog::drop('shops');
  388. }
  389. /**
  390. * test bogus type and scope
  391. *
  392. */
  393. public function testBogusTypeAndScope() {
  394. $this->_resetLogConfig();
  395. $this->_deleteLogs();
  396. CakeLog::write('bogus', 'bogus message');
  397. $this->assertTrue(file_exists(LOGS . 'bogus.log'));
  398. $this->assertFalse(file_exists(LOGS . 'error.log'));
  399. $this->assertFalse(file_exists(LOGS . 'debug.log'));
  400. $this->_deleteLogs();
  401. CakeLog::write('bogus', 'bogus message', 'bogus');
  402. $this->assertTrue(file_exists(LOGS . 'bogus.log'));
  403. $this->assertFalse(file_exists(LOGS . 'error.log'));
  404. $this->assertFalse(file_exists(LOGS . 'debug.log'));
  405. $this->_deleteLogs();
  406. CakeLog::write('error', 'bogus message', 'bogus');
  407. $this->assertFalse(file_exists(LOGS . 'bogus.log'));
  408. $this->assertTrue(file_exists(LOGS . 'error.log'));
  409. $this->assertFalse(file_exists(LOGS . 'debug.log'));
  410. $this->_deleteLogs();
  411. }
  412. /**
  413. * test scoped logging with convenience methods
  414. */
  415. public function testConvenienceScopedLogging() {
  416. if (file_exists(LOGS . 'shops.log')) {
  417. unlink(LOGS . 'shops.log');
  418. }
  419. if (file_exists(LOGS . 'error.log')) {
  420. unlink(LOGS . 'error.log');
  421. }
  422. if (file_exists(LOGS . 'debug.log')) {
  423. unlink(LOGS . 'debug.log');
  424. }
  425. $this->_resetLogConfig();
  426. CakeLog::config('shops', array(
  427. 'engine' => 'FileLog',
  428. 'types' => array('info', 'notice', 'warning'),
  429. 'scopes' => array('transactions', 'orders'),
  430. 'file' => 'shops',
  431. ));
  432. CakeLog::info('info message', 'transactions');
  433. $this->assertFalse(file_exists(LOGS . 'error.log'));
  434. $this->assertTrue(file_exists(LOGS . 'shops.log'));
  435. $this->assertTrue(file_exists(LOGS . 'debug.log'));
  436. $this->_deleteLogs();
  437. CakeLog::error('error message', 'orders');
  438. $this->assertTrue(file_exists(LOGS . 'error.log'));
  439. $this->assertFalse(file_exists(LOGS . 'debug.log'));
  440. $this->assertFalse(file_exists(LOGS . 'shops.log'));
  441. $this->_deleteLogs();
  442. CakeLog::warning('warning message', 'orders');
  443. $this->assertTrue(file_exists(LOGS . 'error.log'));
  444. $this->assertTrue(file_exists(LOGS . 'shops.log'));
  445. $this->assertFalse(file_exists(LOGS . 'debug.log'));
  446. $this->_deleteLogs();
  447. CakeLog::drop('shops');
  448. }
  449. /**
  450. * test convenience methods
  451. */
  452. public function testConvenienceMethods() {
  453. $this->_deleteLogs();
  454. CakeLog::config('debug', array(
  455. 'engine' => 'FileLog',
  456. 'types' => array('notice', 'info', 'debug'),
  457. 'file' => 'debug',
  458. ));
  459. CakeLog::config('error', array(
  460. 'engine' => 'FileLog',
  461. 'types' => array('emergency', 'alert', 'critical', 'error', 'warning'),
  462. 'file' => 'error',
  463. ));
  464. $testMessage = 'emergency message';
  465. CakeLog::emergency($testMessage);
  466. $contents = file_get_contents(LOGS . 'error.log');
  467. $this->assertContains('Emergency: ' . $testMessage, $contents);
  468. $this->assertFalse(file_exists(LOGS . 'debug.log'));
  469. $this->_deleteLogs();
  470. $testMessage = 'alert message';
  471. CakeLog::alert($testMessage);
  472. $contents = file_get_contents(LOGS . 'error.log');
  473. $this->assertContains('Alert: ' . $testMessage, $contents);
  474. $this->assertFalse(file_exists(LOGS . 'debug.log'));
  475. $this->_deleteLogs();
  476. $testMessage = 'critical message';
  477. CakeLog::critical($testMessage);
  478. $contents = file_get_contents(LOGS . 'error.log');
  479. $this->assertContains('Critical: ' . $testMessage, $contents);
  480. $this->assertFalse(file_exists(LOGS . 'debug.log'));
  481. $this->_deleteLogs();
  482. $testMessage = 'error message';
  483. CakeLog::error($testMessage);
  484. $contents = file_get_contents(LOGS . 'error.log');
  485. $this->assertContains('Error: ' . $testMessage, $contents);
  486. $this->assertFalse(file_exists(LOGS . 'debug.log'));
  487. $this->_deleteLogs();
  488. $testMessage = 'warning message';
  489. CakeLog::warning($testMessage);
  490. $contents = file_get_contents(LOGS . 'error.log');
  491. $this->assertContains('Warning: ' . $testMessage, $contents);
  492. $this->assertFalse(file_exists(LOGS . 'debug.log'));
  493. $this->_deleteLogs();
  494. $testMessage = 'notice message';
  495. CakeLog::notice($testMessage);
  496. $contents = file_get_contents(LOGS . 'debug.log');
  497. $this->assertContains('Notice: ' . $testMessage, $contents);
  498. $this->assertFalse(file_exists(LOGS . 'error.log'));
  499. $this->_deleteLogs();
  500. $testMessage = 'info message';
  501. CakeLog::info($testMessage);
  502. $contents = file_get_contents(LOGS . 'debug.log');
  503. $this->assertContains('Info: ' . $testMessage, $contents);
  504. $this->assertFalse(file_exists(LOGS . 'error.log'));
  505. $this->_deleteLogs();
  506. $testMessage = 'debug message';
  507. CakeLog::debug($testMessage);
  508. $contents = file_get_contents(LOGS . 'debug.log');
  509. $this->assertContains('Debug: ' . $testMessage, $contents);
  510. $this->assertFalse(file_exists(LOGS . 'error.log'));
  511. $this->_deleteLogs();
  512. }
  513. /**
  514. * test levels customization
  515. */
  516. public function testLevelCustomization() {
  517. $this->skipIf(DIRECTORY_SEPARATOR === '\\', 'Log level tests not supported on Windows.');
  518. $levels = CakeLog::defaultLevels();
  519. $this->assertNotEmpty($levels);
  520. $result = array_keys($levels);
  521. $this->assertEquals(array(0, 1, 2, 3, 4, 5, 6, 7), $result);
  522. $levels = CakeLog::levels(array('foo', 'bar'));
  523. CakeLog::defaultLevels();
  524. $this->assertEquals('foo', $levels[8]);
  525. $this->assertEquals('bar', $levels[9]);
  526. $levels = CakeLog::levels(array(11 => 'spam', 'bar' => 'eggs'));
  527. CakeLog::defaultLevels();
  528. $this->assertEquals('spam', $levels[8]);
  529. $this->assertEquals('eggs', $levels[9]);
  530. $levels = CakeLog::levels(array(11 => 'spam', 'bar' => 'eggs'), false);
  531. CakeLog::defaultLevels();
  532. $this->assertEquals(array('spam', 'eggs'), $levels);
  533. $levels = CakeLog::levels(array('ham', 9 => 'spam', '12' => 'fam'), false);
  534. CakeLog::defaultLevels();
  535. $this->assertEquals(array('ham', 'spam', 'fam'), $levels);
  536. }
  537. /**
  538. * Test writing log files with custom levels
  539. */
  540. public function testCustomLevelWrites() {
  541. $this->_deleteLogs();
  542. $this->_resetLogConfig();
  543. $levels = CakeLog::levels(array('spam', 'eggs'));
  544. $testMessage = 'error message';
  545. CakeLog::write('error', $testMessage);
  546. CakeLog::defaultLevels();
  547. $this->assertTrue(file_exists(LOGS . 'error.log'));
  548. $contents = file_get_contents(LOGS . 'error.log');
  549. $this->assertContains('Error: ' . $testMessage, $contents);
  550. CakeLog::config('spam', array(
  551. 'engine' => 'FileLog',
  552. 'file' => 'spam.log',
  553. 'types' => 'spam',
  554. ));
  555. CakeLog::config('eggs', array(
  556. 'engine' => 'FileLog',
  557. 'file' => 'eggs.log',
  558. 'types' => array('spam', 'eggs'),
  559. ));
  560. $testMessage = 'spam message';
  561. CakeLog::write('spam', $testMessage);
  562. CakeLog::defaultLevels();
  563. $this->assertTrue(file_exists(LOGS . 'spam.log'));
  564. $this->assertTrue(file_exists(LOGS . 'eggs.log'));
  565. $contents = file_get_contents(LOGS . 'spam.log');
  566. $this->assertContains('Spam: ' . $testMessage, $contents);
  567. $testMessage = 'egg message';
  568. CakeLog::write('eggs', $testMessage);
  569. CakeLog::defaultLevels();
  570. $contents = file_get_contents(LOGS . 'spam.log');
  571. $this->assertNotContains('Eggs: ' . $testMessage, $contents);
  572. $contents = file_get_contents(LOGS . 'eggs.log');
  573. $this->assertContains('Eggs: ' . $testMessage, $contents);
  574. CakeLog::drop('spam');
  575. CakeLog::drop('eggs');
  576. $this->_deleteLogs();
  577. }
  578. }