Format and publish a LogRecord . @param record description of the log event
(LogRecord record)
| 224 | * @param record description of the log event |
| 225 | */ |
| 226 | @Override |
| 227 | public void publish(LogRecord record) { |
| 228 | |
| 229 | if (!isLoggable(record)) { |
| 230 | return; |
| 231 | } |
| 232 | |
| 233 | final String tsDate; |
| 234 | if (rotatable.booleanValue()) { |
| 235 | // Construct the timestamp we will use |
| 236 | Timestamp ts = new Timestamp(System.currentTimeMillis()); |
| 237 | tsDate = ts.toString().substring(0, 10); |
| 238 | } else { |
| 239 | tsDate = ""; |
| 240 | } |
| 241 | |
| 242 | writerLock.readLock().lock(); |
| 243 | try { |
| 244 | // If the date has changed, switch log files |
| 245 | if (!tsDate.equals(date)) { |
| 246 | // Upgrade to writeLock before we switch |
| 247 | writerLock.readLock().unlock(); |
| 248 | writerLock.writeLock().lock(); |
| 249 | try { |
| 250 | // Make sure another thread hasn't already done this |
| 251 | if (!tsDate.equals(date)) { |
| 252 | closeWriter(); |
| 253 | date = tsDate; |
| 254 | openWriter(); |
| 255 | clean(); |
| 256 | } |
| 257 | } finally { |
| 258 | // Downgrade to read-lock. This ensures the writer remains valid |
| 259 | // until the log message is written |
| 260 | writerLock.readLock().lock(); |
| 261 | writerLock.writeLock().unlock(); |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | String result; |
| 266 | try { |
| 267 | result = getFormatter().format(record); |
| 268 | } catch (Exception e) { |
| 269 | reportError(null, e, ErrorManager.FORMAT_FAILURE); |
| 270 | return; |
| 271 | } |
| 272 | |
| 273 | try { |
| 274 | if (writer != null) { |
| 275 | writer.write(result); |
| 276 | if (bufferSize.intValue() < 0) { |
| 277 | writer.flush(); |
| 278 | } |
| 279 | } else { |
| 280 | reportError("FileHandler is closed or not yet initialized, unable to log [" + result + "]", null, |
| 281 | ErrorManager.WRITE_FAILURE); |
| 282 | } |
| 283 | } catch (Exception e) { |
nothing calls this directly
no test coverage detected