codeigniter

by Seun Matt

通过Seun Matt

如何在浏览器中查看CodeIgniter日志文件 (How to View CodeIgniter Log Files in the Browser)

Just like any other page, it is now possible to read CodeIgniter log files in the browser. My Sweet Goodness!

与其他页面一样,现在可以在浏览器中读取CodeIgniter日志文件。 我的天哪!

I began using CodeIgniter in my day to day coding after joining an awesome company. The company’s tech stack includes the PHP Framework — among others. Hitherto now, I’ve used (and still use) Laravel to build some awesome apps.

加入一家很棒的公司后,我开始使用CodeIgniter进行日常编码。 该公司的技术堆栈包括PHP框架等。 到目前为止,我已经使用( 并且仍然使用 )Laravel构建了一些很棒的应用程序。

Laravel has a great logging system that is simple and elegant. Furthermore, there’s a library for showing the logs in the browser. Being able to read the logs in the browser is good for application debugging and insight. Especially in a production environment.

Laravel有一个很棒的日志系统,简单而优雅。 此外,还有一个用于在浏览器中显示日志的库 。 能够在浏览器中读取日志有助于进行应用程序调试和洞察。 特别是在生产环境中。

So here I am in the world of CodeIgniter and couldn’t find an equivalent library to read my logs for debugging and insight.

因此,我在CodeIgniter的世界中,找不到等效的库来读取我的日志以进行调试和分析。

So I took up the challenge and created my first Open Source project of the year — codeigniter-log-viewer.

因此,我接受了挑战,并创建了本年度的第一个开源项目-codeigniter-log-viewer 。

用法 (Usage)

First, let’s add it to a dependency. We can do that by executing:

首先,让我们将其添加到依赖项中。 我们可以通过执行以下操作来做到这一点:

composer require seunmatt/codeigniter-log-viewer

Then, we can create a CodeIgniter application controller, LogViewerController.php:

然后,我们可以创建一个CodeIgniter应用程序控制器LogViewerController.php

