添加打印机端口监视器错误

tech2022-09-03  111

添加打印机端口监视器错误

The pursuit of building an error-free application continues. But in the meanwhile, we need to monitor our application’s errors and take action quickly. Many companies have tried to solve this problem, and one of the best on the market right now is Bugsnag.

对构建无错误应用程序的追求仍在继续。 但是与此同时,我们需要监视应用程序的错误并Swift采取措施。 许多公司都试图解决这个问题,而Bugsnag是目前市场上最好的公司之一 。

They focus on the problem of providing a bug notification system that makes sense of errors and helps you take action in various ways. In this article, we’re going to discover Bugsnag and integrate it into an existing Laravel application. You can clone the demo app from Github to follow along.

他们专注于提供一个错误通知系统的问题,该系统可以识别错误并帮助您采取各种措施。 在本文中,我们将发现Bugsnag并将其集成到现有的Laravel应用程序中。 您可以从Github克隆演示应用程序以进行后续操作。

项目设置 (Project Setup)

You can follow the instructions below to set up the demo application (it is assumed you have a working PHP environment like this one).

您可以按照下面的说明来设置演示应用程序(假定您具有像这样的工作PHP环境)。

// clone the repo git clone git@github.com:Whyounes/bugsnag_demo.git cd bugsnag_demo // update dependencies composer update // migrate and seed the database php artisan migrate && php artisan db:seed

在BugSnag上创建帐户 (Creating an Account on BugSnag)

Before starting to use Bugsnag, we need to create a new account and create our new project. You can start with a 30 day free trial and switch to a paid plan depending on your application’s size. After signing up, you’ll have to create a new project and specify your project type. In our case, that’ll be PHP.

在开始使用Bugsnag之前,我们需要创建一个新帐户并创建我们的新项目。 您可以从30天免费试用开始,然后根据应用程序的大小切换到付费计划。 注册后,您必须创建一个新项目并指定您的项目类型。 在我们的例子中,将是PHP。

将BugSnag添加到我们的项目中 (Adding BugSnag to Our Project)

Bugsnag provides a list of notifiers for different application types. We’re going to install and configure the PHP notifier package. Alternatively, because the demo application is built using Laravel 4, you may want use the Laravel package and follow the Laravel integration guide to easily set up your project, but in this case, we’ll take a more framework-agnostic approach.

Bugsnag提供了针对不同应用程序类型的通知程序列表 。 我们将安装和配置PHP通告程序包 。 另外,由于演示应用程序是使用Laravel 4构建的,因此您可能需要使用Laravel软件包并遵循Laravel集成指南来轻松设置项目,但是在这种情况下,我们将采用与框架无关的方法。

Require bugsnag/bugsnag:2.* using Composer.

使用Composer需要bugsnag/bugsnag:2.* 。

Grab your project API key from project dashboard > settings in Bugsnag’s control panel. You can store your API key in your environment variables or inside a configuration file depending on your application. In this case, we’re going to add it to our app/config/app.php.

从Bugsnag的控制面板中的project dashboard > settings中获取项目API密钥。 您可以根据应用程序将API密钥存储在环境变量中或配置文件中。 在这种情况下,我们将其添加到我们的app/config/app.php 。

// app/config/app.php return array( // ... 'bugsnag_api_key' => 'YOUR KEY' // ... );

Inside app/start/global.php, we bind and configure our Bugsnag client.

在app/start/global.php内部,我们绑定并配置Bugsnag客户端。

// app/start/global.php App::singleton('bugsnag', function() { $bugsnag = new Bugsnag_Client( Config::get('app.bugsnag_api_key') ); return $bugsnag; }); // ...

The container dependency injection setup will vary, depending on your application. The above case is common for Laravel apps.

容器依赖项注入设置会因您的应用程序而异。 以上情况对于Laravel应用程序很常见。

Additionally, you can optionally set a release stage with:

另外,您可以选择设置发布阶段:

$bugsnag->setReleaseStage(App::environment());

This will make Bugsnag log errors only during a specific release stage of an application.

这将仅在应用程序的特定发布阶段使Bugsnag记录错误。

After creating the Bugsnag client, you should attach it to your error handler. This will depend on how you manage errors and exceptions inside your application. Laravel provides fatal and error methods which accept a callback handler, but you can also use PHP’s set_exception_handler and set_error_handler.

创建Bugsnag客户端后,应将其附加到错误处理程序。 这将取决于您如何在应用程序内部管理错误和异常。 Laravel提供了fatal和error方法,它们接受回调处理程序,但是您也可以使用PHP的set_exception_handler和set_error_handler 。

// app/start/global.php App::error(function($exception) { App::make('bugsnag')->notifyException($exception, null, "error"); }); App::fatal(function($exception) { App::make('bugsnag')->notifyException($exception, null, "error"); });

The notifyException method accepts additional meta data as a second parameter and the error level as a third parameter, which will default to warning. However, if you want to attach it directly to the PHP error and exception handlers.

notifyException方法将其他元数据作为第二个参数,将错误级别作为第三个参数,这将默认为warning 。 但是,如果要直接将其附加到PHP错误和异常处理程序。

