001 package railo.commons.lang; 002 003 import java.io.PrintWriter; 004 import java.util.Date; 005 006 import railo.commons.io.SystemUtil; 007 import railo.runtime.PageContext; 008 import railo.runtime.config.Config; 009 import railo.runtime.engine.ThreadLocalPageContext; 010 011 public final class SystemOut { 012 013 public static int OUT=SystemUtil.OUT; 014 public static int ERR=SystemUtil.ERR; 015 016 /** 017 * logs a value 018 * @param value 019 */ 020 public static void printDate(PrintWriter pw,String value) { 021 long millis=System.currentTimeMillis(); 022 pw.write( 023 new Date(millis) 024 +"-" 025 +(millis-(millis/1000*1000)) 026 +" "+value+"\n"); 027 pw.flush(); 028 } 029 /** 030 * logs a value 031 * @param value 032 */ 033 public static void print(PrintWriter pw,String value) { 034 pw.write(value+"\n"); 035 pw.flush(); 036 } 037 038 039 public static void printStack(PrintWriter pw) { 040 new Throwable().printStackTrace(pw); 041 } 042 043 public static void printStack(int type) { 044 Config config=ThreadLocalPageContext.getConfig(); 045 if(config!=null) { 046 if(type==ERR) 047 printStack(config.getErrWriter()); 048 else 049 printStack(config.getOutWriter()); 050 } 051 else { 052 printStack(new PrintWriter((type==ERR)?System.err:System.out)); 053 } 054 } 055 056 /** 057 * logs a value 058 * @param value 059 */ 060 public static void printDate(String value) { 061 printDate(value,OUT); 062 } 063 064 public static void printDate(String value,int type) { 065 printDate(getPrinWriter(type),value); 066 } 067 068 069 public static PrintWriter getPrinWriter(int type) { 070 Config config=ThreadLocalPageContext.getConfig(); 071 if(config!=null) { 072 if(type==ERR) return config.getErrWriter(); 073 return config.getOutWriter(); 074 } 075 return SystemUtil.getPrintWriter(type); 076 } 077 078 079 080 /** 081 * logs a value 082 * @param value 083 */ 084 085 public static void print(String value) { 086 print(value, OUT); 087 } 088 089 public static void print(String value,int type) { 090 PageContext pc=ThreadLocalPageContext.get(); 091 if(pc!=null) { 092 if(type==ERR) 093 print(pc.getConfig().getErrWriter(),value); 094 else 095 print(pc.getConfig().getOutWriter(),value); 096 } 097 else { 098 print(new PrintWriter((type==ERR)?System.err:System.out),value); 099 } 100 } 101 102 }