codeigniter_如何在浏览器中查看CodeIgniter日志文件

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/394865.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

小程序强制自动更新

(3)强制更新官方版 微信团队2018-03-2315987浏览背景 此前有开发者反馈小程序发布新版本后,新版本覆盖率比较慢,因为小程序的更新机制是异步的,部分用户不会马上应用上新版本。 小程序启动会有两种情况,一种是「冷启动」&#xff…

联想m7400pro更换墨粉盒怎么清零_佳能打印机怎么换墨水 佳能打印机换墨水注意事项【详解】...

佳能打印机是我们办公室用品中比较常见的一个品牌,作为国际知名品牌,其质量也是非常有保障的。在使用的时候打印机没有墨是经常会遇见的。这时候我们就需要更换墨水盒了。但很多不知道具体步骤,或者没有注意相关细节,导致换墨水盒…

oracle数据库连接数超了,oracle数据库当前和最大连接数

1、查询oracle的连接数select count(*) from v$session;2、查询oracle的并发连接数select count(*) from v$session where statusACTIVE;3、查看不同用户的连接数select username,count(username) from v$session where username is not null group by username;4、查看所有用户…

MySQL Workbench导出数据库

步骤: 1. 打开mysql workbench,进入需要导出的数据库,点击左侧栏的【Management】tab键。 2. 点选要输出的数据库 点击【Data Export】选在要输出的数据库选择是否输出存储过程和函数,事件,触发器 点击Start Export3. …

django 传递中文_如何在Django中建立消息传递状态

django 传递中文by Ogundipe Samuel由Ogundipe Samuel 如何在Django中建立消息传递状态 (How to Build a Message Delivery Status in Django) Today, we will make a real-time message delivery status framework with Django and Pusher.今天,我们将使用Django和…

软链接与硬链接

文件引用模型 在linux中,一切皆文件,而文件包含元数据(metedata)和用户数据(user data)。元数据中的inode号是系统标识和获取用户数据的唯一凭证,而文件名仅是为了方便用户记忆和使用。为了管理…

c++ 数组的输入遇到特定字符停止输入_C语言 第4章-字符串和格式化输入/输出

#include 用数组name储存字符串,name数组有40个字节,每个字节储存一个字符值。在scanf()函数中,输入字符串name没有&前缀。C预处理器把字符常量DENSITY定义为62.4。strlen()获取字符串长度。1. 字符串1.1. char类型数组双引号标记字符串&…

vue3+typescript引入外部文件

vue3typescript中引入外部文件有几种方法 &#xff08;eg:引入echarts&#xff09; 第一种方法&#xff1a; 1 indext.html中用script引入 <div id"app"></div><script src"https://cdn.bootcss.com/echarts/4.2.1-rc1/echarts-en.common.min.js…

在哪能找到陌生人聊骚_如何说服陌生人帮助您找到工作

在哪能找到陌生人聊骚by Alex Lacey通过亚历克斯莱西 找工作吗&#xff1f; 这是说服陌生人帮助您找到一个人的方法 (Looking for a job? Here’s how to convince strangers to help you find one) 我过去获得40个推荐的7个步骤 (The 7-step process that I used to get 40 …

Python基础 day2

Python基础 一、Python的数据类型 1、int(整型) 在32位机器上&#xff0c;整数的位数为32位&#xff0c;取值范围为-2**31&#xff5e;2**31-1&#xff0c;即-2147483648&#xff5e;2147483647&#xff0c;而.在64位系统上&#xff0c;整数的位数为64位&#xff0c;取值范围为…

matlab 文件指针回到开头,[c/c++] 文件指针位置回到文件开头(rewind)及行开头(ftell+fseek)...

待读入文件1.greenteemo2.csdn3.blog代码&#xff0c;详细说明见注释#include #define LENGTH_OF_LINE 1024int main(){FILE *fp fopen("file.txt", "r"); // 打开文件char line[LENGTH_OF_LINE];while( fgets(line, LENGTH_OF_LINE, fp) ){printf("…

python全栈开发优势_Python全栈开发多少钱?学Python价格贵吗?

Python全栈开发培训多少钱?学习Python是大家进入编程世界的理想之选&#xff0c;而且Python也是一门非常受欢迎的编程&#xff0c;可以从事的领域有很多。 从目前市场上的行情来说&#xff0c;一般情况下Python培训的费用在一万五到两万元之间的&#xff0c;以后可能会更高&am…

gym101808 E

提问&#xff1a;我是什么品种的傻逼&#xff1f; 哇看到积水兴高采烈啊。然后就走上了一条不归路。 为什么不归呢&#xff0c;因为我这个法子就是不对的&#xff0c;我总是在想很多很多点围成的一块区域&#xff0c;然后求这一块区域的面积。 然后尝试了各种扫描方法&#xff…

WordPress中缠结的自定义数据世界

by Kamil Grzegorczyk通过卡米尔(Kamil Grzegorczyk) WordPress中缠结的自定义数据世界 (The Tangled World of Custom Data in WordPress) 降低风险并管理您的自定义字段 (Reducing Risk and Managing Your Custom Fields) Have you ever wondered how to properly name keys…

【站点部署】解析二级域名并部署站点

开设原因 : 近期在学健身, 上一份工作辞掉后, 在北京找了家私人教练培训学校, 进行为期四个月的健身培训, 这个比在健身房找私教专业多了, 被健身房私人教练坑慘了, 说多了都是泪, 已经培训了将近一个半月, 学习了基础私教, 普拉提, 这在学习康复课程, 之后还有功能性 和 综合格…

pip如何安装到Linux服务器,linux中pip安装步骤与使用详解

1、pip下载安装1.1 pip下载代码如下# wget "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5834b2904f92d46aaa333267fb1c922bb" --no-check-certificate1.2 pip安装代码如下# tar -xzvf pip-1.5.4.tar.gz# cd pip-1.5.4# python setup.py inst…

python中列表实现去重使用_Python实现嵌套列表去重方法示例

发现问题 python嵌套列表大家应该都不陌生&#xff0c;但最近遇到了一个问题&#xff0c;这是工作中遇到的一个坑&#xff0c;首先看一下问题 raw_list [["百度", "CPY"], ["京东", "CPY"], ["黄轩", "PN"], [&q…

Android 开发 存储目录的详解

Android 开发 存储目录的详解 简介   Android设备,有3个地方的文件存储位置,他们分别是:  内部存储空间(用户无法浏览到此目录)  外部存储空间(就是手机自身的文件管理目录,用户可以浏览)  SD卡的存储空间(需要插入T卡)  SharedPreferences目录  存储数据库DB目录内…

大数据项目交付国标_在紧迫的期限内交付大型项目

大数据项目交付国标by Paul McGillivray保罗麦吉里夫瑞(Paul McGillivray) 在紧迫的期限内交付大型Web项目 (Delivering a big web project for a tight deadline) This week we launched the first phase of a large website for a fast-growing business, ‘Jump In’. The …

CentOS 安装MySQL(rpm)提示错误Header V3 DSA/SHA1 Signature

提示错误&#xff1a;Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY error: Failed dependencies 错误原因&#xff1a;这是由于yum安装了旧版本的GPG keys造成的 解决办法&#xff1a;后面加上--force --nodeps 原文&#xff1a; 摘要&#xff1a; CentOS安装rpm安装…