$bugsnag = App::make('bugsnag'); set_error_handler(array($bugsnag, 'errorHandler')); set_exception_handler(array($bugsnag, 'exceptionHandler'));

配置Bugsnag (Configuring Bugsnag)

Adding user details to the error: By default, Bugsnag sends the ID of the logged in user with the error, but you can change that by updating the Bugsnag client instance on the container.

向错误中添加用户详细信息:默认情况下,Bugsnag发送带有错误的登录用户的ID,但是您可以通过更新容器上的Bugsnag客户端实例来更改该ID。

// app/start/global.php App::make('bugsnag')->setUser([ 'email' => Auth::check() ? Auth::user()->email : 'Guest user' ]);

Now we can see the user’s username in the error details by selecting the user tab.

现在,通过选择user选项卡,可以在错误详细信息中看到用户的用户名。

You can also alter the error object being sent to the server by using the setBeforeNotifyFunction method which accepts a callable function as a parameter.

您还可以使用setBeforeNotifyFunction方法更改将发送给服务器的错误对象,该方法接受可调用函数作为参数。

// app/start/global.php App::make('bugsnag')->setBeforeNotifyFunction(function($error) { $error->setMetaData([ "user" => [ "username" => Auth::check() ? Auth::user()->username : 'Guest user' ], "metrics" => [ "Metric 1" => "Some data here" ] ]); });

If you noticed on the screenshot above, we have a list of tabs to group meaningful details about the error. We can update existing ones like the USER tab, and add new ones for metrics, etc.

如果您在上面的屏幕截图中注意到,我们有一个选项卡列表,用于将有关该错误的有意义的详细信息分组。 我们可以更新USER标签等现有标签,并为指标添加新标签等。

To avoid sensitive details about your customers or application leaking out, you can add a list of attributes that you want to filter out to your Bugsnag client instance. The value will appear as [FILTERED] on your dashboard.

为了避免泄露有关客户或应用程序的敏感细节,您可以向Bugsnag客户端实例添加要过滤掉的属性列表。 该值将在仪表板上显示为[FILTERED] 。

// app/start/global.php App::singleton('bugsnag', function() { $bugsnag = new Bugsnag_Client( Config::get('app.bugsnag_api_key') ); $bugsnag->setFilters([ 'password' ]); return $bugsnag; }); // ...

Bugsnag资讯主页 (Bugsnag Dashboard)

After creating our Bugsnag account and attaching it to the application, we need to visit the dashboard to explore the different available components. We can choose between the Inbox view, which shows us the list of errors as a list that we can filter through, or switch to the timeline graph page by clicking on the timeline link on the top of the page. You can check the documentation for more details about the timeline graph dashboard.

创建我们的Bugsnag帐户并将其附加到应用程序后,我们需要访问仪表板以探索不同的可用组件。 我们可以在“ Inbox视图中进行选择,该视图将错误列表显示为可以过滤的列表,或者通过单击页面顶部的timeline链接来切换到时间线图页面。 您可以查看文档以获取有关时间线图仪表板的更多详细信息。

让我们产生一些错误 (Let’s Generate Some Errors)

Inside our questions view template, we display the question owner’s username. The user being deleted would cause a problem, and throw an error. (Trying to get property of non-object). If we have a lot of users accessing the questions page (which you can simulate by requesting the same page multiple times), it could clutter our errors dashboard with the same bug. If you seeded the database using the artisan db:seed command, you’ll have a question assigned to a user with an id of 10, which doesn’t exist in the database.

在问题视图模板中,我们显示问题所有者的用户名。 被删除的用户会引起问题,并引发错误。 ( Trying to get property of non-object )。 如果我们有很多用户访问问题页面(您可以通过多次请求同一页面来模拟问题页面),则可能会由于相同的错误而使我们的错误信息中心混乱。 如果使用artisan db:seed命令为数据库设置db:seed ,则将有一个分配给ID为10的用户的问题,该问题在数据库中不存在。

We don’t have to worry about repetitive errors being displayed on the dashboard, and apply any grouping to them. After parsing your errors, Bugsnag will decide if we’re dealing with a repetitive or a new error. Here is an example from our application.

我们不必担心仪表板上会显示重复的错误,也无需对它们进行任何分组。 解析您的错误后,Bugsnag将决定我们要处理的是重复性错误还是新的错误。 这是我们应用程序中的一个示例。

We can fix this error by adding a simple test before accessing the username property on the object.

我们可以通过在访问对象的username属性之前添加一个简单测试来解决此错误。

// app/views/user/questions.blade.php // ... {{ isset($question->user) ? $question->user->username : 'User deleted' }} //...

筛选器 (Filters)

To investigate our errors, Bugsnag provides us with a set of filters to drill down on the data and gather specific details about the source of the problem.

为了调查我们的错误,Bugsnag为我们提供了一组过滤器,以深入挖掘数据并收集有关问题根源的特定详细信息。

You can filter errors by time using the date range selector on the top filter bar, or see all errors by selecting the all filter.

