1 /* 2 * Copyright (c) Meta Platforms, Inc. and affiliates. 3 * All rights reserved. 4 * 5 * This source code is licensed under the BSD-style license found in the 6 * LICENSE file in the root directory of this source tree. 7 */ 8 9 package com.example.executorchllamademo; 10 11 import java.text.SimpleDateFormat; 12 import java.util.Date; 13 import java.util.Locale; 14 15 public class AppLog { 16 private final Long timestamp; 17 private final String message; 18 AppLog(String message)19 public AppLog(String message) { 20 this.timestamp = getCurrentTimeStamp(); 21 this.message = message; 22 } 23 getTimestamp()24 public Long getTimestamp() { 25 return timestamp; 26 } 27 getMessage()28 public String getMessage() { 29 return message; 30 } 31 getFormattedLog()32 public String getFormattedLog() { 33 return "[" + getFormattedTimeStamp() + "] " + message; 34 } 35 getCurrentTimeStamp()36 private Long getCurrentTimeStamp() { 37 return System.currentTimeMillis(); 38 } 39 getFormattedTimeStamp()40 private String getFormattedTimeStamp() { 41 return formatDate(timestamp); 42 } 43 formatDate(long milliseconds)44 private String formatDate(long milliseconds) { 45 SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); 46 Date date = new Date(milliseconds); 47 return formatter.format(date); 48 } 49 } 50