1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. * Copyright (c) 1999 The Apache Software Foundation. All rights
  5. * reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if
  20. * any, must include the following acknowlegement:
  21. * "This product includes software developed by the
  22. * Apache Software Foundation (http://www.apache.org/)."
  23. * Alternately, this acknowlegement may appear in the software itself,
  24. * if and wherever such third-party acknowlegements normally appear.
  25. *
  26. * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
  27. * Foundation" must not be used to endorse or promote products derived
  28. * from this software without prior written permission. For written
  29. * permission, please contact apache@apache.org.
  30. *
  31. * 5. Products derived from this software may not be called "Apache"
  32. * nor may "Apache" appear in their names without prior written
  33. * permission of the Apache Group.
  34. *
  35. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46. * SUCH DAMAGE.
  47. * ====================================================================
  48. *
  49. * This software consists of voluntary contributions made by many
  50. * individuals on behalf of the Apache Software Foundation. For more
  51. * information on the Apache Software Foundation, please see
  52. * <http://www.apache.org/>.
  53. *
  54. */
  55. package org.apache.commons.el;
  56. import java.io.PrintStream;
  57. import java.text.MessageFormat;
  58. import javax.servlet.jsp.el.ELException;
  59. /**
  60. *
  61. * <p>The evaluator may pass an instance of this class to operators
  62. * and expressions during evaluation. They should use this to log any
  63. * warning or error messages that might come up. This allows all of
  64. * our logging policies to be concentrated in one class.
  65. *
  66. * <p>Errors are conditions that are severe enough to abort operation.
  67. * Warnings are conditions through which the operation may continue,
  68. * but which should be reported to the developer.
  69. *
  70. * @author Nathan Abramson - Art Technology Group
  71. * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: luehe $
  72. **/
  73. public class Logger
  74. {
  75. //-------------------------------------
  76. // Member variables
  77. //-------------------------------------
  78. PrintStream mOut;
  79. //-------------------------------------
  80. /**
  81. *
  82. * Constructor
  83. *
  84. * @param pOut the PrintStream to which warnings should be printed
  85. **/
  86. public Logger (PrintStream pOut)
  87. {
  88. mOut = pOut;
  89. }
  90. //-------------------------------------
  91. /**
  92. *
  93. * Returns true if the application should even bother to try logging
  94. * a warning.
  95. **/
  96. public boolean isLoggingWarning ()
  97. {
  98. return false;
  99. }
  100. //-------------------------------------
  101. /**
  102. *
  103. * Logs a warning
  104. **/
  105. public void logWarning (String pMessage,
  106. Throwable pRootCause)
  107. throws ELException
  108. {
  109. if (isLoggingWarning ()) {
  110. if (pMessage == null) {
  111. System.out.println (pRootCause);
  112. }
  113. else if (pRootCause == null) {
  114. System.out.println (pMessage);
  115. }
  116. else {
  117. System.out.println (pMessage + ": " + pRootCause);
  118. }
  119. }
  120. }
  121. //-------------------------------------
  122. /**
  123. *
  124. * Logs a warning
  125. **/
  126. public void logWarning (String pTemplate)
  127. throws ELException
  128. {
  129. if (isLoggingWarning ()) {
  130. logWarning (pTemplate, null);
  131. }
  132. }
  133. //-------------------------------------
  134. /**
  135. *
  136. * Logs a warning
  137. **/
  138. public void logWarning (Throwable pRootCause)
  139. throws ELException
  140. {
  141. if (isLoggingWarning ()) {
  142. logWarning (null, pRootCause);
  143. }
  144. }
  145. //-------------------------------------
  146. /**
  147. *
  148. * Logs a warning
  149. **/
  150. public void logWarning (String pTemplate,
  151. Object pArg0)
  152. throws ELException
  153. {
  154. if (isLoggingWarning ()) {
  155. logWarning
  156. (MessageFormat.format
  157. (pTemplate,
  158. new Object [] {
  159. "" + pArg0,
  160. }));
  161. }
  162. }
  163. //-------------------------------------
  164. /**
  165. *
  166. * Logs a warning
  167. **/
  168. public void logWarning (String pTemplate,
  169. Throwable pRootCause,
  170. Object pArg0)
  171. throws ELException
  172. {
  173. if (isLoggingWarning ()) {
  174. logWarning
  175. (MessageFormat.format
  176. (pTemplate,
  177. new Object [] {
  178. "" + pArg0,
  179. }),
  180. pRootCause);
  181. }
  182. }
  183. //-------------------------------------
  184. /**
  185. *
  186. * Logs a warning
  187. **/
  188. public void logWarning (String pTemplate,
  189. Object pArg0,
  190. Object pArg1)
  191. throws ELException
  192. {
  193. if (isLoggingWarning ()) {
  194. logWarning
  195. (MessageFormat.format
  196. (pTemplate,
  197. new Object [] {
  198. "" + pArg0,
  199. "" + pArg1,
  200. }));
  201. }
  202. }
  203. //-------------------------------------
  204. /**
  205. *
  206. * Logs a warning
  207. **/
  208. public void logWarning (String pTemplate,
  209. Throwable pRootCause,
  210. Object pArg0,
  211. Object pArg1)
  212. throws ELException
  213. {
  214. if (isLoggingWarning ()) {
  215. logWarning
  216. (MessageFormat.format
  217. (pTemplate,
  218. new Object [] {
  219. "" + pArg0,
  220. "" + pArg1,
  221. }),
  222. pRootCause);
  223. }
  224. }
  225. //-------------------------------------
  226. /**
  227. *
  228. * Logs a warning
  229. **/
  230. public void logWarning (String pTemplate,
  231. Object pArg0,
  232. Object pArg1,
  233. Object pArg2)
  234. throws ELException
  235. {
  236. if (isLoggingWarning ()) {
  237. logWarning
  238. (MessageFormat.format
  239. (pTemplate,
  240. new Object [] {
  241. "" + pArg0,
  242. "" + pArg1,
  243. "" + pArg2,
  244. }));
  245. }
  246. }
  247. //-------------------------------------
  248. /**
  249. *
  250. * Logs a warning
  251. **/
  252. public void logWarning (String pTemplate,
  253. Throwable pRootCause,
  254. Object pArg0,
  255. Object pArg1,
  256. Object pArg2)
  257. throws ELException
  258. {
  259. if (isLoggingWarning ()) {
  260. logWarning
  261. (MessageFormat.format
  262. (pTemplate,
  263. new Object [] {
  264. "" + pArg0,
  265. "" + pArg1,
  266. "" + pArg2,
  267. }),
  268. pRootCause);
  269. }
  270. }
  271. //-------------------------------------
  272. /**
  273. *
  274. * Logs a warning
  275. **/
  276. public void logWarning (String pTemplate,
  277. Object pArg0,
  278. Object pArg1,
  279. Object pArg2,
  280. Object pArg3)
  281. throws ELException
  282. {
  283. if (isLoggingWarning ()) {
  284. logWarning
  285. (MessageFormat.format
  286. (pTemplate,
  287. new Object [] {
  288. "" + pArg0,
  289. "" + pArg1,
  290. "" + pArg2,
  291. "" + pArg3,
  292. }));
  293. }
  294. }
  295. //-------------------------------------
  296. /**
  297. *
  298. * Logs a warning
  299. **/
  300. public void logWarning (String pTemplate,
  301. Throwable pRootCause,
  302. Object pArg0,
  303. Object pArg1,
  304. Object pArg2,
  305. Object pArg3)
  306. throws ELException
  307. {
  308. if (isLoggingWarning ()) {
  309. logWarning
  310. (MessageFormat.format
  311. (pTemplate,
  312. new Object [] {
  313. "" + pArg0,
  314. "" + pArg1,
  315. "" + pArg2,
  316. "" + pArg3,
  317. }),
  318. pRootCause);
  319. }
  320. }
  321. //-------------------------------------
  322. /**
  323. *
  324. * Logs a warning
  325. **/
  326. public void logWarning (String pTemplate,
  327. Object pArg0,
  328. Object pArg1,
  329. Object pArg2,
  330. Object pArg3,
  331. Object pArg4)
  332. throws ELException
  333. {
  334. if (isLoggingWarning ()) {
  335. logWarning
  336. (MessageFormat.format
  337. (pTemplate,
  338. new Object [] {
  339. "" + pArg0,
  340. "" + pArg1,
  341. "" + pArg2,
  342. "" + pArg3,
  343. "" + pArg4,
  344. }));
  345. }
  346. }
  347. //-------------------------------------
  348. /**
  349. *
  350. * Logs a warning
  351. **/
  352. public void logWarning (String pTemplate,
  353. Throwable pRootCause,
  354. Object pArg0,
  355. Object pArg1,
  356. Object pArg2,
  357. Object pArg3,
  358. Object pArg4)
  359. throws ELException
  360. {
  361. if (isLoggingWarning ()) {
  362. logWarning
  363. (MessageFormat.format
  364. (pTemplate,
  365. new Object [] {
  366. "" + pArg0,
  367. "" + pArg1,
  368. "" + pArg2,
  369. "" + pArg3,
  370. "" + pArg4,
  371. }),
  372. pRootCause);
  373. }
  374. }
  375. //-------------------------------------
  376. /**
  377. *
  378. * Logs a warning
  379. **/
  380. public void logWarning (String pTemplate,
  381. Object pArg0,
  382. Object pArg1,
  383. Object pArg2,
  384. Object pArg3,
  385. Object pArg4,
  386. Object pArg5)
  387. throws ELException
  388. {
  389. if (isLoggingWarning ()) {
  390. logWarning
  391. (MessageFormat.format
  392. (pTemplate,
  393. new Object [] {
  394. "" + pArg0,
  395. "" + pArg1,
  396. "" + pArg2,
  397. "" + pArg3,
  398. "" + pArg4,
  399. "" + pArg5,
  400. }));
  401. }
  402. }
  403. //-------------------------------------
  404. /**
  405. *
  406. * Logs a warning
  407. **/
  408. public void logWarning (String pTemplate,
  409. Throwable pRootCause,
  410. Object pArg0,
  411. Object pArg1,
  412. Object pArg2,
  413. Object pArg3,
  414. Object pArg4,
  415. Object pArg5)
  416. throws ELException
  417. {
  418. if (isLoggingWarning ()) {
  419. logWarning
  420. (MessageFormat.format
  421. (pTemplate,
  422. new Object [] {
  423. "" + pArg0,
  424. "" + pArg1,
  425. "" + pArg2,
  426. "" + pArg3,
  427. "" + pArg4,
  428. "" + pArg5,
  429. }),
  430. pRootCause);
  431. }
  432. }
  433. //-------------------------------------
  434. /**
  435. *
  436. * Returns true if the application should even bother to try logging
  437. * an error.
  438. **/
  439. public boolean isLoggingError ()
  440. {
  441. return true;
  442. }
  443. //-------------------------------------
  444. /**
  445. *
  446. * Logs an error
  447. **/
  448. public void logError (String pMessage,
  449. Throwable pRootCause)
  450. throws ELException
  451. {
  452. if (isLoggingError ()) {
  453. if (pMessage == null) {
  454. throw new ELException (pRootCause);
  455. }
  456. else if (pRootCause == null) {
  457. throw new ELException (pMessage);
  458. }
  459. else {
  460. throw new ELException (pMessage, pRootCause);
  461. }
  462. }
  463. }
  464. //-------------------------------------
  465. /**
  466. *
  467. * Logs an error
  468. **/
  469. public void logError (String pTemplate)
  470. throws ELException
  471. {
  472. if (isLoggingError ()) {
  473. logError (pTemplate, null);
  474. }
  475. }
  476. //-------------------------------------
  477. /**
  478. *
  479. * Logs an error
  480. **/
  481. public void logError (Throwable pRootCause)
  482. throws ELException
  483. {
  484. if (isLoggingError ()) {
  485. logError (null, pRootCause);
  486. }
  487. }
  488. //-------------------------------------
  489. /**
  490. *
  491. * Logs an error
  492. **/
  493. public void logError (String pTemplate,
  494. Object pArg0)
  495. throws ELException
  496. {
  497. if (isLoggingError ()) {
  498. logError
  499. (MessageFormat.format
  500. (pTemplate,
  501. new Object [] {
  502. "" + pArg0,
  503. }));
  504. }
  505. }
  506. //-------------------------------------
  507. /**
  508. *
  509. * Logs an error
  510. **/
  511. public void logError (String pTemplate,
  512. Throwable pRootCause,
  513. Object pArg0)
  514. throws ELException
  515. {
  516. if (isLoggingError ()) {
  517. logError
  518. (MessageFormat.format
  519. (pTemplate,
  520. new Object [] {
  521. "" + pArg0,
  522. }),
  523. pRootCause);
  524. }
  525. }
  526. //-------------------------------------
  527. /**
  528. *
  529. * Logs an error
  530. **/
  531. public void logError (String pTemplate,
  532. Object pArg0,
  533. Object pArg1)
  534. throws ELException
  535. {
  536. if (isLoggingError ()) {
  537. logError
  538. (MessageFormat.format
  539. (pTemplate,
  540. new Object [] {
  541. "" + pArg0,
  542. "" + pArg1,
  543. }));
  544. }
  545. }
  546. //-------------------------------------
  547. /**
  548. *
  549. * Logs an error
  550. **/
  551. public void logError (String pTemplate,
  552. Throwable pRootCause,
  553. Object pArg0,
  554. Object pArg1)
  555. throws ELException
  556. {
  557. if (isLoggingError ()) {
  558. logError
  559. (MessageFormat.format
  560. (pTemplate,
  561. new Object [] {
  562. "" + pArg0,
  563. "" + pArg1,
  564. }),
  565. pRootCause);
  566. }
  567. }
  568. //-------------------------------------
  569. /**
  570. *
  571. * Logs an error
  572. **/
  573. public void logError (String pTemplate,
  574. Object pArg0,
  575. Object pArg1,
  576. Object pArg2)
  577. throws ELException
  578. {
  579. if (isLoggingError ()) {
  580. logError
  581. (MessageFormat.format
  582. (pTemplate,
  583. new Object [] {
  584. "" + pArg0,
  585. "" + pArg1,
  586. "" + pArg2,
  587. }));
  588. }
  589. }
  590. //-------------------------------------
  591. /**
  592. *
  593. * Logs an error
  594. **/
  595. public void logError (String pTemplate,
  596. Throwable pRootCause,
  597. Object pArg0,
  598. Object pArg1,
  599. Object pArg2)
  600. throws ELException
  601. {
  602. if (isLoggingError ()) {
  603. logError
  604. (MessageFormat.format
  605. (pTemplate,
  606. new Object [] {
  607. "" + pArg0,
  608. "" + pArg1,
  609. "" + pArg2,
  610. }),
  611. pRootCause);
  612. }
  613. }
  614. //-------------------------------------
  615. /**
  616. *
  617. * Logs an error
  618. **/
  619. public void logError (String pTemplate,
  620. Object pArg0,
  621. Object pArg1,
  622. Object pArg2,
  623. Object pArg3)
  624. throws ELException
  625. {
  626. if (isLoggingError ()) {
  627. logError
  628. (MessageFormat.format
  629. (pTemplate,
  630. new Object [] {
  631. "" + pArg0,
  632. "" + pArg1,
  633. "" + pArg2,
  634. "" + pArg3,
  635. }));
  636. }
  637. }
  638. //-------------------------------------
  639. /**
  640. *
  641. * Logs an error
  642. **/
  643. public void logError (String pTemplate,
  644. Throwable pRootCause,
  645. Object pArg0,
  646. Object pArg1,
  647. Object pArg2,
  648. Object pArg3)
  649. throws ELException
  650. {
  651. if (isLoggingError ()) {
  652. logError
  653. (MessageFormat.format
  654. (pTemplate,
  655. new Object [] {
  656. "" + pArg0,
  657. "" + pArg1,
  658. "" + pArg2,
  659. "" + pArg3,
  660. }),
  661. pRootCause);
  662. }
  663. }
  664. //-------------------------------------
  665. /**
  666. *
  667. * Logs an error
  668. **/
  669. public void logError (String pTemplate,
  670. Object pArg0,
  671. Object pArg1,
  672. Object pArg2,
  673. Object pArg3,
  674. Object pArg4)
  675. throws ELException
  676. {
  677. if (isLoggingError ()) {
  678. logError
  679. (MessageFormat.format
  680. (pTemplate,
  681. new Object [] {
  682. "" + pArg0,
  683. "" + pArg1,
  684. "" + pArg2,
  685. "" + pArg3,
  686. "" + pArg4,
  687. }));
  688. }
  689. }
  690. //-------------------------------------
  691. /**
  692. *
  693. * Logs an error
  694. **/
  695. public void logError (String pTemplate,
  696. Throwable pRootCause,
  697. Object pArg0,
  698. Object pArg1,
  699. Object pArg2,
  700. Object pArg3,
  701. Object pArg4)
  702. throws ELException
  703. {
  704. if (isLoggingError ()) {
  705. logError
  706. (MessageFormat.format
  707. (pTemplate,
  708. new Object [] {
  709. "" + pArg0,
  710. "" + pArg1,
  711. "" + pArg2,
  712. "" + pArg3,
  713. "" + pArg4,
  714. }),
  715. pRootCause);
  716. }
  717. }
  718. //-------------------------------------
  719. /**
  720. *
  721. * Logs an error
  722. **/
  723. public void logError (String pTemplate,
  724. Object pArg0,
  725. Object pArg1,
  726. Object pArg2,
  727. Object pArg3,
  728. Object pArg4,
  729. Object pArg5)
  730. throws ELException
  731. {
  732. if (isLoggingError ()) {
  733. logError
  734. (MessageFormat.format
  735. (pTemplate,
  736. new Object [] {
  737. "" + pArg0,
  738. "" + pArg1,
  739. "" + pArg2,
  740. "" + pArg3,
  741. "" + pArg4,
  742. "" + pArg5,
  743. }));
  744. }
  745. }
  746. //-------------------------------------
  747. /**
  748. *
  749. * Logs an error
  750. **/
  751. public void logError (String pTemplate,
  752. Throwable pRootCause,
  753. Object pArg0,
  754. Object pArg1,
  755. Object pArg2,
  756. Object pArg3,
  757. Object pArg4,
  758. Object pArg5)
  759. throws ELException
  760. {
  761. if (isLoggingError ()) {
  762. logError
  763. (MessageFormat.format
  764. (pTemplate,
  765. new Object [] {
  766. "" + pArg0,
  767. "" + pArg1,
  768. "" + pArg2,
  769. "" + pArg3,
  770. "" + pArg4,
  771. "" + pArg5,
  772. }),
  773. pRootCause);
  774. }
  775. }
  776. //-------------------------------------
  777. }