/factory/factory-service-voip-conferences/src/main/java/org/red5/logging/Red5LoggerFactory.java

https://github.com/gritchou/Ulysse · Java · 84 lines · 15 code · 8 blank · 61 comment · 0 complexity · 8a446741dd1bd8410956701a18aa0ee0 MD5 · raw file

  1. package org.red5.logging;
  2. /*
  3. * RED5 Open Source Flash Server - http://www.osflash.org/red5
  4. *
  5. * Copyright (c) 2006-2009 by respective authors (see below). All rights reserved.
  6. *
  7. * This library is free software; you can redistribute it and/or modify it under the
  8. * terms of the GNU Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2.1 of the License, or (at your option) any later
  10. * version.
  11. *
  12. * This library is distributed in the hope that it will be useful, but WITHOUT ANY
  13. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  14. * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License along
  17. * with this library; if not, write to the Free Software Foundation, Inc.,
  18. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. import org.slf4j.Logger;
  21. import org.slf4j.LoggerFactory;
  22. /**
  23. * LoggerFactory to simplify requests for Logger instances within
  24. * Red5 applications. This class is expected to be run only once per
  25. * logger request and is optimized as such.
  26. *
  27. * @author Paul Gregoire (mondain@gmail.com)
  28. */
  29. public class Red5LoggerFactory {
  30. @SuppressWarnings("unchecked")
  31. public static Logger getLogger(Class clazz) {
  32. //determine the red5 app name or servlet context name
  33. String contextName = null;
  34. /* TODO: For a future day, the context or application will be determined
  35. //get a reference to our caller
  36. Class caller = Reflection.getCallerClass(2);
  37. //System.err.printf("Caller class: %s classloader: %s\n", caller, caller.getClassLoader());
  38. try {
  39. //check to see if we've been called by a servlet
  40. Class sub = caller.asSubclass(Servlet.class);
  41. //System.err.println("Caller is a Servlet");
  42. //Method[] methods = caller.getMethods();
  43. //for (Method meth : methods) {
  44. // System.err.printf("Method: %s\n", meth.getName());
  45. //}
  46. Method getContext = caller.getMethod("getServletContext", new Class[0]);
  47. //System.err.printf("got context method - %s\n", getContext);
  48. ServletContext context = (ServletContext) getContext.invoke(caller, null);
  49. System.err.printf("invoked context\n");
  50. contextName = context.getServletContextName();
  51. //System.err.printf("Servlet context name: %s\n", contextName);
  52. Method getContextName = context.getClass().getMethod("getServletContextName", new Class[0]);
  53. System.err.printf("got context name\n");
  54. Object ctxName = getContextName.invoke(null, new Object[0]);
  55. System.err.printf("Servlet context result: %s\n", ctxName);
  56. if (ctxName != null && ctxName instanceof String) {
  57. contextName = ctxName.toString();
  58. }
  59. } catch (Exception ex) {
  60. //ex.printStackTrace();
  61. }
  62. */
  63. return getLogger(clazz, contextName);
  64. }
  65. @SuppressWarnings("unchecked")
  66. public static Logger getLogger(Class clazz, String contextName) {
  67. Logger logger = logger = LoggerFactory.getLogger(clazz);
  68. return logger;
  69. }
  70. }