private $logViewer;
public function __construct() {    $this->logViewer = new \CILogViewer\CILogViewer();    //...}
public function index() {    echo $this->logViewer->showLogs();    return;}

What we did is to instantiate $logViewer in the constructor and then echo the result of showLogs() in the index() function.

我们要做的是在构造函数中实例化$ logViewer ,然后在index()函数中回显showLogs()的结果。

The showLogs() method of codeigniter-log-viewer will parse the content of the log files in application/logs . It will return it for display on the browser.

codeigniter-log-viewer的showLogs()方法将解析application / logs中日志文件的内容 它将返回显示在浏览器上。

Finally, we can map any route of our choice to the index() we created above. This can be done by adding an entry to the $route array in application/config/routes.php:

最后,我们可以将选择的任何路径映射到上面创建的index() 。 这可以通过在application / config / routes.php中$ route数组中添加一个条目来完成

$route['logs'] = "logViewerController/index";

Now we can visit /logs on the browser and see all the log files there. It’s also possible to delete and download the log files.

现在,我们可以在浏览器上访问/ logs并在其中查看所有日志文件。 也可以删除和下载日志文件。

Note: It is advisable to use a protected route in production environment to avoid general public access.

注意 :建议在生产环境中使用受保护的路由,以避免一般公众访问。

这个怎么运作 (How it works)

Internally, the library read the name of all the log files that are available in the default logs directory into an array and reverse it. If no file is specified in the URL query parameters, the latest log file is processed for display by default.

在内部,该库将默认日志目录中可用的所有日志文件的名称读取到一个数组中,并将其反转。 如果在URL查询参数中未指定文件,则默认情况下将处理最新的日志文件以进行显示。

Processing of a log file for display involves reading its contents, using regex to determine the log level and the CSS class and icon of each entry.

处理用于显示的日志文件涉及读取其内容,使用正则表达式确定日志级别以及每个条目CSS类和图标。

Each entry is also checked to know if it’s a new log line or a continuation of the previous line (due to a newline character).

还检查每个条目以知道它是新的日志行还是上一行的继续( 由于换行符 )。

Finally, the log entries are processed into HTML content that is then sent to the browser for display.

最后,将日志条目处理为HTML内容,然后将其发送到浏览器进行显示。

The complete source code is available on Github if you want to play around with it or/and adapt it for use in other frameworks.

如果您想使用它或/和使其适应其他框架,请在Github上获得完整的源代码。

结论 (Conclusion)

Now it’s easier and faster to debug CodeIgniter application — even in production. Spread the word around to friends and colleagues at work.

现在,调试CodeIgniter应用程序变得更加轻松快捷,即使在生产中也是如此。 向工作中的朋友和同事传话。

I want to hear about your experience (and opinions) of using the library in the comment section. Thanks!

我想在评论部分中听到您使用该库的经验( 和见解 )。 谢谢!

Visit the Github Link

访问Github链接

翻译自: https://www.freecodecamp.org/news/how-to-view-codeigniter-log-files-in-the-browser-e4ec7a9e8b23/

codeigniter

codeigniter_如何在浏览器中查看CodeIgniter日志文件相关推荐

  1. web developer tips (69):vs中在浏览器中查看的快捷键

    原文地址:The keyboard shortcut for View in Browser 按快捷键(keyboard shortcut)Ctrl +Shift+W可以在Visual Studio ...

  2. 运行第一个 docker image 并在浏览器中查看

    1. SSH to Docker 虚拟机. 打开gitBash或者Docker Quickstart Terminal, 并且输入: <span style="font-size:14 ...

  3. 文档预览 OfficeWebViewer:在浏览器中查看Office文档

    Office Web Viewer:在浏览器中查看Office文档 由办公室团队 即使您的读者没有安装Office,您的网站或博客上是否也有要阅读的Office文档?您宁愿先查看文档再下载吗?为了给您 ...

  4. react 渲染道具_如何在浏览器中查看您的React状态和道具

    react 渲染道具 by Andrew Bales 通过安德鲁·巴尔斯 如何在浏览器中查看您的React状态和道具 (How to see your React state & props ...

  5. 如何在Web浏览器中查看XML文件

    一旦了解到HTML是XML的一种形式,您可能会想知道如果尝试在浏览器中查看XML文件会发生什么. 结果令人非常失望-Firefox在页面顶部显示一条横幅,上面写着:"此XML文件似乎没有与之 ...

  6. VSCode插件之View In Browser/Open in Browser‘在浏览器中查看’

    推荐: vscode浏览器打开html vscode修改默认浏览器 一. VSCode插件View InBrowser,在浏览器中查看 当前插件功能类似Atom中的"Run-In-Brows ...

  7. 遇到某些无法在浏览器中查看元素的bug应该如何排查(实例)

    通常,我们遇到bug时,总是F12去看相关的位置,看dom,数据,CSS是否有问题.这是前端检查bug的常用手段.那么,不知道你有没有遇到那种特殊情况,就是我根本没法在浏览器中查看某一项操作具体情况, ...

  8. VUE无需上传,在浏览器中查看xlsx或xls表格

    xlsx-to-table 无需上传,在浏览器中查看xlsx或xls表格,由js-xlsx驱动. 在vue-xlsx-table基础上开发,(为了获得完整表头)修改为即使某一列没有数据也获取表头,给列 ...

  9. linux查看mysql连接日志文件,linux下查看mysql日志文件的方法

    查看mysql日志方法: mysql默认不允许我们查看日志.需要更改一些设置 1 vi 更改配置文件 允许用户查看日志文件 sudo vi /etc/mysql/mysql.conf.d/mysqld ...

最新文章

  1. jenkins部署net core初探
  2. 露雨资源库(第一个.net2.0软件)二
  3. Swift之深入解析“泛型”的底层原理
  4. c语言输入与输出库函数#includestdio.h
  5. 使用XMLConfiguration解析xml,properties等相应信息
  6. requests-使用代理proxies
  7. IntelliJ IDEA 15,16 win 7 64位安装包以及注册码 百度云盘
  8. 显示多文档标签_办公小技巧:用好WPS 2019文件名标签
  9. Python-Spyder中文包正式发布!
  10. SSM毕设项目户籍管理系统jrg02(java+VUE+Mybatis+Maven+Mysql)
  11. ListView分页操作
  12. 如何使用 Web Speech API 在浏览器中识别语音
  13. python 分词字典的词性_NLP注2“自定义词性与词典实现”,笔记,字典,的
  14. 解决office 2003安装了office 2007兼容包还是打不开office 2007的文件
  15. android视频播放器课程设计,ANDROID视频播放器课程设计.pdf
  16. 基于redis实现活跃用户统计功能
  17. c语言程序设计1253,1253c语言程序设计a(2010年1月)
  18. CookieSession
  19. VScode快捷键配置汇总
  20. 虹科教您 | KPA Automation softPLC入门操作指南(1)

热门文章

  1. MySQL优化原理分析及优化方案总结
  2. tableau地图城市数据_Tableau 地图 | 无法识别的城市
  3. jQuery 学习笔记(三)——事件与应用
  4. PAT乙级 1003. 我要通过!
  5. 解决新浪微博API调用限制 突破rate_limit_status瓶颈
  6. [unity3d]手游资源热更新策略探讨
  7. NSRange的用法【转】
  8. python异常(高级) Exception
  9. SpringBoot简要
  10. Python+Flask.0010.FLASK即插视图之自定义视图类及修饰器