您可以使用顶部过滤器栏上的日期范围选择器按时间过滤错误,或者通过选择all过滤器查看所有错误。

A better way to filter errors is by data – like user, error status, severity, assigned to X, etc. You can check the documentation for the list of supported filters. Because Bugsnag parses your error messages when you send them, it will help auto-complete the search terms for hostnames, release stage, etc.

过滤错误的一种更好的方法是通过数据-如用户,错误状态,严重性,分配给X等。您可以查看文档以获取支持的过滤器列表。 由于Bugsnag在发送错误消息时会对其进行分析,因此将有助于自动完成主机名,发布阶段等搜索条件。

添加合作者 (Adding Collaborators)

There is a good chance that you’re not working alone on your project, or you’re the project manager. You can add project collaborators by going to the top right corner and clicking the collaborators link.

您很有可能不是一个人在项目上工作,或者您是项目经理。 您可以通过右上角单击collaborators链接来添加项目协作者。

Bugsnag parses the errors and groups them accordingly to avoid long repetitive lists. After selecting an error, we can assign it to an existing collaborator or invite a new one.

Bugsnag解析错误并相应地对它们进行分组,以避免冗长的重复列表。 选择错误后,我们可以将其分配给现有的协作者或邀请新的协作者。

错误状态 (Error Status)

The left sidebar on the dashboard shows the list of errors grouped by status, (Open, In progress, Fixed, Snoozed, Ignored). After selecting an error, we can change its status in the top left bar.

仪表板上的左侧栏显示了按状态分组的错误列表(“ 打开”,“进行中”,“已修复”,“被延后”,“已忽略” )。 选择错误后,我们可以在左上方栏中更改其状态。

By default, Bugsnag will only show status:open errors to help us identify active errors, but we can change that using the aforementioned filters.

默认情况下,Bugsnag仅显示status:open错误,以帮助我们识别活动错误,但是我们可以使用上述过滤器进行更改。

暂停和忽略错误 (Snoozing and Ignoring Errors)

If you have an error occurring frequently and your team is currently working on a fix for it, you can snooze it for a specific period or by using a condition.

如果您经常发生错误,并且您的团队正在为该错误进行修复,则可以将其暂停特定时间或使用条件。

If you’d like to ignore this error – which is not recommended for production – you can do so by using the ignore button next to the snooze option on the actions menu.

如果您想忽略此错误(不建议在生产环境中使用),可以使用操作菜单上贪睡选项旁边的忽略按钮来做到这一点。

第三方通知 (Third Party Notifications)

Teams often use multiple apps and services for their development process. Bugsnag offers a list of notification plugins that we can configure to send notifications for different types of errors. You can notify your team on Slack, create issues on Github, post to your server’s webhook, etc.

团队通常在其开发过程中使用多个应用程序和服务。 Bugsnag提供了通知插件列表,我们可以将其配置为针对不同类型的错误发送通知。 您可以在Slack上通知您的团队,在Github上创建问题,发布到服务器的Webhook等。

松弛通知 (Slack Notifications)

Navigate to our project settings and click on the Team Notifications link to display the list of integrations, then select Slack.

导航到我们的项目设置,然后单击“ Team Notifications链接以显示集成列表,然后选择“松弛”。

We need to specify when it should notify us and how often. Then, we need to get our Slack webhook URL by following the link above the input, paste the URL, and send a test notification.

我们需要指定何时通知我们以及通知频率。 然后,我们需要通过点击输入上方的链接来获取Slack webhook URL,粘贴URL并发送测试通知。

创建Github问题 (Creating a Github Issue)

The other way to act on error notifications is to create a new Github issue. Navigate to our project settings and click on the Issue Tracker link to display the list of integrations, then select Github issues.

处理错误通知的另一种方法是创建新的Github问题。 导航到我们的项目设置,然后单击“ Issue Tracker链接以显示集成列表,然后选择Github问题。

结论 (Conclusion)

Bugsnag provides a nice platform for automating one’s error tracking system and save the time of going through logs, creating monitoring scripts, etc. You can focus on building your application while keeping an eye on what’s happening on your production release.

Bugsnag提供了一个很好的平台来自动化错误跟踪系统,并节省了通过日志,创建监视脚本等的时间。您可以专注于构建应用程序,同时关注生产版本中发生的情况。

Bugsnag has already attracted some big companies like Github, Cisco, LinkedIn, etc. You can start by creating your 30 days trial to explore available features and switch to a paid plan if you really like it. If you’re using another error monitoring platform, or you’ve already tried Bugsnag, let us know what you think!

Bugsnag已经吸引了一些大公司,例如Github,Cisco,LinkedIn等。您可以从创建30天的试用版开始,以探索可用的功能,如果您真的喜欢,可以改用付费计划。 如果您正在使用其他错误监视平台,或者已经尝试过Bugsnag,请告诉我们您的想法!

翻译自: https://www.sitepoint.com/laravel-with-bugsnag-the-last-error-monitor-youll-need/

添加打印机端口监视器错误

相关资源:“性能监视器计数器要求错误”的解决方法
最新回复(0)