Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
73306b07
Kaydet (Commit)
73306b07
authored
Ock 14, 2007
tarafından
Vinay Sajip
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added WatchedFileHandler (based on SF patch #1598415)
üst
bb2cc698
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
0 deletions
+49
-0
handlers.py
Lib/logging/handlers.py
+49
-0
No files found.
Lib/logging/handlers.py
Dosyayı görüntüle @
73306b07
...
...
@@ -28,6 +28,7 @@ To use, simply 'import logging' and log away!
"""
import
sys
,
logging
,
socket
,
types
,
os
,
string
,
cPickle
,
struct
,
time
,
glob
from
stat
import
ST_DEV
,
ST_INO
try
:
import
codecs
...
...
@@ -282,6 +283,54 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
self
.
stream
=
open
(
self
.
baseFilename
,
'w'
)
self
.
rolloverAt
=
self
.
rolloverAt
+
self
.
interval
class
WatchedFileHandler
(
logging
.
FileHandler
):
"""
A handler for logging to a file, which watches the file
to see if it has changed while in use. This can happen because of
usage of programs such as newsyslog and logrotate which perform
log file rotation. This handler, intended for use under Unix,
watches the file to see if it has changed since the last emit.
(A file has changed if its device or inode have changed.)
If it has changed, the old file stream is closed, and the file
opened to get a new stream.
This handler is not appropriate for use under Windows, because
under Windows open files cannot be moved or renamed - logging
opens the files with exclusive locks - and so there is no need
for such a handler. Furthermore, ST_INO is not supported under
Windows; stat always returns zero for this value.
This handler is based on a suggestion and patch by Chad J.
Schroeder.
"""
def
__init__
(
self
,
filename
,
mode
=
'a'
,
encoding
=
None
):
logging
.
FileHandler
.
__init__
(
self
,
filename
,
mode
,
encoding
)
stat
=
os
.
stat
(
self
.
baseFilename
)
self
.
dev
,
self
.
ino
=
stat
[
ST_DEV
],
stat
[
ST_INO
]
def
emit
(
self
,
record
):
"""
Emit a record.
First check if the underlying file has changed, and if it
has, close the old stream and reopen the file to get the
current stream.
"""
if
not
os
.
path
.
exists
(
self
.
baseFilename
):
stat
=
None
changed
=
1
else
:
stat
=
os
.
stat
(
self
.
baseFilename
)
changed
=
(
stat
[
ST_DEV
]
!=
self
.
dev
)
or
(
stat
[
ST_INO
]
!=
self
.
ino
)
if
changed
:
self
.
stream
.
flush
()
self
.
stream
.
close
()
self
.
stream
=
self
.
_open
()
if
stat
is
None
:
stat
=
os
.
stat
(
self
.
baseFilename
)
self
.
dev
,
self
.
ino
=
stat
[
ST_DEV
],
stat
[
ST_INO
]
logging
.
FileHandler
.
emit
(
self
,
record
)
class
SocketHandler
(
logging
.
Handler
):
"""
A handler class which writes logging records, in pickle format, to
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment