02-monolog - PHP 日志神器 之 Handlers, Formatters and Processors

Handlers

記錄日志到文件與系統(tǒng)日志(syslog)

  • StreamHandler:記錄日志到任何 PHP stream褪猛,用它來(lái)記錄到文件网杆。
  • RotatingFileHandler: 每天一個(gè)文件,會(huì)自動(dòng)刪除比$maxFiles老的文件伊滋,這只是一個(gè)很隨意的方案碳却,You should use logrotate for high profile setups though。
  • SyslogHandler: 記錄到系統(tǒng)日志
  • ErrorLogHandler: Logs records to PHP's error_log()
    function.

下面的就是擴(kuò)展閱讀啦


發(fā)送提醒與郵件

看看就能理解

  • NativeMailerHandler: Sends emails using PHP's mail()
    function.
  • SwiftMailerHandler: Sends emails using a Swift_Mailer
    instance.
  • PushoverHandler: Sends mobile notifications via the Pushover API.
  • HipChatHandler: Logs records to a HipChat chat room using its API.
  • FlowdockHandler: Logs records to a Flowdock account.
  • SlackHandler: Logs records to a Slack account.
  • MandrillHandler: Sends emails via the Mandrill API using a Swift_Message
    instance.
  • FleepHookHandler: Logs records to a Fleep conversation using Webhooks.
  • IFTTTHandler: Notifies an IFTTT trigger with the log channel, level name and message.

記錄到指定server與網(wǎng)絡(luò)日志

接著看看

SocketHandler: Logs records to sockets, use this for UNIX and TCP sockets. See an example.
AmqpHandler: Logs records to an amqp compatible server. Requires the php-amqp extension (1.0+).
GelfHandler: Logs records to a Graylog2 server.
CubeHandler: Logs records to a Cube server.
RavenHandler: Logs records to a Sentry server using raven.
ZendMonitorHandler: Logs records to the Zend Monitor present in Zend Server.
NewRelicHandler: Logs records to a NewRelic application.
LogglyHandler: Logs records to a Loggly account.
RollbarHandler: Logs records to a Rollbar account.
SyslogUdpHandler: Logs records to a remote Syslogd server.
LogEntriesHandler: Logs records to a LogEntries account.

開發(fā)環(huán)境中新啼,利用瀏覽器擴(kuò)展

裝擴(kuò)展

FirePHPHandler: Handler for FirePHP, providing inline console
messages within FireBug.
ChromePHPHandler: Handler for ChromePHP, providing inline console
messages within Chrome.
BrowserConsoleHandler: Handler to send logs to browser's Javascript console
with no browser extension required. Most browsers supporting console
API are supported.
PHPConsoleHandler: Handler for PHP Console, providing inline console
and notification popup messages within Chrome.

記錄到數(shù)據(jù)庫(kù)

顧名思義

RedisHandler: Logs records to a redis server.
MongoDBHandler: Handler to write records in MongoDB via a Mongo extension connection.
CouchDBHandler: Logs records to a CouchDB server.
DoctrineCouchDBHandler: Logs records to a CouchDB server via the Doctrine CouchDB ODM.
ElasticSearchHandler: Logs records to an Elastic Search server.
DynamoDbHandler: Logs records to a DynamoDB table with the AWS SDK.

特殊的Handler

慢慢看

FingersCrossedHandler: A very interesting wrapper. It takes a logger as parameter and will accumulate log records of all levels until a record exceeds the defined severity level. At which point it delivers all records, including those of lower severity, to the handler it wraps. This means that until an error actually happens you will not see anything in your logs, but when it happens you will have the full information, including debug and info records. This provides you with all the information you need, but only when you need it.

DeduplicationHandler: Useful if you are sending notifications or emails when critical errors occur. It takes a logger as parameter and will accumulate log records of all levels until the end of the request (or flush()
is called). At that point it delivers all records to the handler it wraps, but only if the records are unique over a given time period (60seconds by default). If the records are duplicates they are simply discarded. The main use of this is in case of critical failure like if your database is unreachable for example all your requests will fail and that can result in a lot of notifications being sent. Adding this handler reduces the amount of notifications to a manageable level.

WhatFailureGroupHandler: This handler extends the GroupHandler ignoring exceptions raised by each child handler. This allows you to ignore issues where a remote tcp connection may have died but you do not want your entire application to crash and may wish to continue to log to other handlers.

BufferHandler: This handler will buffer all the log records it receives until close()
is called at which point it will callhandleBatch()
on the handler it wraps with all the log messages at once. This is very useful to send an email with all records at once for example instead of having one mail for every log record.

GroupHandler: This handler groups other handlers. Every record received is sent to all the handlers it is configured with.

FilterHandler: This handler only lets records of the given levels through to the wrapped handler.

SamplingHandler: Wraps around another handler and lets you sample records if you only want to store some of them.

NullHandler: Any record it can handle will be thrown away. This can be used to put on top of an existing handler stack to disable it temporarily.

PsrHandler: Can be used to forward log records to an existing PSR-3 logger

TestHandler: Used for testing, it records everything that is sent to it and has accessors to read out the information.

HandlerWrapper: A simple handler wrapper you can inherit from to create your own wrappers easily.

Formatters

? 為常用

