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
4600f11a
Kaydet (Commit)
4600f11a
authored
Mar 13, 2005
tarafından
Vinay Sajip
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added optional encoding argument to file handlers.
üst
b89e7c9b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
11 deletions
+25
-11
handlers.py
Lib/logging/handlers.py
+25
-11
No files found.
Lib/logging/handlers.py
Dosyayı görüntüle @
4600f11a
# Copyright 2001-200
4
by Vinay Sajip. All Rights Reserved.
# Copyright 2001-200
5
by Vinay Sajip. All Rights Reserved.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
...
...
@@ -29,6 +29,11 @@ To use, simply 'import logging' and log away!
import
sys
,
logging
,
socket
,
types
,
os
,
string
,
cPickle
,
struct
,
time
,
glob
try
:
import
codecs
except
ImportError
:
codecs
=
None
#
# Some constants...
#
...
...
@@ -45,11 +50,15 @@ class BaseRotatingHandler(logging.FileHandler):
Not meant to be instantiated directly. Instead, use RotatingFileHandler
or TimedRotatingFileHandler.
"""
def
__init__
(
self
,
filename
,
mode
):
def
__init__
(
self
,
filename
,
mode
,
encoding
=
None
):
"""
Use the specified filename for streamed logging
"""
logging
.
FileHandler
.
__init__
(
self
,
filename
,
mode
)
if
codecs
is
None
:
encoding
=
None
logging
.
FileHandler
.
__init__
(
self
,
filename
,
mode
,
encoding
)
self
.
mode
=
mode
self
.
encoding
=
encoding
def
emit
(
self
,
record
):
"""
...
...
@@ -70,7 +79,7 @@ class RotatingFileHandler(BaseRotatingHandler):
Handler for logging to a set of files, which switches from one file
to the next when the current file reaches a certain size.
"""
def
__init__
(
self
,
filename
,
mode
=
"a"
,
maxBytes
=
0
,
backupCount
=
0
):
def
__init__
(
self
,
filename
,
mode
=
'a'
,
maxBytes
=
0
,
backupCount
=
0
,
encoding
=
None
):
"""
Open the specified file and use it as the stream for logging.
...
...
@@ -91,10 +100,9 @@ class RotatingFileHandler(BaseRotatingHandler):
If maxBytes is zero, rollover never occurs.
"""
self
.
mode
=
mode
if
maxBytes
>
0
:
self
.
mode
=
"a"
# doesn't make sense otherwise!
BaseRotatingHandler
.
__init__
(
self
,
filename
,
self
.
mode
)
mode
=
'a'
# doesn't make sense otherwise!
BaseRotatingHandler
.
__init__
(
self
,
filename
,
mode
,
encoding
)
self
.
maxBytes
=
maxBytes
self
.
backupCount
=
backupCount
...
...
@@ -118,7 +126,10 @@ class RotatingFileHandler(BaseRotatingHandler):
os
.
remove
(
dfn
)
os
.
rename
(
self
.
baseFilename
,
dfn
)
#print "%s -> %s" % (self.baseFilename, dfn)
self
.
stream
=
open
(
self
.
baseFilename
,
"w"
)
if
self
.
encoding
:
self
.
stream
=
codecs
.
open
(
self
.
baseFilename
,
'w'
,
self
.
encoding
)
else
:
self
.
stream
=
open
(
self
.
baseFilename
,
'w'
)
def
shouldRollover
(
self
,
record
):
"""
...
...
@@ -142,8 +153,8 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
If backupCount is > 0, when rollover is done, no more than backupCount
files are kept - the oldest ones are deleted.
"""
def
__init__
(
self
,
filename
,
when
=
'h'
,
interval
=
1
,
backupCount
=
0
):
BaseRotatingHandler
.
__init__
(
self
,
filename
,
'a'
)
def
__init__
(
self
,
filename
,
when
=
'h'
,
interval
=
1
,
backupCount
=
0
,
encoding
=
None
):
BaseRotatingHandler
.
__init__
(
self
,
filename
,
'a'
,
encoding
)
self
.
when
=
string
.
upper
(
when
)
self
.
backupCount
=
backupCount
# Calculate the real rollover interval, which is just the number of
...
...
@@ -262,7 +273,10 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
s
.
sort
()
os
.
remove
(
s
[
0
])
#print "%s -> %s" % (self.baseFilename, dfn)
self
.
stream
=
open
(
self
.
baseFilename
,
"w"
)
if
self
.
encoding
:
self
.
stream
=
codecs
.
open
(
self
.
baseFilename
,
'w'
,
self
.
encoding
)
else
:
self
.
stream
=
open
(
self
.
baseFilename
,
'w'
)
self
.
rolloverAt
=
int
(
time
.
time
())
+
self
.
interval
class
SocketHandler
(
logging
.
Handler
):
...
...
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