aspect LogAllMethods { Log log = new Log(); // pseudocode -- replace with whatever logging mechanism you like before(): call(public * com.mycompany.*.*(..)) { log.log("Entered method: " + thisJoinPoint); } after(): call(public * com.mycomapny.*.*(..)) { log.log("Leaving method: " + thisJoinPoint); } }
/** * * @param c the current class * @return the corresponding logger */ public static Log getLog(Class<?> c) { return new Log(c); }
var logger1 = new Log(); logger1.log(0, "should print"); logger1.log(1, "should print"); logger1.log(2, "should print"); Log.SetLevel(1); //global level logger1.log(0, "should print"); logger1.log(1, "should print"); logger1.log(2, "should not print");
/** * * @param c the current class * @return the corresponding logger */ public static Log getLog(Class<?> c) { return new Log(c); }
/** * * @param c the current class * @return the corresponding logger */ public static Log getLog(Class<?> c) { return new Log(c); }
var logLevel = 1; function Log() { this.log = function (level, msg) { if (level === logLevel) { alert(msg); } else { //Whatever you want to do } }; } var logger1 = new Log(); logger1.log(1, "should print"); //will alert logger1.log(2, "should not print"); //will not alert alert(logLevel); //to prove that 'logLevel' is defined at a global level. The value is alerted signifying its scope to be at the global level
function Log () { this.list = []; } Log.prototype.add = function () { this.list.push.apply(this.list, arguments); }; Log.prototype.alert = function () { alert(this.list); }; Log.prototype.reset = function () { while (this.list.length > 0) { this.list.pop(); } }; var log = new Log(), log2 = new Log(); log.add('one', 'three'); log2.add('two', 'four'); log.alert(); log.reset(); log2.alert(); alert('Lists are different? ' + log.list !== log2.list);
//Singleton constructor private DataModel() { //This makes it crash logs = new ArrayList<Log>(); logs.add(new Log("1234","sms", 123545, 1, 0)); //Load logs from database - Not done yet. }
class Main extends Application { Log log; // class, not shown here Work work; public start() // entry point { log = new Log("main.log"); // opens log file, need to be non-static work = new Work(log); } }
Future<?> f = scheduledExecutor.scheduleAtFixedRate(new Log(),...); try { f.get(); } catch (ExecutionException e) { Throwable actualException = e.getCause(); }
class Main extends Application { public static Log log = new Log("main.log"); // class, not shown here Work work; public start() // entry point { work = new Work(); } }
Log l = null; try { l = new Log(); ... } finally { l.exit(); }
private List<Log> logs= new ArrayList<Log>(); private static DataModel instance; private Context ctx; //Singleton constructor private DataModel() { //This makes it crash logs.add(new Log("1234","sms", 123545, 1, 0)); int i=0; //Load logs from database - Not done yet. } public static DataModel getInstance() { if (instance == null) { //Creates the instance instance = new DataModel(); } return instance;
public class DataModel { private List<Log> logs; private static DataModel instance; private Context ctx; //Singleton constructor private DataModel() { if(logs == null){ logs = new ArrayList<Log>(); } logs.add(new Log("1234","sms", 123545, 1, 0)); //Load logs from database - Not done yet. } public synchronized static DataModel getInstance() { if (instance == null) { //Creates the instance instance = new DataModel(); } return instance; }
log = new Log() { public boolean isWarnEnabled() { return false; } public boolean isInfoEnabled() { return false; }
try{ Foo foo = (Foo) pjp.proceed(); Log log = new Log(); log.setFoo(foo);
private static void calculateOnArray(double[] doubles, MathOperation operation) { int count = 0; for (double i : doubles){ doubles[count] = operation.f(i); count += 1; } } public static double[] ln(double[] z) { calculateOnArray(z, new Log()); return z; } public static double[] inverse(double[] z) { calculateOnArray(z, new Invert()); return z; }
Log log = new Log(); Needed to set ID before adding it to mAdapter log.setmDate(date); log.setmAmount(amount); log.setmMiles(miles); mDataSource.insert(date, amount, miles, OilTable.TAG); log.setmId(mDataSource.getLastLogID(OilTable.TAG)); mAdapter.add(log);