LineFormatter: Formats a log record into a one-line string. ?
HtmlFormatter: Used to format log records into a human readable html table, mainly suitable for emails.?
NormalizerFormatter: Normalizes objects/resources down to strings so a record can easily be serialized/encoded.
ScalarFormatter: Used to format log records into an associative array of scalar values.
JsonFormatter: Encodes a log record into json.?
WildfireFormatter: Used to format log records into the Wildfire/FirePHP protocol, only useful for the FirePHPHandler.
ChromePHPFormatter: Used to format log records into the ChromePHP format, only useful for the ChromePHPHandler.
GelfMessageFormatter: Used to format log records into Gelf message instances, only useful for the GelfHandler.
LogstashFormatter: Used to format log records into logstash event json, useful for any handler listed under inputs here.
ElasticaFormatter: Used to format log records into an Elastica\Document object, only useful for the ElasticSearchHandler.
LogglyFormatter: Used to format log records into Loggly messages, only useful for the LogglyHandler.
FlowdockFormatter: Used to format log records into Flowdock messages, only useful for the FlowdockHandler.
MongoDBFormatter: Converts \DateTime instances to \MongoDate and objects recursively to arrays, only useful with the MongoDBHandler.

Processors

PsrLogMessageProcessor: Processes a log record's message according to PSR-3 rules, replacing {foo}
with the value from $context['foo'].

IntrospectionProcessor: Adds the line/file/class/method from which the log call originated.

WebProcessor: Adds the current request URI, request method and client IP to a log record.

MemoryUsageProcessor: Adds the current memory usage to a log record.

MemoryPeakUsageProcessor: Adds the peak memory usage to a log record.

ProcessIdProcessor: Adds the process id to a log record.

UidProcessor: Adds a unique identifier to a log record.

GitProcessor: Adds the current git branch and commit to a log record.

TagProcessor: Adds an array of predefined tags to a log record.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末追城,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子燥撞,更是在濱河造成了極大的恐慌座柱,老刑警劉巖迷帜,帶你破解...
    沈念sama閱讀 218,036評(píng)論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異色洞,居然都是意外死亡戏锹,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,046評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門火诸,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)锦针,“玉大人,你說(shuō)我怎么就攤上這事置蜀∧嗡眩” “怎么了?”我有些...
    開封第一講書人閱讀 164,411評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵盯荤,是天一觀的道長(zhǎng)馋吗。 經(jīng)常有香客問(wèn)我,道長(zhǎng)秋秤,這世上最難降的妖魔是什么宏粤? 我笑而不...
    開封第一講書人閱讀 58,622評(píng)論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮灼卢,結(jié)果婚禮上绍哎,老公的妹妹穿的比我還像新娘。我一直安慰自己鞋真,他們只是感情好崇堰,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,661評(píng)論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著灿巧,像睡著了一般赶袄。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上抠藕,一...
    開封第一講書人閱讀 51,521評(píng)論 1 304
  • 那天,我揣著相機(jī)與錄音蒋困,去河邊找鬼盾似。 笑死,一個(gè)胖子當(dāng)著我的面吹牛雪标,可吹牛的內(nèi)容都是我干的零院。 我是一名探鬼主播,決...
    沈念sama閱讀 40,288評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼村刨,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼告抄!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起嵌牺,我...
    開封第一講書人閱讀 39,200評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤打洼,失蹤者是張志新(化名)和其女友劉穎龄糊,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體募疮,經(jīng)...
    沈念sama閱讀 45,644評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡炫惩,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,837評(píng)論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了阿浓。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片他嚷。...
    茶點(diǎn)故事閱讀 39,953評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖芭毙,靈堂內(nèi)的尸體忽然破棺而出筋蓖,到底是詐尸還是另有隱情,我是刑警寧澤退敦,帶...
    沈念sama閱讀 35,673評(píng)論 5 346
  • 正文 年R本政府宣布扭勉,位于F島的核電站,受9級(jí)特大地震影響苛聘,放射性物質(zhì)發(fā)生泄漏涂炎。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,281評(píng)論 3 329
  • 文/蒙蒙 一设哗、第九天 我趴在偏房一處隱蔽的房頂上張望唱捣。 院中可真熱鬧,春花似錦网梢、人聲如沸震缭。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,889評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)拣宰。三九已至,卻和暖如春烦感,著一層夾襖步出監(jiān)牢的瞬間巡社,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,011評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工手趣, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留晌该,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,119評(píng)論 3 370
  • 正文 我出身青樓绿渣,卻偏偏與公主長(zhǎng)得像朝群,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子中符,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,901評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容

  • NAME dnsmasq - A lightweight DHCP and caching DNS server....
    ximitc閱讀 2,856評(píng)論 0 0
  • 寫在前面 幾個(gè)月之前姜胖,偶然看到了老莊的一篇博客——《如何評(píng)價(jià)一個(gè)新技術(shù) 》,討論了docker是一個(gè)什么級(jí)別的發(fā)明...
    李福就是李建業(yè)閱讀 7,500評(píng)論 0 13
  • 【讀經(jīng)】 代上7-8章 【金句】 拿弗他利的兒子是雅薛淀散、沽尼右莱、耶色蚜锨、沙龍。這都是辟拉的子孫隧出。 (歷代志上 7:13...
    chanor閱讀 720評(píng)論 0 0
  • 五谷為之踏志,天地藏之。集天地之光華胀瞪,采日月之流芳针余。一杯濁酒,兩袖清風(fēng)凄诞,杯盡自狂圆雁,天地幾人高?酒清青豆與食盡,同銷一世...
    行森閱讀 229評(píng)論 0 1
  • 恒星 恒星的定義:本身能夠發(fā)生熱核反應(yīng)帆谍,能夠發(fā)光發(fā)熱伪朽,最終演化為致密殘骸的星體。恒星的質(zhì)量必須大汛蝙,至少8%的太陽(yáng)質(zhì)...
    小浣熊UU閱讀 2,025評(píng)論 1 3