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.pswp.cn/news/394865.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/394865.shtml
英文地址,請注明出處:http://en.pswp.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安裝…