chapters.appenders.mail.Marked_EMail_Activity Maven / Gradle / Ivy
/**
* Logback: the reliable, generic, fast and flexible logging framework.
* Copyright (C) 2011-2012, Anthony Trinh. All rights reserved.
* Copyright (C) 1999-2011, QOS.ch. All rights reserved.
*
* This program and the accompanying materials are dual-licensed under
* either the terms of the Eclipse Public License v1.0 as published by
* the Eclipse Foundation
*
* or (per the licensee's choosing)
*
* under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation.
*/
package chapters.appenders.mail;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
/**
* This activity sends an email when the user presses a button on the main page.
* Note this application requires the Android Java Mail jars from
* http://code.google.com/p/javamail-android/ to be in the classpath
* or else an error occurs. Also remember to set the INTERNET permission in AndroidManifest.xml:
*
* <uses-permission android:name="android.permission.INTERNET"/>
*
*
* Example logback configuration:
*
* <configuration>
* <appender name="SMTP" class="ch.qos.logback.classic.net.SMTPAppender">
* <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
* <marker>TOO_BIG_ACCELERATION</marker>
* </evaluator>
* <cyclicBufferTracker class="ch.qos.logback.core.spi.CyclicBufferTrackerImpl">
* <!-- send just one log entry per email -->
* <bufferSize>1</bufferSize>
* </cyclicBufferTracker>
* <smtpHost>smtp.gmail.com</smtpHost>
* <smtpPort>465</smtpPort>
* <SSL>true</SSL>
* <username>[email protected]</username>
* <password>foo123</password>
* <to>[email protected]</to>
* <from>[email protected]</from>
* <subject>%date{yyyyMMdd'T'HH:mm:ss.SSS}; %-5level; %msg</subject>
* <layout class="ch.qos.logback.classic.PatternLayout">
* <pattern>%date{yyyyMMdd'T'HH:mm:ss.SSS}; %-5level; %msg%n</pattern>
* </layout>
* </appender>
*
* <root level="INFO">
* <appender-ref ref="SMTP" />
* </root>
* </configuration>
*
*
*
* @author Enrico Spinielli
*/
public class Marked_EMail_Activity extends Activity {
static private final Logger LOG = LoggerFactory.getLogger(Marked_EMail_Activity.class);
private static final Marker MARKER = MarkerFactory.getMarker("TOO_BIG_ACCELERATION");
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/* Get the button declared in our layout.xml, and
* set its click-event handler to log an error message
* (we had configured the logger to send an email).
*/
final Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
LOG.info(MARKER, "on marker email");
}
});
LOG.info("end of onCreate");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy