Table of contents
Download the official source code
Open the Logan Server project with IDEA
Use Docker to download the MySQL image and start the container
Configure Maven to use Tomcat to run the program
Open LoganSite with Visual Code
The request failed with Network Error #323.
File load 404 #219 on LoganSite access.
Does Server SDK have more detailed tutorials? #315
foreword
This article is carried from the author's Yuque blog. A few days ago, I found that some netizens liked it, and I thought it was helpful, so I shared it. After all, CSDN's SEO is very good.
Logan is a large front-end log system launched by Meituan Dianping Group. The name is a combination of Log and An, which stands for the individual log service and is also the name of Uncle Wolverine.
overview
Logan's open source is a complete set of log system, including log collection and storage, reporting and analysis, and visual display. We provide five components, including end-to-end log collection and storage, iOS SDK , Android SDK , Web SDK , back-end log storage and analysis Server , and log analysis platform LoganSite . And a Flutter plugin Flutter plugin is provided .
Overall structure
quick start
This is not the handling of official documents, but a hand-in-hand teaching to set up and run the log system. If you just read the documents, there will indeed be some steps that get stuck and cannot be resolved. This article is a supplement to the official documentation and an answer to some questions about Github Issues.
If a worker wants to do a good job, he must first sharpen his tools. Here, you need to prepare the following tools first: Linux development environment (Windows system is also available), Npm, Node.js, Yarn, Java8, IDEA, Docker, AndroidStudio, and an Android phone.
Okay, pretend you're ready and read on.
Download the official source code
The first step, of course, is to download the source code. If using Github is not smooth, you can refer to the following methods:
It is recommended to use the SwitchHosts tool to manage hosts and access Github more conveniently.
How to use, add a Hosts, fill in with reference to the following content:
Title: Random
Type: Remote
URL: https://raw.hellogithub.com/hosts
Auto Refresh: 1 hour is best
Tool source:
https://github.com/521xueweihan/GitHub520
https://github.com/oldj/SwitchHosts
Here I download the source code to the local directory: /work/LogCenter/, unzip it, and at the same time, I also create two new directories, applogs and MySql, which will be used later.
Open the Logan Server project with IDEA
Use IDEA to open the Logan Sever project for backup, directory: /work/LogCenter/Logan/Logan/Server.
If you look at the official documentation, here the official only gives the sql statement to create the table, I said it is very convenient, because you need to use the MySQL database, so here is the introduction of using Docker to build the MySQL environment, if you are not interested, please skip this chapter.
Use Docker to download the MySQL image and start the container
I don't need to say how to install Docker.
Link to see for yourself: Docker Tutorial | Rookie Tutorial
Open the command line terminal, enter: docker pull mysql:5.7, press Enter to execute, as follows:
pc:~$ docker pull mysql:5.7 5.7: Pulling from library/mysql 33847f680f63: Already exists 5cb67864e624: Already exists 1a2b594783f5: Already exists b30e406dd925: Already exists 48901e306e4c: Already exists 603d2b7147fd: Already exists 802aa684c1c4: Already exists 5b5a19178915: Pull complete f9ce7411c6e4: Pull complete f51f6977d9b2: Pull complete aeb6b16ce012: Pull complete Digest: sha256:be70d18aedc37927293e7947c8de41ae6490ecd4c79df1db40d1b5b5af7d9596 Status: Downloaded newer image for mysql:5.7 docker.io/library/mysql:5.7
Wait for the image download to complete. Enter: docker images, view the image as follows:
pc:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE kibana elastdocker-7.12.0 5ffdef382e6f 2 days ago 1.05GB logstash elastdocker-7.12.0 97fe3f5ae942 2 days ago 971MB elasticsearch elastdocker-7.12.0 1ad2d4e4b508 2 days ago 830MB elastic_certs latest 1ad2d4e4b508 2 days ago 830MB elastic_keystore latest 1ad2d4e4b508 2 days ago 830MB docker.elastic.co/beats/metricbeat 7.14.0-arm64 9dc075992137 13 days ago 1.19GB docker.elastic.co/beats/metricbeat 7.14.0 e3583bac930e 13 days ago 517MB mysql 5.7 8cf625070931 3 weeks ago 448MB mysql latest c60d96bd2b77 3 weeks ago 514MB docker.elastic.co/kibana/kibana 7.12.0 7a6b1047dd48 4 months ago 1.05GB docker.elastic.co/elasticsearch/elasticsearch 7.12.0 9337ed510a0c 4 months ago 830MB docker.elastic.co/logstash/logstash 7.12.0 c283394286f5 4 months ago 971MB jenkins v1.0.0 fab8efdd0aef 14 months ago 6.12GB jenkins test 1eb52b79643e 14 months ago 978MB hub.c.163.com/public/ubuntu 16.04-tools 1196ea15dad6 4 years ago 336MB
see it? There is a line: mysql 5.7 is the image we just downloaded. Next, we write the docker-compose configuration to start the mysql:5.7 container.
Create a new mysql-5.7.yml in the MySql directory, and write the following content:
version: '2.0' services: mysql: container_name: "logan-mysql-5.7" environment: MYSQL_ROOT_PASSWORD: "123456" image: "mysql:5.7" restart: always ports: - 3316:3306
You can understand it, if you don’t understand it, learn first: Docker Compose | Rookie Tutorial
Enter the /home/work/LogCenter/MySql directory from the command line terminal
Enter the command: docker-compose -f mysql-5.7.yml up -d
/home/work/LogCenter/MySql$ docker-compose -f mysql-5.7.yml up -d
Creating network "mysql_default" with the default driver
Creating logan-mysql-5.7 ... done
Enter the command: docker-compose ps or docker ps to view the started container, the state is Up means it is running.
/home/work/LogCenter/MySql$ docker-compose ps
Name Command State Ports
-----------------------------------------------------------------------------------------
logan-mysql-5.7 docker-entrypoint.sh mysqld Up 0.0.0.0:3316->3306/tcp, 33060/tcp
At this time, use Navicat or DBeaver to connect and test, see mysql-5.7.yml for the port number and password, and it is successful.
Sometimes not so lucky. The reason for not being able to connect is often the wrong password, or the remote login restricts the ip. At this time, you need to enter the MySQL container and connect to the database to modify it.
Reference: docker deploys mysql sample code for remote connection
The login is successful, create a new database named logan, execute the official sql, and create the corresponding table. The corresponding sql statement is in this position:
At this point, the MySQL development environment is set up.
Running Logan Server
At this point, it can finally run. Logan Server is a project managed by Maven, so when importing a project, choose Maven.
Modify db.properties
Modify the IP to 1270.0.1, the port to 3316, the database to logan, the account to root, and the password to 123456, according to your msql configuration.
jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://127.0.0.1:3316/logan?characterEncoding=UTF8&allowMultiQueries=true&socketTimeout=60000&autoReconnect=true jdbc.username=root jdbc.password=123456
Modify log4j.properties
Modify log4j.appender.R.File=/home/lb/work/LogCenter/applogs, which is the directory created in the previous preparations.
log4j.rootLogger=ERROR,R,stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n log4j.appender.R=org.apache.log4j.DailyRollingFileAppender log4j.appender.R.File=/home/lb/work/LogCenter/applogs/logan.log log4j.appender.R.layout=org.apache.log4j.PatternLayout log4j.appender.R.layout.ConversionPattern=%d-[TS] %p %t %c - %m%n
Configure Maven to use Tomcat to run the program
At this time, the program cannot be run yet, and it needs to be configured.
Click Add Configuration--> + Maven + OK in turn.
Fill in the Command line, fill in tomcat:run, and click OK.
Then you can click the green triangle button to run the program.
We tried to run it, and reported an error. Sure enough, it was too young too simple.
Reported this error: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project logan-web: Fatal error compiling
After some searching, it was said that it was caused by inconsistent Java versions:
Well, check pom.xml, there is no Java version configuration. Then go to File-->Project Structure and set the Project SDK to version 1.8.
Run it again and it looks like it worked.
Please remember the Url address of Sever in the picture: http://localhost:8080/logan-web , it will be used right away.
Access Logan Server
Open the browser and visit the server Url printed by the console: http://localhost:8080/logan-web , but an error is reported, are you tired?
Look at the console output again:
[INFO] [INFO] --------------------< com.meituan.logan:logan-web >--------------------- [INFO] Building logan-web 1.0-SNAPSHOT [INFO] --------------------------------[ war ]--------------------------------- [INFO] [INFO] >>> tomcat-maven-plugin:1.1:run (default-cli) > compile @ logan-web >>> [INFO] [INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ logan-web --- [debug] execute contextualize [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 7 resources [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ logan-web --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] <<< tomcat-maven-plugin:1.1:run (default-cli) < compile @ logan-web <<< [INFO] [INFO] [INFO] --- tomcat-maven-plugin:1.1:run (default-cli) @ logan-web --- [INFO] Running war on http://localhost:8080/logan-web [INFO] Using existing Tomcat server configuration at /home/work/IdeaProjects/Logan-master/Logan/Server/target/tomcat 八月 13, 2021 6:39:29 下午 org.apache.catalina.startup.Embedded start 信息: Starting tomcat server 八月 13, 2021 6:39:29 下午 org.apache.catalina.core.StandardEngine start 信息: Starting Servlet Engine: Apache Tomcat/6.0.29 八月 13, 2021 6:39:30 下午 org.apache.catalina.core.ApplicationContext log 信息: Initializing Spring root WebApplicationContext *********post initializaitonAugust *********post initializaiton 13, 2021 6:39:32 pm org.apache.catalina.core.ApplicationContext log information: Initializing Spring DispatcherServlet 'mvc-dispatcher'August 13, 2021 6:39 :32 PM org.apache.coyote.http11.Http11Protocol init Info: Initializing Coyote HTTP/1.1 on http-8080 Aug 13, 2021 6:39:32 PM org.apache.coyote.http11.Http11Protocol start Info: Starting Coyote HTTP /1.1 on http-8080 Aug 13, 2021 6:40:28 pm org.apache.jasper.compiler.JDTCompiler$1 findType severe: Compilation error org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException at org.eclipse. jdt.internal.compiler.classfmt.ClassFileReader.<init>(ClassFileReader.java:342) at org.apache.jasper.compiler.JDTCompiler$1.findType(JDTCompiler. java:206) at org.apache.jasper.compiler.JDTCompiler$1.findType(JDTCompiler.java:163) at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(LookupEnvironment.java:96) at org.eclipse.jdt.internal.compiler.lookup.UnresolvedReferenceBinding.resolve(UnresolvedReferenceBinding.java:49) at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.resolveType(BinaryTypeBinding.java:97) at org.eclipse.jdt.internal.compiler.lookup.PackageBinding.getTypeOrPackage(PackageBinding.java:167) at org.eclipse.jdt.internal.compiler.lookup.Scope.getType(Scope.java:2187) at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:974) at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1164) at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.java:366) at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:623) at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:392) at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:429) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:349) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:327) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:314) at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at com.meituan.logan.web.filter.CORSFilter.doFilter(CORSFilter.java:47) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:748) 八月 13, 2021 6:40:28 下午 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for servlet jsp threw exception org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 1 in the generated java file The type java.io.ObjectInputStream cannot be resolved. It is indirectly referenced from required .class files Stacktrace: at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92) at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330) at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:349) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:327) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:314) at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at com.meituan.logan.web.filter.CORSFilter.doFilter(CORSFilter.java:47) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:748)
It's great, it's really not a server development, running a project is so rough.
Du Niang search: org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException
Said Tomcat version is too low:
Tomcat startup exception: org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException
Very good, Almighty Du Niang. Try upgrading the Tomcat version. Configure the tomcat7 plugin in pom.xml.
<plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <port>8888</port> </configuration> </plugin>
After adding the configuration, click Maven synchronization.
Then edit Maven's Command Line to: tomcat7:run, click OK to save.
Then just run it.
Of course, you can run it directly through the Maven Tomcat7 plug-in on the right, as you like.
Using Tomcat7 may cause the following errors.
八月 13, 2021 6:20:35 下午 org.apache.catalina.core.StandardService startInternal 信息: Starting service Tomcat 八月 13, 2021 6:20:35 下午 org.apache.catalina.core.StandardEngine startInternal 信息: Starting Servlet Engine: Apache Tomcat/7.0.47 八月 13, 2021 6:20:37 下午 org.apache.catalina.startup.ContextConfig processAnnotationsJar 严重: Unable to process Jar entry [module-info.class] from Jar [jar:file:/home/nxg/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.10.1/jackson-annotations-2.10.1.jar!/] for annotations org.apache.tomcat.util.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 19 at org.apache.tomcat.util.bcel.classfile.Constant.readConstant(Constant.java:133) at org.apache.tomcat.util.bcel.classfile.ConstantPool.<init>(ConstantPool.java:60) at org.apache.tomcat.util.bcel.classfile.ClassParser.readConstantPool(ClassParser.java:209) at org.apache.tomcat.util.bcel.classfile.ClassParser.parse(ClassParser.java:119) at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2134) at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:2010) at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1976) at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1961) at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1319) at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:878) at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:376) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119) at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5322) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)
Baidu searched related articles saying that this has no effect. The actual test verifies that this error report does not have any effect, so skip it first.
When you may still encounter the following problems.
提示:Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:run (default-cli) on project logan-web: Could not start Tomcat
The method is also to try to run with the tomcat7 version.
The browser refreshes the webpage and outputs: hello, logan, it feels great, it is this kind of feel.
Run Logan Site
After running the backend, it's the frontend's turn. Prepare the Node.js development environment, Npm, Yarn and so on are indispensable, here is a little mention of the pits encountered.
Npm is very slow, you need to set the Taobao mirror source. See the tutorial: npm replaced with Taobao mirror source and cnpm
Do not use npm install to set the mirror source, use this method directly:
npm config set registry https://registry.npm.taobao.org
Open LoganSite with Visual Code
Open LoganSite Backup using Visual Code.
Environmental requirements
Node: ^10.15.3 yarn: ^1.15.2 or npm ^6.12.0
Install
run locally
Create a file in the LoganSite root directory .env.development
and specify the API_BASE_URL environment variable in it to:
API_BASE_URL=http://localhost:8080/logan-web
That's right, this url is the URL printed on the console in Logan Server.
Then execute the following command in the root directory of LoganSite, or execute the cd command to enter the root directory of LoganSite first.
$ yarn $ yarn start
Why is it not recommended to use npm, well, whoever uses it knows.
Note: .env.development
It must be placed in the root directory of LoganSite, and the url filled in must be the URL printed on the console in Logan Server.
If you encounter the same problem as Github Issue:
1. After LoganSite starts, it prompts an error: request error Network Error #323 .
2. After LoganSite starts, it prompts an error: 404 #219 when the file is loaded when LoganSite is connected .
Please check for modifications as above.
F12 opens the console, clicks the Network tab, usually:
http://localhost:8080/logan-web/logan/latest.json
This url request reports an error, you can see if this is the problem.
Run Logan-Android Sample
AndroidStudio directly imports the Logan-Android project. Because it relies on the Android-SDK source code, the NDK path needs to be set for compilation, and the NDK version is required to be less than or equal to 16.1.4479499. Add ndk.dir=/work/android/android-ndk-r15c to local.properties under the Logan-Android root directory, and fill in your NDK path as required.
## This file must *NOT* be checked into Version Control Systems, # as it contains information specific to your local configuration. # # Location of the SDK. This is only used by Gradle. # For customization when using a Version Control System, please read the # header note. #Wed Aug 11 18:04:17 CST 2021 sdk.dir=/work/android/android-sdk-linux ndk.dir=/work/android/android-ndk-r15c
Then modify the url here in test.logan.dianping.com.logan.RealSendLogRunnable as shown below:
The complete code is as follows:
/*
* Copyright (c) 2018-present, 美团点评
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package test.logan.dianping.com.logan;
import android.text.TextUtils;
import android.util.Log;
import com.dianping.logan.SendLogRunnable;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession;
public class RealSendLogRunnable extends SendLogRunnable {
private static final String TAG = "RealSendLogRunnable";
private String mUploadLogUrl = "http://192.168.1.139:8080/logan-web/logan/upload.json";
@Override
public void sendLog(File logFile) {
boolean success = doSendFileByAction(logFile);
Log.d("上传日志测试", "日志上传测试结果:" + success);
// Must Call finish after send log
finish();
if (logFile.getName().contains(".copy")) {
logFile.delete();
}
}
public void setIp(String ip) {
mUploadLogUrl = "http://" + ip + ":8080/logan-web/logan/upload.json";
}
private HashMap<String, String> getActionHeader() {
HashMap<String, String> map = new HashMap<>();
map.put("Content-Type", "binary/octet-stream"); //二进制上传
map.put("client", "android");
return map;
}
/**
* 主动上报
*/
private boolean doSendFileByAction(File logFile) {
boolean isSuccess = false;
try {
FileInputStream fileStream = new FileInputStream(logFile);
byte[] backData = doPostRequest(mUploadLogUrl, fileStream, getActionHeader());
isSuccess = handleSendLogBackData(backData);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return isSuccess;
}
private byte[] doPostRequest(String url, InputStream inputData, Map<String, String> headerMap) {
Log.i(TAG, "doPostRequest: url " + url);
int statusCode = -1;
byte[] data = null;
OutputStream outputStream = null;
InputStream inputStream = null;
HttpURLConnection c = null;
ByteArrayOutputStream back;
byte[] Buffer = new byte[2048];
try {
java.net.URL u = new URL(url);
c = (HttpURLConnection) u.openConnection();
if (c instanceof HttpsURLConnection) {
((HttpsURLConnection) c).setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
}
Set<Map.Entry<String, String>> entrySet = headerMap.entrySet();
for (Map.Entry<String, String> tempEntry : entrySet) {
c.addRequestProperty(tempEntry.getKey(), tempEntry.getValue());
}
c.setReadTimeout(15000);
c.setConnectTimeout(15000);
c.setDoInput(true);
c.setDoOutput(true);
c.setRequestMethod("POST");
outputStream = c.getOutputStream();
int i;
while ((i = inputData.read(Buffer)) != -1) {
outputStream.write(Buffer, 0, i);
}
outputStream.flush();
statusCode = c.getResponseCode();
if (statusCode == 200) {
back = new ByteArrayOutputStream();
inputStream = c.getInputStream();
while ((i = inputStream.read(Buffer)) != -1) {
back.write(Buffer, 0, i);
}
data = back.toByteArray();
}
} catch (ProtocolException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (inputData != null) {
try {
inputData.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (c != null) {
c.disconnect();
}
}
Log.d(TAG, "log send completed, http statusCode : " + statusCode);
return data;
}
/**
* 处理上传日志接口返回的数据
*/
private boolean handleSendLogBackData(byte[] backData) throws JSONException {
boolean isSuccess = false;
if (backData != null) {
String data = new String(backData);
if (!TextUtils.isEmpty(data)) {
JSONObject jsonObj = new JSONObject(data);
if (jsonObj.optBoolean("success", false)) {
isSuccess = true;
}
}
}
return isSuccess;
}
}
Note: The IP and port number need to be replaced with the IP and port number of the corresponding Logan Server. The Logan Server console here prints: http://localhost:8080/logan-web , but the Logan-Android Sample is running on other The device is on hand, so the localhost here needs to be changed to the actual IP of the Logan Server operating environment (LAN or server public network IP), and ensure
The device running Logan-Android Sample can access the actual IP of Logan Server.
There is another place that is also recommended to be modified. The loganSendByDefault method of test.logan.dianping.com.logan.MainActivity. The Logan Server Url filled here is the official platform of Meituan Dianping, but it is no longer accessible. Replace it with your own convenient test .
code show as below:
private void loganSendByDefault() {
String buildVersion = "";
String appVersion = "";
try {
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
appVersion = pInfo.versionName;
buildVersion = String.valueOf(pInfo.versionCode);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
//final String url = "https://openlogan.inf.test.sankuai.com/logan/upload.json";
final String url = "http://192.168.1.139:8080部分/logan-web/logan/upload.json";
SimpleDateFormat dataFormat = new SimpleDateFormat("yyyy-MM-dd");
final String date = dataFormat.format(new Date(System.currentTimeMillis()));
Logan.s(url, date, "1", "logan-test-unionid", "deviceId", buildVersion, appVersion, new SendLogCallback() {
@Override
public void onLogSendCompleted(int statusCode, byte[] data) {
final String resultData = data != null ? new String(data) : "";
Log.d(TAG, "日志上传结果, http状态码: " + statusCode + ", 详细: " + resultData);
}
});
}
When you are ready, run the Logan-Android Sample, and emphasize again that the device must be able to access the actual IP of the Logan Server (the same LAN or the server uses a public IP), and then click all the buttons on the App interface. If you see a log similar to the following, it means that the log is uploaded It worked.
2021-08-16 11:55:58.202 17982-17998/test.logan.dianping.com.logan D/test.logan.dianping.com.logan.MyApplication: clogan > cmd : clogan_init | code : -1010 2021-08-16 11:55:58.202 17982-17998/test.logan.dianping.com.logan D/LoganThread: Logan write start 2021-08-16 11:55:58.208 17982-17998/test.logan.dianping.com.logan D/test.logan.dianping.com.logan.MyApplication: clogan > cmd : clogan_open | code : -2010 2021-08-16 11:55:58.209 17982-17998/test.logan.dianping.com.logan D/test.logan.dianping.com.logan.MyApplication: clogan > cmd : clogan_write | code : -4010 2021-08-16 11:55:58.209 17982-17998/test.logan.dianping.com.logan D/LoganThread: Logan write start 2021-08-16 11:55:58.209 17982-17998/test.logan.dianping.com.logan D/LoganThread: Logan write start 2021-08-16 11:55:58.309 17982-17999/test.logan.dianping.com.logan I/mali_so: [File] : hardware/arm/maliT760/driver/product/base/src/mali_base_kbase.c; [Line] : 978; [Func] : base_context_deal_with_version_affairs_rk_ext; arm_release_ver of this mali_so is 'r14p0-01rel0', rk_so_ver is '5@0'. 2021-08-16 11:55:58.310 17982-17999/test.logan.dianping.com.logan D/mali_so: [File] : hardware/arm/maliT760/driver/product/base/src/mali_base_kbase.c; [Line] : 983; [Func] : base_context_deal_with_version_affairs_rk_ext; current process is NOT sf, to bail out. 2021-08-16 11:55:58.317 17982-17999/test.logan.dianping.com.logan I/OpenGLRenderer: Initialized EGL, version 1.4 2021-08-16 11:55:58.317 17982-17999/test.logan.dianping.com.logan D/OpenGLRenderer: Swap behavior 1 2021-08-16 11:55:58.328 17982-17999/test.logan.dianping.com.logan D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000 2021-08-16 11:56:00.225 17982-18031/test.logan.dianping.com.logan D/test.logan.dianping.com.logan.MainActivity: times : 0 2021-08-16 11:56:00.225 17982-17998/test.logan.dianping.com.logan D/LoganThread: Logan write start 2021-08-16 11:56:00.231 17982-18031/test.logan.dianping.com.logan D/test.logan.dianping.com.logan.MainActivity: times : 1 2021-08-16 11:56:01.339 17982-18035/test.logan.dianping.com.logan I/RealSendLogRunnable: doPostRequest: url http://192.168.1.139:8080/logan-web/logan/upload.json 2021-08-16 11:56:01.342 17982-18035/test.logan.dianping.com.logan D/NetworkSecurityConfig: No Network Security Config specified, using platform default 2021-08-16 11:56:01.608 17982-18035/test.logan.dianping.com.logan D/RealSendLogRunnable: log send completed, http statusCode : 200 2021-08-16 11:56:01.609 17982-18035/test.logan.dianping.com.logan D/上传日志测试: 日志上传测试结果:false 2021-08-16 11:56:01.793 17982-17998/test.logan.dianping.com.logan D/LoganThread: Logan send start 2021-08-16 11:56:01.793 17982-17998/test.logan.dianping.com.logan D/LoganThread: prepare log file 2021-08-16 11:56:01.794 17982-17998/test.logan.dianping.com.logan D/LoganThread: Logan flush start 2021-08-16 11:56:01.799 17982-18035/test.logan.dianping.com.logan I/SendLogDefaultRunnable: doPostRequest: url = http://192.168.1.139:8080/logan-web/logan/upload.json 2021-08-16 11:56:01.848 17982-18035/test.logan.dianping.com.logan D/SendLogDefaultRunnable: log send completed, http statusCode : 200 2021-08-16 11:56:01.848 17982-18035/test .logan.dianping.com.logan D/test.logan.dianping.com.logan.MainActivity: log upload result, http status code: 200, details: {"code":200,"msg":null,"data" :"/logan/downing?name=1_deviceId_1629043200000_23eb244a-7a65-4934-9095-26b2f346de43.log"}
Let's look at the database verification:
After finding two log records, go back to http://localhost:3000/ , press F5 to refresh, and indeed see two log records.
Click to view log details, nothing wrong.
Thanks for reading, this is the end of Logan's step-by-step getting started guide, please leave a message for more questions.
Some Github Issue solutions
Request failed Network Error #323 .
Solution:
Create a file in the LoganSite root directory .env.development
and specify the API_BASE_URL environment variable in it to:
API_BASE_URL=http://localhost:8080/logan-web
Note that this API_BASE_URL is the URL printed on the console in Logan Server, as shown in the figure below;
Note: .env.development
Be sure to put it in the root directory of LoganSite, and check whether the BASE_URL variable in src/common/api.js points to the variable configured in .env.development.
const BASE_URL = process.defineEnv.API_BASE_URL; const API_TIME_OUT = 30000; let pendingRequests = []; // axios instance const instance = axios.create({ baseURL: BASE_URL, timeout: API_TIME_OUT, withCredentials: true });
File load 404 #219 on LoganSite access .
Solution: Same as #323.
Does Server SDK have more detailed tutorials? #315
Solution: Check out the content of the chapter Running Logan Server in this article and click me to jump .