1 29 30 package com.caucho.log; 31 32 import com.caucho.config.ConfigException; 33 import com.caucho.config.types.Bytes; 34 import com.caucho.config.types.Period; 35 import com.caucho.util.L10N; 36 import com.caucho.vfs.Path; 37 38 import javax.annotation.PostConstruct; 39 import java.io.IOException ; 40 41 44 public class RotateLog { 45 private final static L10N L = new L10N(RotateLog.class); 46 47 private static final long ROLLOVER_SIZE = Long.MAX_VALUE / 2; 48 49 private Path _path; 50 private String _pathFormat; 51 private String _archiveFormat; 52 53 private Period _rolloverPeriod; 54 private Bytes _rolloverSize; 55 private int _rolloverCount = -1; 56 57 private RotateStream _rotateStream; 58 59 private String _timestamp; 60 61 64 public Path getPath() 65 { 66 return _path; 67 } 68 69 72 public void setPath(Path path) 73 { 74 _path = path; 75 } 76 77 80 public String getPathFormat() 81 { 82 return _pathFormat; 83 } 84 85 88 public void setPathFormat(String path) 89 { 90 _pathFormat = path; 91 } 92 93 96 public void setHref(Path path) 97 { 98 setPath(path); 99 } 100 101 104 public void setRolloverPeriod(Period period) 105 { 106 _rolloverPeriod = period; 107 } 108 109 112 public void setRolloverSize(Bytes size) 113 { 114 _rolloverSize = size; 115 } 116 117 120 public int getRolloverCount() 121 { 122 return _rolloverCount; 123 } 124 125 128 public void setRolloverCount(int count) 129 { 130 _rolloverCount = count; 131 } 132 133 136 public String getTimestamp() 137 { 138 return _timestamp; 139 } 140 141 144 150 151 154 public String getArchiveFormat() 155 { 156 return _archiveFormat; 157 } 158 159 162 public void setArchiveFormat(String format) 163 { 164 _archiveFormat = format; 165 } 166 167 170 public RotateStream getRotateStream() 171 { 172 return _rotateStream; 173 } 174 175 178 public String getTagName() 179 { 180 return "rotate-log"; 181 } 182 183 186 @PostConstruct 187 public void init() 188 throws ConfigException, IOException 189 { 190 if (_path != null) 191 _rotateStream = RotateStream.create(_path); 192 else if (_pathFormat != null) 193 _rotateStream = RotateStream.create(_pathFormat); 194 else 195 throw new ConfigException(L.l("`path' is a required attribute of <{0}>. Each <{0}> must configure the destination stream.", getTagName())); 196 197 if (_path != null && _path.exists() && ! _path.canRead() && 198 (_rolloverPeriod != null || 199 _rolloverSize != null || 200 _archiveFormat != null)) { 201 throw new ConfigException(L.l("log path '{0}' is not readable and therefore cannot be rotated.", _path.getURL())); 202 } 203 204 AbstractRolloverLog rolloverLog = _rotateStream.getRolloverLog(); 205 206 if (_rolloverPeriod != null) 207 rolloverLog.setRolloverPeriod(_rolloverPeriod); 208 209 if (_rolloverSize != null) 210 rolloverLog.setRolloverSize(_rolloverSize); 211 _rotateStream.setMaxRolloverCount(_rolloverCount); 212 if (_archiveFormat != null) 213 rolloverLog.setArchiveFormat(_archiveFormat); 214 215 _rotateStream.init(); 216 } 217 } 218 | Popular Tags |