Console Log System : Velocity Log « Velocity « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » Velocity » Velocity LogScreenshots 
Console Log System


import org.apache.velocity.runtime.RuntimeServices;
import org.apache.velocity.runtime.log.LogSystem;

public class ConsoleLogSystem implements LogSystem {

  private RuntimeServices rs;

  private int maxLevel = LogSystem.INFO_ID;

  private static final String[] LEVEL_NAMES = new String[] { "ERROR""WARN",
      "INFO""DEBUG" };

  private static final int[] LEVELS = new int[] { LogSystem.ERROR_ID,
      LogSystem.WARN_ID, LogSystem.INFO_ID, LogSystem.DEBUG_ID };

  public void init(RuntimeServices rsthrows Exception {
    System.out.println("ConsoleLogSystem.init() called");
    this.rs = rs;
    configure();
  }

  public void logVelocityMessage(int level, String message) {
    if (level >= maxLevel) {
      System.out.println("[" + getLevelName(level"] " + message);
    }
  }

  private void configure() {
    String maxLevelName = rs.getString("console.logsystem.max.level");

    int level = getLevelFromString(maxLevelName);

    if (level > -1) {
      System.out.println("Using log level: " + maxLevelName);
      maxLevel = level;
    }
  }

  private int getLevelFromString(String levelName) {
    for (int x = 0; x < LEVEL_NAMES.length; x++) {
      if (LEVEL_NAMES[x].equals(levelName)) {
        return LEVELS[x];
      }
    }
    // should not arrive here, couldn't find the level
    return -1;
  }

  private String getLevelName(int level) {
    for (int x = 0; x < LEVELS.length; x++) {
      if (LEVELS[x== level) {
        return LEVEL_NAMES[x];
      }
    }
    return "UNKNOWN";
  }
}
           
       
velocity-ConsoleLogSystem.zip( 2,190 k)
Related examples in the same category
1. This is a toy demonstration of how Velocity can use an externally configured logger
2. Custom log for Velocity
3. How to use an existing Log4j Categeory as the Velocity logging target
w___w_w__.ja___v___a2s__.__c___o_m | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.