Centralize log management with Sentry

Source: Internet
Author: User

In the debugging program, through the log staging to troubleshoot the bug is an important means, it can be described as a tool for debugging the program.

About Log Management

As the application components become more, then each coder to the output log a variety of, there are write stdout, write stderr, have written to the syslog, also write to Xxx.log. Then this will cause the Platform Application log to be distributed everywhere and cannot be managed uniformly.

Why Use Sentry

Sentry is a centralized log management system. It has the following advantages:

    • Multi-project, multi-user
    • Friendly interface
    • You can configure exception departure rules, such as sending messages
    • Support for mainstream language interfaces
Installation reference

https://docs.getsentry.com/on-premise/server/installation/

Requirements
    • Linux Server
    • PostgreSQL
    • Redis-server
    • Python 2/3
    • Nginx
Steps

Install dependent packages

sudo apt-get install python-setuptools python-pip python-dev libxslt1-dev libxml2-dev libz-dev libffi-dev libssl-dev LIBP Q-dev Libyaml-dev

Installing Sentry

Pip Install-u sentry==8.0.0rc2
Configuration

Vim sentry.conf.py

DATABASES = {'    default ': '        ENGINE ': ' Sentry.db.postgres ',        ' NAME ': ' Sentry ',        ' USER ': ' Postgres ',        ' PASSWORD ': ' 123456 ',        ' HOST ': ' localhost ',        ' PORT ': ' 5432 ',    }}email_host = ' smtp.exmail.qq.com ' Email_host_password = ' he******* ' email_host_user = ' [EMAIL protected] ' Email_port = 25EMAIL_USE_TLS = False

Setting the configuration file path to environment variables

Export Sentry_conf=/home/hewx/workbench/sentry

Initializing the database

Sentry Update

Configure the Web Server

SudoApt-getInstallNginx-fullSudoVim/etc/Nginx/Sites-enabled/DefaultLocation/{proxy_pass http://localhost:9000; proxy_redirect off; Proxy_set_header host $host; proxy_set_header X-forwarded-for $proxy_add_x_forwarded_for; proxy_set_header X-forwarded-Proto $Scheme;}     
Start

Start Wokers

Sentry Celery Worker-b

Start the Web service

Sentry Start
Example PHP

Use a browser to access sentry and create a project

Refer to PHP usage directives http://10.0.0.180/sentry/45183e54fa36/settings/install/php/

<?PhpRequire_once"Vendor/autoload.php";$Client=NewRaven_client(‘http:5d68caa5e36c4eaa8f7c0601a521fab6:[email PROTECTED]/3 ');$Error_Handler=NewRaven_errorhandler ($clienterror_handler->registerexceptionhandler (); $error_handler->registererrorhandler  (); $error_handler->registershutdownfunction< Span class= "P" > (); $client->capturemessage ( Span class= "s" > "There was a mistake here" ); $i = 1 /0< Span class= "P"; ?>                
Python

Pip Install Raven

Clientclient(' http://f1ba62aa87cb4fc1a36d9e4f96017e99:[email protected]/4 ')try 0zerodivisionerrorclient.  Captureexception()          
Javascript
<!DOCTYPEHtml><Html><Head><MetaCharSet="Utf-8"><Title>SentryTest</Title></Head><Body><ScriptSrc="Https://cdn.ravenjs.com/2.0.1/raven.min.js"></Script><Script>Raven.config ( ' http: //[EMAIL&NBSP;PROTECTED]/5 '). Install () try { Dosomething (a[0} catch (e) { span class= "n" >raven. Captureexception (e) } </script> </body> </html>          
Android

Https://github.com/joshdholtz/Sentry-Android/tree/android-studio-ify

ImportCom.joshdholtz.sentry.Sentry;PublicClassMainactivityExtendsAppcompatactivity{@OverrideProtectedvoidOnCreate(BundleSavedinstancestate){Super.OnCreate(Savedinstancestate);Setcontentview(R.Layout.Activity_main);Sentry.Init(This,"Http://10.0.0.180","Http://340137fc1dc6443e99d9d02b8f1638d0:[email PROTECTED]/6");Sentry.Capturemessage("OMG This works woooo");IntA=1/0;}......RuntimeException:UnableToStartActivityComponentInfo{Com.Joshdholtz.Sentrytesting/Com.Joshdholtz.Sentryapp.Mainactivity}:Java.Lang.ArithmeticException:DivideByZeroModule"Android.app.ActivityThread",Line2189,InchPerformlaunchactivityModule"Android.app.ActivityThread",Line2238,InchHandlelaunchactivityModule"Android.app.ActivityThread",Line138,InchAccess$800Module"Android.app.activitythread$h",Line1201,InchHandlemessageModule"Android.os.Handler",Line102,InchDispatchMessageModule"Android.os.Looper",Line136,InchLoopModule"Android.app.ActivityThread",Line5016,InchMainModule"Java.lang.reflect.Method",InchInvokenativeModule"Java.lang.reflect.Method",Line515,InchInvokeModule"Com.android.internal.os.zygoteinit$methodandargscaller",Line792,InchRunModule"Com.android.internal.os.ZygoteInit",Line608,InchMainModule"Dalvik.system.NativeStart",InchMainArithmeticException:DivideByZeroModule"Com.joshdholtz.sentryapp.MainActivity",Line20,InchOnCreatemodule  "android.app.Activity" line 5251, in performcreate module "Android.app.Instrumentation", line 1087, in callactivityoncreate module "Android.app.ActivityThread", line 2153, in performlaunchactivity Module "Android.app.ActivityThread", line 2238, in Handlelaunchactivity module "Android.app.ActivityThread", line 138, in access$800 module "android.app.activitythread$h ", line 1201, in handlemessage module" Android.os.Handler ", line 102, DispatchMessage module" Android.os.Looper ", line 136, in Loop Module ' Android.app.ActivityThread ', line 5016, in main Module ' Java.lang.reflect.Method ', in Invokenative Mo Dule "Java.lang.reflect.Method", line 515, in Invoke Module "Com.android.internal.os.zygoteinit$methodandargscaller", Line 792, in run module ' Com.android.internal.os.ZygoteInit ', line 608, in main module ' Dalvik.system.NativeStart ', in Mai n     

Centralized log management with sentry

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.