forked from twisted/twisted
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branches/log-booyah-6750-6: New logging system
Author: wsanchez, glyph Reviewer: ralphm Fixes: twisted#6750 git-svn-id: svn://svn.twistedmatrix.com/svn/Twisted/trunk@44442 bbbe8e31-12d6-0310-92fd-ac37d47ddeeb
- Loading branch information
wsanchez
committed
Apr 14, 2015
1 parent
6d52ade
commit 30eab99
Showing
60 changed files
with
8,332 additions
and
557 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ Developer Guides | |
application | ||
tap | ||
systemd | ||
logger | ||
logging | ||
constants | ||
rdbms | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from twisted.logger import Logger | ||
|
||
class AdHoc(object): | ||
log = Logger(namespace="ad_hoc") | ||
|
||
def __init__(self, a, b): | ||
self.a = a | ||
self.b = b | ||
|
||
def logMessage(self): | ||
self.log.info("message from {log_source} " | ||
"where a is {log_source.a} and b is {log_source.b}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import io | ||
from twisted.logger import jsonFileLogObserver, globalLogPublisher | ||
from ad_hoc import AdHoc | ||
|
||
globalLogPublisher.addObserver(jsonFileLogObserver(io.open("log.json", "a"))) | ||
|
||
AdHoc(3, 4).logMessage() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from twisted.logger import extractField | ||
|
||
fmt = ( | ||
"message from {log_source} " | ||
"where a is {log_source.a} and b is {log_source.b}" | ||
) | ||
|
||
def analyze(event): | ||
if event.get("log_format") == fmt: | ||
a = extractField("log_source.a", event) | ||
b = extractField("log_source.b", event) | ||
print("A + B = " + repr(a + b)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import io | ||
from twisted.logger import eventsFromJSONLogFile | ||
|
||
for event in eventsFromJSONLogFile(io.open("log.json")): | ||
print(sum(event["values"])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import sys | ||
import io | ||
from twisted.logger import ( | ||
eventsFromJSONLogFile, textFileLogObserver | ||
) | ||
|
||
output = textFileLogObserver(sys.stdout) | ||
|
||
for event in eventsFromJSONLogFile(io.open("log.json")): | ||
output(event) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from twisted.logger import Logger | ||
|
||
class MyObject(object): | ||
log = Logger() | ||
|
||
def __init__(self, value): | ||
self.value = value | ||
|
||
def doSomething(self, something): | ||
self.log.info( | ||
"Object with value {log_source.value!r} doing {something}.", | ||
something=something | ||
) | ||
|
||
MyObject(7).doSomething("a task") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import io | ||
from twisted.logger import eventsFromJSONLogFile | ||
from analyze import analyze | ||
|
||
for event in eventsFromJSONLogFile(io.open("log.json")): | ||
analyze(event) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from twisted.logger import globalLogPublisher | ||
from analyze import analyze | ||
from ad_hoc import AdHoc | ||
|
||
globalLogPublisher.addObserver(analyze) | ||
|
||
AdHoc(3, 4).logMessage() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import io | ||
from twisted.logger import jsonFileLogObserver, Logger | ||
|
||
log = Logger(observer=jsonFileLogObserver(io.open("log.json", "a")), | ||
namespace="saver") | ||
|
||
def loggit(values): | ||
log.info("Some values: {values!r}", values=values) | ||
|
||
loggit([1234, 5678]) | ||
loggit([9876, 5432]) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.