|
libcpuid
|
LibCPUID provides CPU identification. More...
Data Structures | |
| struct | cpu_raw_data_t |
| Contains just the raw CPUID data. More... | |
| struct | cpu_sgx_t |
| This contains information about SGX features of the processor Example usage: More... | |
| struct | cpu_id_t |
| This contains the recognized CPU features/info. More... | |
| struct | cpu_mark_t |
| Internal structure, used in cpu_tsc_mark, cpu_tsc_unmark and cpu_clock_by_mark. More... | |
| struct | cpu_epc_t |
| The return value of cpuid_get_epc(). More... | |
| struct | cpu_list_t |
| a structure that holds a list of processor names More... | |
Macros | |
| #define | NUM_CPU_VENDORS NUM_CPU_VENDORS |
| #define | CPU_INVALID_VALUE 0x3fffffff |
Typedefs | |
| typedef void(* | libcpuid_warn_fn_t) (const char *msg) |
Functions | |
| int | cpuid_get_total_cpus (void) |
| Returns the total number of logical CPU threads (even if CPUID is not present). More... | |
| int | cpuid_present (void) |
| Checks if the CPUID instruction is supported. More... | |
| void | cpu_exec_cpuid (uint32_t eax, uint32_t *regs) |
| Executes the CPUID instruction. More... | |
| void | cpu_exec_cpuid_ext (uint32_t *regs) |
| Executes the CPUID instruction with the given input registers. More... | |
| int | cpuid_get_raw_data (struct cpu_raw_data_t *data) |
| Obtains the raw CPUID data from the current CPU. More... | |
| int | cpuid_serialize_raw_data (struct cpu_raw_data_t *data, const char *filename) |
| Writes the raw CPUID data to a text file. More... | |
| int | cpuid_deserialize_raw_data (struct cpu_raw_data_t *data, const char *filename) |
| Reads raw CPUID data from file. More... | |
| int | cpu_identify (struct cpu_raw_data_t *raw, struct cpu_id_t *data) |
| Identifies the CPU. More... | |
| const char * | cpu_feature_str (cpu_feature_t feature) |
| Returns the short textual representation of a CPU flag. More... | |
| const char * | cpuid_error (void) |
| Returns textual description of the last error. More... | |
| void | cpu_rdtsc (uint64_t *result) |
| Executes RDTSC. More... | |
| void | cpu_tsc_mark (struct cpu_mark_t *mark) |
| Store TSC and timing info. More... | |
| void | cpu_tsc_unmark (struct cpu_mark_t *mark) |
| Calculate TSC and timing difference. More... | |
| int | cpu_clock_by_mark (struct cpu_mark_t *mark) |
| Calculates the CPU clock. More... | |
| int | cpu_clock_by_os (void) |
| Returns the CPU clock, as reported by the OS. More... | |
| int | cpu_clock_measure (int millis, int quad_check) |
| Measure the CPU clock frequency. More... | |
| int | cpu_clock_by_ic (int millis, int runs) |
| Measure the CPU clock frequency using instruction-counting. More... | |
| int | cpu_clock (void) |
| Get the CPU clock frequency (all-in-one method) More... | |
| struct cpu_epc_t | cpuid_get_epc (int index, const struct cpu_raw_data_t *raw) |
| Fetches information about an EPC (Enclave Page Cache) area. More... | |
| const char * | cpuid_lib_version (void) |
| Returns the libcpuid version. More... | |
| libcpuid_warn_fn_t | cpuid_set_warn_function (libcpuid_warn_fn_t warn_fun) |
| Sets the warning print function. More... | |
| void | cpuid_set_verbosiness_level (int level) |
| Sets the verbosiness level. More... | |
| cpu_vendor_t | cpuid_get_vendor (void) |
| Obtains the CPU vendor from CPUID from the current CPU. More... | |
| void | cpuid_get_cpu_list (cpu_vendor_t vendor, struct cpu_list_t *list) |
| Gets a list of all known CPU names from a specific vendor. More... | |
| void | cpuid_free_cpu_list (struct cpu_list_t *list) |
| Frees a CPU list. More... | |
| struct msr_driver_t * | cpu_msr_driver_open (void) |
| Starts/opens a driver, needed to read MSRs (Model Specific Registers) More... | |
| struct msr_driver_t * | cpu_msr_driver_open_core (unsigned core_num) |
| Similar to cpu_msr_driver_open, but accept one parameter. More... | |
| int | cpu_rdmsr (struct msr_driver_t *handle, uint32_t msr_index, uint64_t *result) |
| Reads a Model-Specific Register (MSR) More... | |
| int | cpu_rdmsr_range (struct msr_driver_t *handle, uint32_t msr_index, uint8_t highbit, uint8_t lowbit, uint64_t *result) |
| Similar to cpu_rdmsr, but extract a range of bits. More... | |
| int | cpu_msrinfo (struct msr_driver_t *handle, cpu_msrinfo_request_t which) |
| Reads extended CPU information from Model-Specific Registers. More... | |
| int | msr_serialize_raw_data (struct msr_driver_t *handle, const char *filename) |
| Writes the raw MSR data to a text file. More... | |
| int | cpu_msr_driver_close (struct msr_driver_t *handle) |
| Closes an open MSR driver. More... | |
LibCPUID provides CPU identification.
| enum cpu_error_t |
Describes common library error codes.
| enum cpu_feature_t |
CPU feature identifiers.
Usage:
| enum cpu_hint_t |
| Enumerator | |
|---|---|
| INFO_MPERF | Maximum performance frequency clock. This is a counter, which increments as a proportion of the actual processor speed. |
| INFO_APERF | Actual performance frequency clock. This accumulates the core clock counts when the core is active. |
| INFO_MIN_MULTIPLIER | Minimum CPU:FSB ratio for this CPU, multiplied by 100. |
| INFO_CUR_MULTIPLIER | Current CPU:FSB ratio, multiplied by 100. e.g., a CPU:FSB value of 18.5 reads as "1850". |
| INFO_MAX_MULTIPLIER | Maximum CPU:FSB ratio for this CPU, multiplied by 100. |
| INFO_TEMPERATURE | The current core temperature in Celsius. |
| INFO_THROTTLING | 1 if the current logical processor is throttling. 0 if it is running normally. |
| INFO_VOLTAGE | The current core voltage in Volt, multiplied by 100. |
| INFO_BCLK | See INFO_BUS_CLOCK. |
| INFO_BUS_CLOCK | The main bus clock in MHz, e.g., FSB/QPI/DMI/HT base clock, multiplied by 100. |
| enum cpu_sgx_feature_t |
SGX features flags.
Usage:
| Enumerator | |
|---|---|
| INTEL_SGX1 | SGX1 instructions support |
| INTEL_SGX2 | SGX2 instructions support |
| enum cpu_vendor_t |
CPU vendor, as guessed from the Vendor String.
| int cpu_clock | ( | void | ) |
Get the CPU clock frequency (all-in-one method)
This is an all-in-one method for getting the CPU clock frequency. It tries to use the OS for that. If the OS doesn't have this info, it uses cpu_clock_measure with 200ms time interval and quadruple checking.
| int cpu_clock_by_ic | ( | int | millis, |
| int | runs | ||
| ) |
Measure the CPU clock frequency using instruction-counting.
| millis | - how much time to allocate for each run, in milliseconds |
| runs | - how many runs to perform |
The function performs a busy-wait cycle using a known number of "heavy" (SSE) instructions. These instructions run at (more or less guaranteed) 1 IPC rate, so by running a busy loop for a fixed amount of time, and measuring the amount of instructions done, the CPU clock is accurately measured.
Of course, this function is still affected by the power-saving schemes, so the warnings as of cpu_clock_measure() still apply. However, this function is immune to problems with detection, related to the Intel Nehalem's "Turbo" mode, where the internal clock is raised, but the RDTSC rate is unaffected.
The function will run for about (millis * runs) milliseconds. You can make only a single busy-wait run (runs == 1); however, this can be affected by task scheduling (which will break the counting), so allowing more than one run is recommended. As run length is not imperative for accurate readings (e.g., 50ms is sufficient), you can afford a lot of short runs, e.g. 10 runs of 50ms or 20 runs of 25ms.
Recommended values - millis = 50, runs = 4. For more robustness, increase the number of runs.
NOTE: on Bulldozer and later CPUs, the busy-wait cycle runs at 1.4 IPC, thus the results are skewed. This is corrected internally by dividing the resulting value by 1.4. However, this only occurs if the thread is executed on a single CMT module - if there are other threads competing for resources, the results are unpredictable. Make sure you run cpu_clock_by_ic() on a CPU that is free from competing threads, or if there are such threads, they shouldn't exceed the number of modules. On a Bulldozer X8, that means 4 threads.
| int cpu_clock_by_mark | ( | struct cpu_mark_t * | mark | ) |
Calculates the CPU clock.
| mark | - pointer to a cpu_mark_t structure, which has been initialized with cpu_tsc_mark and later ‘stopped’ with cpu_tsc_unmark. |
| int cpu_clock_by_os | ( | void | ) |
Returns the CPU clock, as reported by the OS.
This function uses OS-specific functions to obtain the CPU clock. It may differ from the true clock for several reasons:
i) The CPU might be in some power saving state, while the OS reports its full-power frequency, or vice-versa.
ii) In some cases you can raise or lower the CPU frequency with overclocking utilities and the OS will not notice.
| int cpu_clock_measure | ( | int | millis, |
| int | quad_check | ||
| ) |
Measure the CPU clock frequency.
| millis | - How much time to waste in the busy-wait cycle. In millisecs. Useful values 10 - 1000 |
| quad_check | - Do a more thorough measurement if nonzero (see the explanation). |
The function performs a busy-wait cycle for the given time and calculates the CPU frequency by the difference of the TSC values. The accuracy of the calculation depends on the length of the busy-wait cycle: more is better, but 100ms should be enough for most purposes.
While this will calculate the CPU frequency correctly in most cases, there are several reasons why it might be incorrect:
i) RDTSC doesn't guarantee it will run at the same clock as the CPU. Apparently there aren't CPUs at the moment, but still, there's no guarantee.
ii) The CPU might be in a low-frequency power saving mode, and the CPU might be switched to higher frequency at any time. If this happens during the measurement, the result can be anywhere between the low and high frequencies. Also, if you're interested in the high frequency value only, this function might return the low one instead.
iii) On SMP systems exhibiting TSC drift (see cpu_rdtsc)
the quad_check option will run four consecutive measurements and then return the average of the two most-consistent results. The total runtime of the function will still be ‘millis’ - consider using a bit more time for the timing interval.
Finally, for benchmarking / CPU intensive applications, the best strategy is to use the cpu_tsc_mark() / cpu_tsc_unmark() / cpu_clock_by_mark() method. Begin by mark()-ing about one second after application startup (allowing the power-saving manager to kick in and rise the frequency during that time), then unmark() just before application finishing. The result will most acurately represent at what frequency your app was running.
| void cpu_exec_cpuid | ( | uint32_t | eax, |
| uint32_t * | regs | ||
| ) |
Executes the CPUID instruction.
| eax | - the value of the EAX register when executing CPUID |
| regs | - the results will be stored here. regs[0] = EAX, regs[1] = EBX, ... |
| void cpu_exec_cpuid_ext | ( | uint32_t * | regs | ) |
Executes the CPUID instruction with the given input registers.
| regs | - Input/output. Prior to executing CPUID, EAX, EBX, ECX and EDX will be set to regs[0], regs[1], regs[2] and regs[3]. After CPUID, this array will contain the results. |
| const char* cpu_feature_str | ( | cpu_feature_t | feature | ) |
Returns the short textual representation of a CPU flag.
| feature | - the feature, whose textual representation is wanted. |
| int cpu_identify | ( | struct cpu_raw_data_t * | raw, |
| struct cpu_id_t * | data | ||
| ) |
Identifies the CPU.
| raw | - Input - a pointer to the raw CPUID data, which is obtained either by cpuid_get_raw_data or cpuid_deserialize_raw_data. Can also be NULL, in which case the functions calls cpuid_get_raw_data itself. |
| data | - Output - the decoded CPU features/info is written here. |
| int cpu_msr_driver_close | ( | struct msr_driver_t * | handle | ) |
Closes an open MSR driver.
This function unloads the MSR driver opened by cpu_msr_driver_open and frees any resources associated with it.
| handle | - a handle to the MSR reader driver, as created by cpu_msr_driver_open |
| struct msr_driver_t* cpu_msr_driver_open | ( | void | ) |
Starts/opens a driver, needed to read MSRs (Model Specific Registers)
On systems that support it, this function will create a temporary system driver, that has privileges to execute the RDMSR instruction. After the driver is created, you can read MSRs by calling cpu_rdmsr
| struct msr_driver_t* cpu_msr_driver_open_core | ( | unsigned | core_num | ) |
Similar to cpu_msr_driver_open, but accept one parameter.
This function works on certain operating systems (GNU/Linux, FreeBSD)
| core_num | specify the core number for MSR. The first core number is 0. The last core number is cpuid_get_total_cpus - 1. |
| int cpu_msrinfo | ( | struct msr_driver_t * | handle, |
| cpu_msrinfo_request_t | which | ||
| ) |
Reads extended CPU information from Model-Specific Registers.
| handle | - a handle to an open MSR driver, |
| which | - which info field should be returned. A list of available information entities is listed in the cpu_msrinfo_request_t enum. |
| - | if the requested information is available for the current processor model, the respective value is returned. if no information is available, or the CPU doesn't support the query, the special value CPU_INVALID_VALUE is returned |
| int cpu_rdmsr | ( | struct msr_driver_t * | handle, |
| uint32_t | msr_index, | ||
| uint64_t * | result | ||
| ) |
Reads a Model-Specific Register (MSR)
If the CPU has MSRs (as indicated by the CPU_FEATURE_MSR flag), you can read a MSR with the given index by calling this function.
There are several prerequisites you must do before reading MSRs: 1) You must ensure the CPU has RDMSR. Check the CPU_FEATURE_MSR flag in cpu_id_t::flags 2) You must ensure that the CPU implements the specific MSR you intend to read. 3) You must open a MSR-reader driver. RDMSR is a privileged instruction and needs ring-0 access in order to work. This temporary driver is created by calling cpu_msr_driver_open
| handle | - a handle to the MSR reader driver, as created by cpu_msr_driver_open |
| msr_index | - the numeric ID of the MSR you want to read |
| result | - a pointer to a 64-bit integer, where the MSR value is stored |
| int cpu_rdmsr_range | ( | struct msr_driver_t * | handle, |
| uint32_t | msr_index, | ||
| uint8_t | highbit, | ||
| uint8_t | lowbit, | ||
| uint64_t * | result | ||
| ) |
Similar to cpu_rdmsr, but extract a range of bits.
| handle | - a handle to the MSR reader driver, as created by cpu_msr_driver_open |
| msr_index | - the numeric ID of the MSR you want to read |
| highbit | - the high bit in range, must be inferior to 64 |
| lowbit | - the low bit in range, must be equal or superior to 0 |
| result | - a pointer to a 64-bit integer, where the MSR value is stored |
| void cpu_rdtsc | ( | uint64_t * | result | ) |
Executes RDTSC.
The RDTSC (ReaD Time Stamp Counter) instruction gives access to an internal 64-bit counter, which usually increments at each clock cycle. This can be used for various timing routines, and as a very precise clock source. It is set to zero on system startup. Beware that may not increment at the same frequency as the CPU. Consecutive calls of RDTSC are, however, guaranteed to return monotonically-increasing values.
| result | - a pointer to a 64-bit unsigned integer, where the TSC value will be stored |
| void cpu_tsc_mark | ( | struct cpu_mark_t * | mark | ) |
Store TSC and timing info.
This function stores the current TSC value and current time info from a precise OS-specific clock source in the cpu_mark_t structure. The sys_clock field contains time with microsecond resolution. The values can later be used to measure time intervals, number of clocks, FPU frequency, etc.
| mark | [out] - a pointer to a cpu_mark_t structure |
| void cpu_tsc_unmark | ( | struct cpu_mark_t * | mark | ) |
Calculate TSC and timing difference.
| mark | - input/output: a pointer to a cpu_mark_t structure, which has already been initialized by cpu_tsc_mark. The difference in TSC and time will be written here. |
This function calculates the TSC and time difference, by obtaining the current TSC and timing values and subtracting the contents of the ‘mark’ structure from them. Results are written in the same structure.
Example:
| int cpuid_deserialize_raw_data | ( | struct cpu_raw_data_t * | data, |
| const char * | filename | ||
| ) |
Reads raw CPUID data from file.
| data | - a pointer to cpu_raw_data_t structure. The deserialized data will be written here. |
| filename | - the path of the file, containing the serialized raw data. If empty, stdin will be used. |
| const char* cpuid_error | ( | void | ) |
Returns textual description of the last error.
libcpuid stores an ‘errno’-style error status, whose description can be obtained with this function.
| void cpuid_free_cpu_list | ( | struct cpu_list_t * | list | ) |
Frees a CPU list.
This function deletes all the memory associated with a CPU list, as obtained by cpuid_get_cpu_list()
| list | - the list to be free()'d. |
| void cpuid_get_cpu_list | ( | cpu_vendor_t | vendor, |
| struct cpu_list_t * | list | ||
| ) |
Gets a list of all known CPU names from a specific vendor.
This function compiles a list of all known CPU (code)names (i.e. the possible values of cpu_id_t::cpu_codename) for the given vendor.
There are about 100 entries for Intel and AMD, and a few for the other vendors. The list is written out in approximate chronological introduction order of the parts.
| vendor | the vendor to be queried |
| list | [out] the resulting list will be written here. NOTE: As the memory is dynamically allocated, be sure to call cpuid_free_cpu_list() after you're done with the data |
| struct cpu_epc_t cpuid_get_epc | ( | int | index, |
| const struct cpu_raw_data_t * | raw | ||
| ) |
Fetches information about an EPC (Enclave Page Cache) area.
| index | - zero-based index, valid range [0..cpu_id_t.egx.num_epc_sections) |
| raw | - a pointer to fetched raw CPUID data. Needed only for testing, you can safely pass NULL here (if you pass a real structure, it will be used for fetching the leaf 12h data if index < 2; otherwise the real CPUID instruction will be used). |
| int cpuid_get_raw_data | ( | struct cpu_raw_data_t * | data | ) |
Obtains the raw CPUID data from the current CPU.
| data | - a pointer to cpu_raw_data_t structure |
| int cpuid_get_total_cpus | ( | void | ) |
Returns the total number of logical CPU threads (even if CPUID is not present).
Under VM, this number (and total_logical_cpus, since they are fetched with the same code) may be nonsensical, i.e. might not equal NumPhysicalCPUs*NumCoresPerCPU*HyperThreading. This is because no matter how many logical threads the host machine has, you may limit them in the VM to any number you like. This is the number returned by cpuid_get_total_cpus().
| cpu_vendor_t cpuid_get_vendor | ( | void | ) |
Obtains the CPU vendor from CPUID from the current CPU.
| const char* cpuid_lib_version | ( | void | ) |
Returns the libcpuid version.
| int cpuid_present | ( | void | ) |
Checks if the CPUID instruction is supported.
| 1 | if CPUID is present |
| 0 | the CPU doesn't have CPUID. |
| int cpuid_serialize_raw_data | ( | struct cpu_raw_data_t * | data, |
| const char * | filename | ||
| ) |
Writes the raw CPUID data to a text file.
| data | - a pointer to cpu_raw_data_t structure |
| filename | - the path of the file, where the serialized data should be written. If empty, stdout will be used. |
| void cpuid_set_verbosiness_level | ( | int | level | ) |
Sets the verbosiness level.
When the verbosiness level is above zero, some functions might print diagnostic information about what are they doing. The higher the level is, the more detail is printed. Level zero is guaranteed to omit all such output. The output is written using the same machinery as the warnings,
| level | the desired verbosiness level. Useful values 0..2 inclusive |
| libcpuid_warn_fn_t cpuid_set_warn_function | ( | libcpuid_warn_fn_t | warn_fun | ) |
Sets the warning print function.
In some cases, the internal libcpuid machinery would like to emit useful debug warnings. By default, these warnings are written to stderr. However, you can set a custom function that will receive those warnings.
| warn_fun | - the warning function you want to set. If NULL, warnings are disabled. The function takes const char* argument. |
| int msr_serialize_raw_data | ( | struct msr_driver_t * | handle, |
| const char * | filename | ||
| ) |
Writes the raw MSR data to a text file.
| handle | - a handle to the MSR reader driver, as created by cpu_msr_driver_open |
| filename | - the path of the file, where the serialized data should be written. If empty, stdout will be used. |


Page 404
Search
Admin
5
Search
Portfolios
Team Profiles
Contacts
Collections
News
Setting
Notifications
1
Profile
Home
Portfolios
5
Team Profiles
Profiles
Menu
News
Collections
Not found :(
Search for an entity, portfolio, contact or document
Cancel
Most Popular Searches
Note
Information disclosed on this website is propretary to Vertex Ventures holdings.
Continue
JavaScript is off. Please enable to view full site.


1 Chronicles 5:16
And they dwelt in Gilead in Bashan, and in her towns, and in all the suburbs of Sharon, upon their borders.


JList
class provides the
setDropMode
method which supports the following drop modes.
JList
is
DropMode.USE_SELECTION
.
When dragging in this mode, the selected item in the list
moves to echo the potential drop point. On a drop the
selected item shifts to the drop location.
This mode is provided for backwards compatibility
but is otherwise not recommended.
DropMode.ON
, the selected item
in the list moves to echo the potential drop point, but the
selected item is not affected on the drop. This mode
can be used to drop on top of existing list items.
DropMode.INSERT
, the user is restricted to
selecting the space between existing list items,
or before the first item
or after the last item in the list. Selecting existing
list items is not allowed.
DropMode.ON_OR_INSERT
is a combination
of the ON
and INSERT
modes.
The JTree
class provides the same set of
drop modes and the JTable
class has
several more specific to adding rows or columns.
To obtain the location of the drop, the
TransferSupport
class provides the
getDropLocation
method that returns the precise point
where the drop has occurred. But for a list component, the index of
the drop is more useful than a pixel location, so
JList
provides a special subclass, called
JList.DropLocation
. This class provides the
getIndex
and
isInsert
methods, which handle the math for you.
The table, tree, and text components each provide an implementation
of DropLocation
with methods that make the most sense for
each component.
The
JTable.setDropMode
method has the most choices.
The following table shows the methods for all four classes:
JList.DropLocation |
JTree.DropLocation |
JTable.DropLocation |
JTextComponent.DropLocation |
|---|---|---|---|
isInsert |
getChildIndex |
isInsertRow |
getIndex |
getIndex |
getPath |
isInsertColumn |
getBias |
getRow | |||
getColumn |
Next is a demo that implements a custom transfer handler for a list component so that it fully participates in drag and drop.


sign up
Football is for everyone, regardless of physical shape, gender, height and weight. American football is about cooperation and tactics, this is a group sport where all teammates depend on each other, to achieve the best possible result.  Regardless of your sports backgrounds, we will find the best position for you.


Learning the Basic's of Web Design has never been easier!
Welcome to Rendered where we teach you the basics of Web Design, Coding and Much More and show you how to WOW your viewers with amazing products you will learn to make through our courses.
Some of the Great Rendered Courses you can try out!
Get the basics correct, you will go a long way!
Add Interactivity and Funcionality to your website by Learing the Basics to JavaScript.
Learn the basics of CSS and owerhaul your website to look better, and to work better.
Learn the basics of HTML through Video's, Interactive Quizes, and Projects.
Rendered is the simplest, mordern, and reliable place on the internet to learn the basic's of Programming.


Personnel roster
Archives administration
Document specification
Work trajectory management
Official document circulation
Digital contract signature
Floating Population Management
Safety Production Management
Skills Management
Achievement Certificate Issuance


WaMDaM_v1.05 [WaMDaM_DBWrench_Schema_v1.05.xml]
A person record must be defined first to relate a source with an organization even if the person is unknown because sources connect to organizations through a person.
| PK | Name | Data Type | NULL | Auto | Default | Comment | FK |
|
| PersonID | Integer |
| Primary key identifier | |||
| PersonName | VarChar(255) | First and Last name of the person | |||||
| Address | VarChar(255) |
| The primary mailing address of the person, including street, city, state, zip, and country | ||||
| VarChar(255) |
| The primary email address of the person | |||||
| Phone | VarChar(50) |
| The primary phone number of the person | ||||
| PersonWebpage | VarChar(255) |
| A URL for the website for a person | ||||
| Position | VarChar(255) |
| Position of the person | ||||
| OrganizationID | Integer | Foreigh key identifier for an organization |
|
(none)
| Name | Parent Table | Child Table | Parent Columns | Child Columns |
| fk_People_Organizations | Metadata.Organizations | Metadata.People | OrganizationID | OrganizationID |
(none)
| Diagram Name |
| 01_WaMDaM |
| 02_WaMDaM_WCVs |


{{ message }}
This example is a quick exercise to illustrate how the top-aligned layout works. As you scroll, this navbar remains in its original position and moves with the rest of the page.
return »This example is a quick exercise to illustrate how the top-aligned layout works. As you scroll, this navbar remains in its original position and moves with the rest of the page.
return »


{% extends "hqwebapp/bootstrap3/base_section.html" %} {% load i18n %} {% load crispy_forms_tags %} {% block page_content %}
{% blocktrans %}Your backup phone number will be used if your primary method of registration is not available. Please enter a valid phone number.{% endblocktrans %}
{% elif wizard.steps.current == 'validation' %}{% blocktrans %}We've sent a token to your phone number. Please enter the token you've received.{% endblocktrans %}
{% endif %} {% endblock %}


Knowledge engineering refers to all technical, scientific and social aspects involved in building, maintaining and using knowledge-based systems.
reprezentacja wiedzy, automatyczne wnioskowanie, semantyka, projektowanie i zarządzanie ontologiami, grafy wiedzowe, linked (open) data, dane grafowe, projektowanie algorytmów, data modelling, data integration, computational & probabilistic logics, natural language processing, statistical relational learning, web APIs
Założyciel & Architekt Wiedzy
If you are interested in what we do and would like to work with us or collaborate on a new exciting project then we would like to hear from you!


Races in Use: 17
Choices Per Player: 1 2 3 4 5
Speaker: Don't Determine Determine Randomly Use House Rule (above)
Players' Names, Separated By Commas: (optional, to randomize seating order)


Normalize Timezones takes Google Analytics Country, Region, Hour and Sessions data and normalizes the time to visitors home country.
It useful for understanding behavior of sites with visitors from alot of different timezones by allowing you to estimate behavior based on time of day of the originating visitors home country.
Usage:
1- Open this Google Analytics Query Explorer Url
2- Authorize your google analytics account
3- Select the account and property you'd like to use.
4- Scroll down change start-date and end-date if you'd like. (Its set to show last 30 days of data by default).
5- Click Get Data button.
6- Either copy the entire result table OR click Excel TSV button to download a sheet and copy data from there.
7- Paste the data in the text field on http://marketlytics.github.io/ga-normalize-timezone and process the data.
8- On next screen see a list of countries and normalized session based on your accounts timezone. (You can toggle your Google Analytics views timezone at the top).


Two Jedi Knights escape a hostile blockade to find allie
s and come across a young boy who may bring balance to the Force, but the long dormant Sith resurface to reclaim their old glory.
Star Wars: Episode II - Attack of the Clones
Ten years after initially meeting, Anakin Skywalker shares a forbidden romance with Padmé, while Obi-Wan investigates an assassination attempt on the Senator and discovers a secret clone army crafted for the Jedi.
Star Wars: Episode III - Revenge of the Sith
As the Clone Wars near an end, the Sith Lord Darth Sidious steps out of the shadows, at which time Anakin succumbs to his emotions, becoming Darth Vader and putting his relationships with Obi-Wan and Padme at risk.


Freeeze yogurt with Zero Artificial Sweeteners is a great choice for your health lifestyle. Each delicious flavor has 90 calories, 13g of protein, and 3g of fiber per 5.3oz serving.
READ MOREOriginal greek yogurt is a delicious, nutritious, and convenient option to help you stick to your healthy routine. With a variety of fruity and indulgent flavors, 80 calories, and 12g of protein per 5.3oz serving, you can enjoy it every day!
For balance nutrition on-the-go, berry on the grove is a smart choice. Shake up your routine with your favorite fruit flavors in a smooth 7 fl. oz. protein smoothies with 9 grams of protein, 90 calories, 0 added sugar, and 0% fat. A delicious way to eat well on-the-go.


--- layout: default title: About Us ---
Sweeny Lime, LLC has been serving farmers since 2001. We purchased the lime business from our friend Eugene Steele who owned it for 40 years.
John Sweeny, owner, has an BS in Animal Science from Virginia Tech and farms with his wife, Nancy.
Nancy Sweeny, bookkeeper, [has a degree] from Shenandoah University and is an accomplished musician and singer.


Trump’s impeachment opposed by more independents: poll
by Bob FredericksOpposition to the House Democrats’ drive to impeach President Trump is growing, especially among independent voters, according to a new poll released Thursday.
The national Emerson College survey said that support for impeachment has flipped since October from 48 percent supporting it and 44 percent opposed to 43 percent supporting it and 45 percent opposed.
The biggest swing was among independents, who oppose impeachment now by 49 percent to 34 percent, a reversal from October when they supported impeachment by 48 percent to 39 percent who opposed.
The impeachment hearings were being watched or followed by 69 percent of voters.
Meanwhile, the president’s support in the Republican primary increased this month to 93 percent against GOP primary challengers Bill Weld and Joe Walsh.


Share to QR code
This application is a share target for other applications. It allows you to easily share URLs from your computer to another device (such as a smart phone)
How to use
From within another application, open the charms bar and select "SHARE"
Here is an example of it being used within Internet Explorer to share a URL


Remove a County Court Judgment
If you don't think the CCJ should have been issued in the first place, you can apply to have it removed. This is known as having it 'set aside'.
You'll have to go to a hearing. The court will usually only remove a CCJ if it accepts you didn't know about the claim against you.
You must pay a £255 fee to make the request. You can't get the fee refunded if the court rejects your request.


Files CCore/inc/TypeNumber.h CCore/src/TypeNumber.cpp
TypeNumber is a tool to convert a type into a number. Different types have different associated numbers. This feature can be used for the quick type comparison and the type reporting. To be used with this feature a type must have an associated Unid.
class TypeNumber
{
ulen number;
....
public:
ulen get() const { return number; }
bool operator == (TypeNumber obj) const { return number==obj.number; }
bool operator != (TypeNumber obj) const { return number!=obj.number; }
template <class ... TT>
bool oneOf() const;
};
TypeNumber is a lightweight type number class. It folds the type number.
get() returns the type number itself.
== and != operators can be used to compare objects.
oneOf() returns true, if the number is a number of one of types from the given type list.
template <UnidType T>
class TypeNumberOf : public TypeNumber
{
....
public:
TypeNumberOf();
};
And this derived class is a type number constructor for the given type.
TypeNumber<T>()==TypeNumber<S>() iff T==S


{% extends "base.html" %} {% block bodyclass %}questions{% endblock %} {% block content %}
You are about to reopen the question {{ question.title }}.


Chelsea 4-4 Ajax: Blues punish nine-man visitors with late comeback - 5 talking points
A crazy game at Stamford Bridge saw Chelsea come back from 4-1 down after Ajax had two men sent off
by Tom Hopkinson, https://www.mirror.co.uk/authors/tom-hopkinson/Frank Lampard's Chelsea hauled themselves back from the dead to earn a draw with Ajax in a bonkers match at Stamford Bridge.
The Blues were heading for a thumping when Donny van de Beek made it 4-1 on 55 minutes.
Cesar Azpilicueta reduced the deficit after 63 minutes to give Chelsea a glimmer of hope.
And when Ajax had both Daley Blind and Joel Veltman sent off for second bookable offences, both conceded within the same passage of play, the Blues smelled blood.
Veltman’s handball gave Jorginho the chance to score his second penalty, which he duly took, and Reece James fired home his first Champions League goal to pull his side level.
Azpilicueta’s sweet strike looked to have won it for Chelsea but the VAR ruled it out for handball.
Tammy Abraham’s own-goal gave Ajax a 107-second lead, Jorginho levelled from the spot soon after, and Ajax regained the lead when Quincey Promes nodded home.
Kepa Arrizabalaga then scored an own-goal as Hakim Ziyech’s cross hit his far post and rebounded home after hitting the diving keeper.
Van de Beek then looked to have put the game to bed, but the madness was about to begin.
1. Chelsea need to look at their defence
Chelsea have conceded more Premier League goals this season than any other side in the top 10.
In fact, you have to go down to 13th to find another team — West Ham — who have conceded as many as the 17 the Blues have let in.
It is a statistic that will bother manager Frank Lampard and, defensively, both the back four and team as a whole, looked shaky all night against Ajax.
They struggled to deal with several in-swinging crosses which were whipped in at pace in th first half and the jitters continued after the break when Donny Van de Beek was given far too much space in the box to score his goal.
Fikayo Tomori and half-time substitute Reece James are still young and still learning.
But Kurt Zouma, Cesar Azpilicueta and Marcos Alonso, replaced by James, are all experienced enough and talented enough to not be conceding four goals at home.
2. Azpilicueta proves rare goalscoring hero
Cesar Azpilicueta finishing was sublime and twice he put the ball in the back of the net with strikes his manager would have been proud of in his pomp.
Sadly for the Chelsea skipper and his side, the second was ruled out by the VAR, Paolo Valeri of Italy, who spotted a handball in the build-up.
The Spaniard had only managed six goals for Chelsea in more than 200 appearances — his manager will be demanding a few more after this showing.
3. Van de Beek gives Mount a lesson
Mason Mount has looked totally at ease as a first-team regular at a top-six club this season after making the breakthrough at Stamford Bridge.
But he will arguably have learned as much about himself as a player in the hour or so he played against Ajax before limping off than any other game in the past three or four months.
Donny van de Beek is a special defensive midfielder and he barely gave the Chelsea youngster a look in all evening.
Mount is only 19 and has plenty of time on his side but this was a reminder that he needs to keep working very hard if he is going to be unpicking midfields like Ajax in the years ahead.
Worryingly, Mount's evening ended prematurely as he hobbled off injured, making him a doubt for England duty.
4. Jorginho and Kovacic worthy of their praise
Jorginho and Mateo Kovacic drew special praise from manager Frank Lampard in his pre-match programme notes and understandably so given their recent performances.
“Our support was fantastic at Vicarage Road [on Saturday],” he wrote. “I heard a lot of singing for Mateo Kovacic and Jorginho, and I’m delighted with that — our fans appreciate effort and good play, and you can see both of those attributes in the way they are playing at the moment.”
Both have been excellent in midfield this season but have maybe found their performances overshadowed by the emergence of Mason Mount.
Mount, for the most part, has been brilliant, of course, but those two deserve a lot of credit for the work they do that gives him the freedom to play.
5. Blind's unhappy return
Daley Blind return to England came to an abrupt and unhappy end as he was sent off for two bookable offences.
Both were poor challenges, especially the second on Tammy Abraham, although it looked more mistimed than malicious.
You might say he looked like he’d lost a yard of pace but Manchester United fans will probably tell you he didn’t have that much in the first place.


| with_abort {rlang} | R Documentation |
with_abort()
promotes conditions as if they were thrown with
abort()
. These errors embed a backtrace. They are
particularly suitable to be set as parent errors (see parent
argument of abort()
).
with_abort(expr, classes = "error")
expr |
An expression run in a context where errors are promoted to rlang errors. |
classes |
Character vector of condition classes that should be promoted to rlang errors. |
with_abort()
installs a calling handler for errors and
rethrows non-rlang errors with abort()
. However, error handlers
installed within with_abort()
have priority. For this reason,
you should use tryCatch()
and exiting handlers outside
with_abort()
rather than inside.
# with_abort() automatically casts simple errors thrown by stop() # to rlang errors. It is is handy for rethrowing low level # errors. The backtraces are then segmented between the low level # and high level contexts. f <- function() g() g <- function() stop("Low level error") high_level <- function() { with_handlers( with_abort(f()), error = ~ abort("High level error", parent = .) ) }


I met another Drupaler about a year later for first time
The Drupal Community
Wanted to know other Drupalers
So started to to talk with other Latin American drupaleros
Started with regular meetings
First Drupal Event Drupal Summit Latino 2013 (Ecuador)
DrupalCamp Santiago de Chile 2015
Embracing the change
Heraclitus of Ephesus (~500 BC)
Everything changes and nothing stands still.
All is flux, nothing stays still.
No man ever steps in the same river twice.
All things . . . are in flux like a river. Heraclitus’s insistence on the process of change
as fundamental to the world poses a question
to us when we are facing difficult changes that we might want to deny or resist. By insisting that
something or someone stay the same, could it be that we are destroying the very thing we wish to
preserve? In any particular case, when we are resisting change, we might ask ourselves, is this
like trying to stop a river’s waters from flowing?


source file: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py
file stats: 738 lines, 299 executed: 40.5% covered
1. # Copyright 2001-2014 by Vinay Sajip. All Rights Reserved. 2. # 3. # Permission to use, copy, modify, and distribute this software and its 4. # documentation for any purpose and without fee is hereby granted, 5. # provided that the above copyright notice appear in all copies and that 6. # both that copyright notice and this permission notice appear in 7. # supporting documentation, and that the name of Vinay Sajip 8. # not be used in advertising or publicity pertaining to distribution 9. # of the software without specific, written prior permission. 10.  # ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL 12. # VINAY SAJIP BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 13. # ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER 14. # IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 15. # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16. 17. """ 18. Logging package for Python. Based on PEP 282 and comments thereto in 19. comp.lang.python. 20. 21. Copyright (C) 2001-2014 Vinay Sajip. All Rights Reserved. 22. 23. To use, simply 'import logging' and log away! 24. """ 25. 26. import sys, os, time, cStringIO, traceback, warnings, weakref, collections 27. 28. __all__ = ['BASIC_FORMAT', 'BufferingFormatter', 'CRITICAL', 'DEBUG', 'ERROR', 29. 'FATAL', 'FileHandler', 'Filter', 'Formatter', 'Handler', 'INFO', 30. 'LogRecord', 'Logger', 'LoggerAdapter', 'NOTSET', 'NullHandler', 31. 'StreamHandler', 'WARN', 'WARNING', 'addLevelName', 'basicConfig', 32. 'captureWarnings', 'critical', 'debug', 'disable', 'error', 33. 'exception', 'fatal', 'getLevelName', 'getLogger', 'getLoggerClass', 34. 'info', 'log', 'makeLogRecord', 'setLoggerClass', 'warn', 'warning'] 35. 36. try: 37. import codecs 38. except ImportError: 39. codecs = None 40. 41. try: 42. import thread 43. import threading 44. except ImportError: 45. thread = None 46. 47. __author__ = "Vinay Sajip<EMAIL_ADDRESS>48. __status__ = "production" 49. # Note: the attributes below are no longer maintained. 50. __version__ = "<IP_ADDRESS>" 51. __date__ = "07 February 2010" 52. 53. #--------------------------------------------------------------------------- 54. # Miscellaneous module data 55. #--------------------------------------------------------------------------- 56. try: 57. unicode 58. _unicode = True 59. except NameError: 60. _unicode = False 61. 62. # next bit filched from 1.5.2's inspect.py 63. def currentframe(): 64. """Return the frame object for the caller's stack frame.""" 65. try: 66. raise Exception 67. except: 68. return sys.exc_info()[2].tb_frame.f_back 69. 70. if hasattr(sys, '_getframe'): currentframe = lambda: sys._getframe(3) 71. # done filching 72. 73. # 74. # _srcfile is used when walking the stack to check when we've got the first 75. # caller stack frame. 76. # 77. _srcfile = os.path.normcase(currentframe.__code__.co_filename) 78. 79. # _srcfile is only used in conjunction with sys._getframe(). 80. # To provide compatibility with older versions of Python, set _srcfile 81. # to None if _getframe() is not available; this value will prevent 82. # findCaller() from being called. 83. #if not hasattr(sys, "_getframe"): 84. # _srcfile = None 85. 86. # 87. #_startTime is used as the base when calculating the relative time of events 88. # 89. _startTime = time.time() 90. 91. # 92. #raiseExceptions is used to see if exceptions during handling should be 93. #propagated 94. # 95. raiseExceptions = 1 96. 97. # 98. # If you don't want threading information in the log, set this to zero 99. # 100. logThreads = 1 101. 102. # 103. # If you don't want multiprocessing information in the log, set this to zero 104. # 105. logMultiprocessing = 1 106. 107. # 108. # If you don't want process information in the log, set this to zero 109. # 110. logProcesses = 1 111. 112. #--------------------------------------------------------------------------- 113. # Level related stuff 114. #--------------------------------------------------------------------------- 115. # 116. # Default levels and level names, these can be replaced with any positive set 117. # of values having corresponding names. There is a pseudo-level, NOTSET, which 118. # is only really there as a lower limit for user-defined levels. Handlers and 119. # loggers are initialized with NOTSET so that they will log all messages, even 120. # at user-defined levels. 121. # 122. 123. CRITICAL = 50 124. FATAL = CRITICAL 125. ERROR = 40 126. WARNING = 30 127. WARN = WARNING 128. INFO = 20 129. DEBUG = 10 130. NOTSET = 0 131. 132. _levelNames = { 133. CRITICAL : 'CRITICAL', 134. ERROR : 'ERROR', 135. WARNING : 'WARNING', 136. INFO : 'INFO', 137. DEBUG : 'DEBUG', 138. NOTSET : 'NOTSET', 139. 'CRITICAL' : CRITICAL, 140. 'ERROR' : ERROR, 141. 'WARN' : WARNING, 142. 'WARNING' : WARNING, 143. 'INFO' : INFO, 144. 'DEBUG' : DEBUG, 145. 'NOTSET' : NOTSET, 146. } 147. 148. def getLevelName(level): 149. """ 150. Return the textual representation of logging level 'level'. 151. 152. If the level is one of the predefined levels (CRITICAL, ERROR, WARNING, 153. INFO, DEBUG) then you get the corresponding string. If you have 154. associated levels with names using addLevelName then the name you have 155. associated with 'level' is returned. 156. 157. If a numeric value corresponding to one of the defined levels is passed 158. in, the corresponding string representation is returned. 159. 160. Otherwise, the string "Level %s" % level is returned. 161. """ 162. return _levelNames.get(level, ("Level %s" % level)) 163. 164. def addLevelName(level, levelName): 165. """ 166. Associate 'levelName' with 'level'. 167. 168. This is used when converting levels to text during message formatting. 169. """ 170. _acquireLock() 171. try: #unlikely to cause an exception, but you never know... 172. _levelNames[level] = levelName 173. _levelNames[levelName] = level 174. finally: 175. _releaseLock() 176. 177. def _checkLevel(level): 178. if isinstance(level, (int, long)): 179. rv = level 180. elif str(level) == level: 181. if level not in _levelNames: 182. raise ValueError("Unknown level: %r" % level) 183. rv = _levelNames[level] 184. else: 185. raise TypeError("Level not an integer or a valid string: %r" % level) 186. return rv 187. 188. #--------------------------------------------------------------------------- 189. # Thread-related stuff 190. #--------------------------------------------------------------------------- 191. 192. # 193. #_lock is used to serialize access to shared data structures in this module. 194. #This needs to be an RLock because fileConfig() creates and configures 195. #Handlers, and so might arbitrary user threads. Since Handler code updates the 196. #shared dictionary _handlers, it needs to acquire the lock. But if configuring, 197. #the lock would already have been acquired - so we need an RLock. 198. #The same argument applies to Loggers and Manager.loggerDict. 199. # 200. if thread: 201. _lock = threading.RLock() 202. else: 203. _lock = None 204. 205. def _acquireLock(): 206. """ 207. Acquire the module-level lock for serializing access to shared data. 208. 209. This should be released with _releaseLock(). 210. """ 211. if _lock: 212. _lock.acquire() 213. 214. def _releaseLock(): 215. """ 216. Release the module-level lock acquired by calling _acquireLock(). 217. """ 218. if _lock: 219. _lock.release() 220. 221. #--------------------------------------------------------------------------- 222. # The logging record 223. #--------------------------------------------------------------------------- 224. 225. class LogRecord(object): 226. """ 227. A LogRecord instance represents an event being logged. 228. 229. LogRecord instances are created every time something is logged. They 230. contain all the information pertinent to the event being logged. The 231. main information passed in is in msg and args, which are combined 232. using str(msg) % args to create the message field of the record. The 233. record also includes information such as when the record was created, 234. the source line where the logging call was made, and any exception 235. information to be logged. 236. """ 237. def __init__(self, name, level, pathname, lineno, 238. msg, args, exc_info, func=None): 239. """ 240. Initialize a logging record with interesting information. 241. """ 242. ct = time.time() 243. self.name = name 244. self.msg = msg 245. # 246. # The following statement allows passing of a dictionary as a sole 247. # argument, so that you can do something like 248. # logging.debug("a %(a)d b %(b)s", {'a':1, 'b':2}) 249. # Suggested by Stefan Behnel. 250. # Note that without the test for args[0], we get a problem because 251. # during formatting, we test to see if the arg is present using 252. # 'if self.args:'. If the event being logged is e.g. 'Value is %d' 253. # and if the passed arg fails 'if self.args:' then no formatting 254. # is done. For example, logger.warn('Value is %d', 0) would log 255. # 'Value is %d' instead of 'Value is 0'. 256. # For the use case of passing a dictionary, this should not be a 257. # problem. 258. # Issue #21172: a request was made to relax the isinstance check 259. # to hasattr(args[0], '__getitem__'). However, the docs on string 260. # formatting still seem to suggest a mapping object is required. 261. # Thus, while not removing the isinstance check, it does now look 262. # for collections.Mapping rather than, as before, dict. 263. if (args and len(args) == 1 and isinstance(args[0], collections.Mapping) 264. and args[0]): 265. args = args[0] 266. self.args = args 267. self.levelname = getLevelName(level) 268. self.levelno = level 269. self.pathname = pathname 270. try: 271. self.filename = os.path.basename(pathname) 272. self.module = os.path.splitext(self.filename)[0] 273. except (TypeError, ValueError, AttributeError): 274. self.filename = pathname 275. self.module = "Unknown module" 276. self.exc_info = exc_info 277. self.exc_text = None # used to cache the traceback text 278. self.lineno = lineno 279. self.funcName = func 280. self.created = ct 281. self.msecs = (ct - long(ct)) * 1000 282. self.relativeCreated = (self.created - _startTime) * 1000 283. if logThreads and thread: 284. self.thread = thread.get_ident() 285. self.threadName = threading.current_thread().name 286. else: 287. self.thread = None 288. self.threadName = None 289. if not logMultiprocessing: 290. self.processName = None 291. else: 292. self.processName = 'MainProcess' 293. mp = sys.modules.get('multiprocessing') 294. if mp is not None: 295. # Errors may occur if multiprocessing has not finished loading 296. # yet - e.g. if a custom import hook causes third-party code 297. # to run when multiprocessing calls import. See issue 8200 298. # for an example 299. try: 300. self.processName = mp.current_process().name 301. except StandardError: 302. pass 303. if logProcesses and hasattr(os, 'getpid'): 304. self.process = os.getpid() 305. else: 306. self.process = None 307. 308. def __str__(self): 309. return '<LogRecord: %s, %s, %s, %s, "%s">'%(self.name, self.levelno, 310. self.pathname, self.lineno, self.msg) 311. 312. def getMessage(self): 313. """ 314. Return the message for this LogRecord. 315. 316. Return the message for this LogRecord after merging any user-supplied 317. arguments with the message. 318. """ 319. if not _unicode: #if no unicode support... 320. msg = str(self.msg) 321. else: 322. msg = self.msg 323. if not isinstance(msg, basestring): 324. try: 325. msg = str(self.msg) 326. except UnicodeError: 327. msg = self.msg #Defer encoding till later 328. if self.args: 329. msg = msg % self.args 330. return msg 331. 332. def makeLogRecord(dict): 333. """ 334. Make a LogRecord whose attributes are defined by the specified dictionary, 335. This function is useful for converting a logging event received over 336. a socket connection (which is sent as a dictionary) into a LogRecord 337. instance. 338. """ 339. rv = LogRecord(None, None, "", 0, "", (), None, None) 340. rv.__dict__.update(dict) 341. return rv 342. 343. #--------------------------------------------------------------------------- 344. # Formatter classes and functions 345. #--------------------------------------------------------------------------- 346. 347. class Formatter(object): 348. """ 349. Formatter instances are used to convert a LogRecord to text. 350. 351. Formatters need to know how a LogRecord is constructed. They are 352. responsible for converting a LogRecord to (usually) a string which can 353. be interpreted by either a human or an external system. The base Formatter 354. allows a formatting string to be specified. If none is supplied, the 355. default value of "%s(message)\\n" is used. 356. 357. The Formatter can be initialized with a format string which makes use of 358. knowledge of the LogRecord attributes - e.g. the default value mentioned 359. above makes use of the fact that the user's message and arguments are pre- 360. formatted into a LogRecord's message attribute. Currently, the useful 361. attributes in a LogRecord are described by: 362. 363. %(name)s Name of the logger (logging channel) 364. %(levelno)s Numeric logging level for the message (DEBUG, INFO, 365. WARNING, ERROR, CRITICAL) 366. %(levelname)s Text logging level for the message ("DEBUG", "INFO", 367. "WARNING", "ERROR", "CRITICAL") 368. %(pathname)s Full pathname of the source file where the logging 369. call was issued (if available) 370. %(filename)s Filename portion of pathname 371. %(module)s Module (name portion of filename) 372. %(lineno)d Source line number where the logging call was issued 373. (if available) 374. %(funcName)s Function name 375. %(created)f Time when the LogRecord was created (time.time() 376. return value) 377. %(asctime)s Textual time when the LogRecord was created 378. %(msecs)d Millisecond portion of the creation time 379. %(relativeCreated)d Time in milliseconds when the LogRecord was created, 380. relative to the time the logging module was loaded 381. (typically at application startup time) 382. %(thread)d Thread ID (if available) 383. %(threadName)s Thread name (if available) 384. %(process)d Process ID (if available) 385. %(message)s The result of record.getMessage(), computed just as 386. the record is emitted 387. """ 388. 389. converter = time.localtime 390. 391. def __init__(self, fmt=None, datefmt=None): 392. """ 393. Initialize the formatter with specified format strings. 394. 395. Initialize the formatter either with the specified format string, or a 396. default as described above. Allow for specialized date formatting with 397. the optional datefmt argument (if omitted, you get the ISO8601 format). 398. """ 399. if fmt: 400. self._fmt = fmt 401. else: 402. self._fmt = "%(message)s" 403. self.datefmt = datefmt 404. 405. def formatTime(self, record, datefmt=None): 406. """ 407. Return the creation time of the specified LogRecord as formatted text. 408. 409. This method should be called from format() by a formatter which 410. wants to make use of a formatted time. This method can be overridden 411. in formatters to provide for any specific requirement, but the 412. basic behaviour is as follows: if datefmt (a string) is specified, 413. it is used with time.strftime() to format the creation time of the 414. record. Otherwise, the ISO8601 format is used. The resulting 415. string is returned. This function uses a user-configurable function 416. to convert the creation time to a tuple. By default, time.localtime() 417. is used; to change this for a particular formatter instance, set the 418. 'converter' attribute to a function with the same signature as 419. time.localtime() or time.gmtime(). To change it for all formatters, 420. for example if you want all logging times to be shown in GMT, 421. set the 'converter' attribute in the Formatter class. 422. """ 423. ct = self.converter(record.created) 424. if datefmt: 425. s = time.strftime(datefmt, ct) 426. else: 427. t = time.strftime("%Y-%m-%d %H:%M:%S", ct) 428. s = "%s,%03d" % (t, record.msecs) 429. return s 430. 431. def formatException(self, ei): 432. """ 433. Format and return the specified exception information as a string. 434. 435. This default implementation just uses 436. traceback.print_exception() 437. """ 438. sio = cStringIO.StringIO() 439. traceback.print_exception(ei[0], ei[1], ei[2], None, sio) 440. s = sio.getvalue() 441. sio.close() 442. if s[-1:] == "\n": 443. s = s[:-1] 444. return s 445. 446. def usesTime(self): 447. """ 448. Check if the format uses the creation time of the record. 449. """ 450. return self._fmt.find("%(asctime)") >= 0 451. 452. def format(self, record): 453. """ 454. Format the specified record as text. 455. 456. The record's attribute dictionary is used as the operand to a 457. string formatting operation which yields the returned string. 458. Before formatting the dictionary, a couple of preparatory steps 459. are carried out. The message attribute of the record is computed 460. using LogRecord.getMessage(). If the formatting string uses the 461. time (as determined by a call to usesTime(), formatTime() is 462. called to format the event time. If there is exception information, 463. it is formatted using formatException() and appended to the message. 464. """ 465. record.message = record.getMessage() 466. if self.usesTime(): 467. record.asctime = self.formatTime(record, self.datefmt) 468. try: 469. s = self._fmt % record.__dict__ 470. except UnicodeDecodeError as e: 471. # Issue 25664. The logger name may be Unicode. Try again ... 472. try: 473. record.name = record.name.decode('utf-8') 474. s = self._fmt % record.__dict__ 475. except UnicodeDecodeError: 476. raise e 477. if record.exc_info: 478. # Cache the traceback text to avoid converting it multiple times 479. # (it's constant anyway) 480. if not record.exc_text: 481. record.exc_text = self.formatException(record.exc_info) 482. if record.exc_text: 483. if s[-1:] != "\n": 484. s = s + "\n" 485. try: 486. s = s + record.exc_text 487. except UnicodeError: 488. # Sometimes filenames have non-ASCII chars, which can lead 489. # to errors when s is Unicode and record.exc_text is str 490. # See issue 8924. 491. # We also use replace for when there are multiple 492. # encodings, e.g. UTF-8 for the filesystem and latin-1 493. # for a script. See issue 13232. 494. s = s + record.exc_text.decode(sys.getfilesystemencoding(), 495. 'replace') 496. return s 497. 498. # 499. # The default formatter to use when no other is specified 500. # 501. _defaultFormatter = Formatter() 502. 503. class BufferingFormatter(object): 504. """ 505. A formatter suitable for formatting a number of records. 506. """ 507. def __init__(self, linefmt=None): 508. """ 509. Optionally specify a formatter which will be used to format each 510. individual record. 511. """ 512. if linefmt: 513. self.linefmt = linefmt 514. else: 515. self.linefmt = _defaultFormatter 516. 517. def formatHeader(self, records): 518. """ 519. Return the header string for the specified records. 520. """ 521. return "" 522. 523. def formatFooter(self, records): 524. """ 525. Return the footer string for the specified records. 526. """ 527. return "" 528. 529. def format(self, records): 530. """ 531. Format the specified records and return the result as a string. 532. """ 533. rv = "" 534. if len(records) > 0: 535. rv = rv + self.formatHeader(records) 536. for record in records: 537. rv = rv + self.linefmt.format(record) 538. rv = rv + self.formatFooter(records) 539. return rv 540. 541. #--------------------------------------------------------------------------- 542. # Filter classes and functions 543. #--------------------------------------------------------------------------- 544. 545. class Filter(object): 546. """ 547. Filter instances are used to perform arbitrary filtering of LogRecords. 548. 549. Loggers and Handlers can optionally use Filter instances to filter 550. records as desired. The base filter class only allows events which are 551. below a certain point in the logger hierarchy. For example, a filter 552. initialized with "A.B" will allow events logged by loggers "A.B", 553. "A.B.C", "A.B.C.D", "A.B.D" etc. but not "A.BB", "B.A.B" etc. If 554. initialized with the empty string, all events are passed. 555. """ 556. def __init__(self, name=''): 557. """ 558. Initialize a filter. 559. 560. Initialize with the name of the logger which, together with its 561. children, will have its events allowed through the filter. If no 562. name is specified, allow every event. 563. """ 564. self.name = name 565. self.nlen = len(name) 566. 567. def filter(self, record): 568. """ 569. Determine if the specified record is to be logged. 570. 571. Is the specified record to be logged? Returns 0 for no, nonzero for 572. yes. If deemed appropriate, the record may be modified in-place. 573. """ 574. if self.nlen == 0: 575. return 1 576. elif self.name == record.name: 577. return 1 578. elif record.name.find(self.name, 0, self.nlen) != 0: 579. return 0 580. return (record.name[self.nlen] == ".") 581. 582. class Filterer(object): 583. """ 584. A base class for loggers and handlers which allows them to share 585. common code. 586. """ 587. def __init__(self): 588. """ 589. Initialize the list of filters to be an empty list. 590. """ 591. self.filters = [] 592. 593. def addFilter(self, filter): 594. """ 595. Add the specified filter to this handler. 596. """ 597. if not (filter in self.filters): 598. self.filters.append(filter) 599. 600. def removeFilter(self, filter): 601. """ 602. Remove the specified filter from this handler. 603. """ 604. if filter in self.filters: 605. self.filters.remove(filter) 606. 607. def filter(self, record): 608. """ 609. Determine if a record is loggable by consulting all the filters. 610. 611. The default is to allow the record to be logged; any filter can veto 612. this and the record is then dropped. Returns a zero value if a record 613. is to be dropped, else non-zero. 614. """ 615. rv = 1 616. for f in self.filters: 617. if not f.filter(record): 618. rv = 0 619. break 620. return rv 621. 622. #--------------------------------------------------------------------------- 623. # Handler classes and functions 624. #--------------------------------------------------------------------------- 625. 626. _handlers = weakref.WeakValueDictionary() #map of handler names to handlers 627. _handlerList = [] # added to allow handlers to be removed in reverse of order initialized 628. 629. def _removeHandlerRef(wr): 630. """ 631. Remove a handler reference from the internal cleanup list. 632. """ 633. # This function can be called during module teardown, when globals are 634. # set to None. It can also be called from another thread. So we need to 635. # pre-emptively grab the necessary globals and check if they're None, 636. # to prevent race conditions and failures during interpreter shutdown. 637. acquire, release, handlers = _acquireLock, _releaseLock, _handlerList 638. if acquire and release and handlers: 639. try: 640. acquire() 641. try: 642. if wr in handlers: 643. handlers.remove(wr) 644. finally: 645. release() 646. except TypeError: 647. # https://bugs.python.org/issue21149 - If the RLock object behind 648. # acquire() and release() has been partially finalized you may see 649. # an error about NoneType not being callable. Absolutely nothing 650. # we can do in this GC during process shutdown situation. Eat it. 651. pass 652. 653. def _addHandlerRef(handler): 654. """ 655. Add a handler to the internal cleanup list using a weak reference. 656. """ 657. _acquireLock() 658. try: 659. _handlerList.append(weakref.ref(handler, _removeHandlerRef)) 660. finally: 661. _releaseLock() 662. 663. class Handler(Filterer): 664. """ 665. Handler instances dispatch logging events to specific destinations. 666. 667. The base handler class. Acts as a placeholder which defines the Handler 668. interface. Handlers can optionally use Formatter instances to format 669. records as desired. By default, no formatter is specified; in this case, 670. the 'raw' message as determined by record.message is logged. 671. """ 672. def __init__(self, level=NOTSET): 673. """ 674. Initializes the instance - basically setting the formatter to None 675. and the filter list to empty. 676. """ 677. Filterer.__init__(self) 678. self._name = None 679. self.level = _checkLevel(level) 680. self.formatter = None 681. # Add the handler to the global _handlerList (for cleanup on shutdown) 682. _addHandlerRef(self) 683. self.createLock() 684. 685. def get_name(self): 686. return self._name 687. 688. def set_name(self, name): 689. _acquireLock() 690. try: 691. if self._name in _handlers: 692. del _handlers[self._name] 693. self._name = name 694. if name: 695. _handlers[name] = self 696. finally: 697. _releaseLock() 698. 699. name = property(get_name, set_name) 700. 701. def createLock(self): 702. """ 703. Acquire a thread lock for serializing access to the underlying I/O. 704. """ 705. if thread: 706. self.lock = threading.RLock() 707. else: 708. self.lock = None 709. 710. def acquire(self): 711. """ 712. Acquire the I/O thread lock. 713. """ 714. if self.lock: 715. self.lock.acquire() 716. 717. def release(self): 718. """ 719. Release the I/O thread lock. 720. """ 721. if self.lock: 722. self.lock.release() 723. 724. def setLevel(self, level): 725. """ 726. Set the logging level of this handler. 727. """ 728. self.level = _checkLevel(level) 729. 730. def format(self, record): 731. """ 732. Format the specified record. 733. 734. If a formatter is set, use it. Otherwise, use the default formatter 735. for the module. 736. """ 737. if self.formatter: 738. fmt = self.formatter 739. else: 740. fmt = _defaultFormatter 741. return fmt.format(record) 742. 743. def emit(self, record): 744. """ 745. Do whatever it takes to actually log the specified logging record. 746. 747. This version is intended to be implemented by subclasses and so 748. raises a NotImplementedError. 749. """ 750. raise NotImplementedError('emit must be implemented ' 751. 'by Handler subclasses') 752. 753. def handle(self, record): 754. """ 755. Conditionally emit the specified logging record. 756. 757. Emission depends on filters which may have been added to the handler. 758. Wrap the actual emission of the record with acquisition/release of 759. the I/O thread lock. Returns whether the filter passed the record for 760. emission. 761. """ 762. rv = self.filter(record) 763. if rv: 764. self.acquire() 765. try: 766. self.emit(record) 767. finally: 768. self.release() 769. return rv 770. 771. def setFormatter(self, fmt): 772. """ 773. Set the formatter for this handler. 774. """ 775. self.formatter = fmt 776. 777. def flush(self): 778. """ 779. Ensure all logging output has been flushed. 780. 781. This version does nothing and is intended to be implemented by 782. subclasses. 783. """ 784. pass 785. 786. def close(self): 787. """ 788. Tidy up any resources used by the handler. 789. 790. This version removes the handler from an internal map of handlers, 791. _handlers, which is used for handler lookup by name. Subclasses 792. should ensure that this gets called from overridden close() 793. methods. 794. """ 795. #get the module data lock, as we're updating a shared structure. 796. _acquireLock() 797. try: #unlikely to raise an exception, but you never know... 798. if self._name and self._name in _handlers: 799. del _handlers[self._name] 800. finally: 801. _releaseLock() 802. 803. def handleError(self, record): 804. """ 805. Handle errors which occur during an emit() call. 806. 807. This method should be called from handlers when an exception is 808. encountered during an emit() call. If raiseExceptions is false, 809. exceptions get silently ignored. This is what is mostly wanted 810. for a logging system - most users will not care about errors in 811. the logging system, they are more interested in application errors. 812. You could, however, replace this with a custom handler if you wish. 813. The record which was being processed is passed in to this method. 814. """ 815. if raiseExceptions and sys.stderr: # see issue 13807 816. ei = sys.exc_info() 817. try: 818. traceback.print_exception(ei[0], ei[1], ei[2], 819. None, sys.stderr) 820. sys.stderr.write('Logged from file %s, line %s\n' % ( 821. record.filename, record.lineno)) 822. except IOError: 823. pass # see issue 5971 824. finally: 825. del ei 826. 827. class StreamHandler(Handler): 828. """ 829. A handler class which writes logging records, appropriately formatted, 830. to a stream. Note that this class does not close the stream, as 831. sys.stdout or sys.stderr may be used. 832. """ 833. 834. def __init__(self, stream=None): 835. """ 836. Initialize the handler. 837. 838. If stream is not specified, sys.stderr is used. 839. """ 840. Handler.__init__(self) 841. if stream is None: 842. stream = sys.stderr 843. self.stream = stream 844. 845. def flush(self): 846. """ 847. Flushes the stream. 848. """ 849. self.acquire() 850. try: 851. if self.stream and hasattr(self.stream, "flush"): 852. self.stream.flush() 853. finally: 854. self.release() 855. 856. def emit(self, record): 857. """ 858. Emit a record. 859. 860. If a formatter is specified, it is used to format the record. 861. The record is then written to the stream with a trailing newline. If 862. exception information is present, it is formatted using 863. traceback.print_exception and appended to the stream. If the stream 864. has an 'encoding' attribute, it is used to determine how to do the 865. output to the stream. 866. """ 867. try: 868. msg = self.format(record) 869. stream = self.stream 870. fs = "%s\n" 871. if not _unicode: #if no unicode support... 872. stream.write(fs % msg) 873. else: 874. try: 875. if (isinstance(msg, unicode) and 876. getattr(stream, 'encoding', None)): 877. ufs = u'%s\n' 878. try: 879. stream.write(ufs % msg) 880. except UnicodeEncodeError: 881. #Printing to terminals sometimes fails. For example, 882. #with an encoding of 'cp1251', the above write will 883. #work if written to a stream opened or wrapped by 884. #the codecs module, but fail when writing to a 885. #terminal even when the codepage is set to cp1251. 886. #An extra encoding step seems to be needed. 887. stream.write((ufs % msg).encode(stream.encoding)) 888. else: 889. stream.write(fs % msg) 890. except UnicodeError: 891. stream.write(fs % msg.encode("UTF-8")) 892. self.flush() 893. except (KeyboardInterrupt, SystemExit): 894. raise 895. except: 896. self.handleError(record) 897. 898. class FileHandler(StreamHandler): 899. """ 900. A handler class which writes formatted logging records to disk files. 901. """ 902. def __init__(self, filename, mode='a', encoding=None, delay=0): 903. """ 904. Open the specified file and use it as the stream for logging. 905. """ 906. #keep the absolute path, otherwise derived classes which use this 907. #may come a cropper when the current directory changes 908. if codecs is None: 909. encoding = None 910. self.baseFilename = os.path.abspath(filename) 911. self.mode = mode 912. self.encoding = encoding 913. self.delay = delay 914. if delay: 915. #We don't open the stream, but we still need to call the 916. #Handler constructor to set level, formatter, lock etc. 917. Handler.__init__(self) 918. self.stream = None 919. else: 920. StreamHandler.__init__(self, self._open()) 921. 922. def close(self): 923. """ 924. Closes the stream. 925. """ 926. self.acquire() 927. try: 928. try: 929. if self.stream: 930. try: 931. self.flush() 932. finally: 933. stream = self.stream 934. self.stream = None 935. if hasattr(stream, "close"): 936. stream.close() 937. finally: 938. # Issue #19523: call unconditionally to 939. # prevent a handler leak when delay is set 940. StreamHandler.close(self) 941. finally: 942. self.release() 943. 944. def _open(self): 945. """ 946. Open the current base file with the (original) mode and encoding. 947. Return the resulting stream. 948. """ 949. if self.encoding is None: 950. stream = open(self.baseFilename, self.mode) 951. else: 952. stream = codecs.open(self.baseFilename, self.mode, self.encoding) 953. return stream 954. 955. def emit(self, record): 956. """ 957. Emit a record. 958. 959. If the stream was not opened because 'delay' was specified in the 960. constructor, open it before calling the superclass's emit. 961. """ 962. if self.stream is None: 963. self.stream = self._open() 964. StreamHandler.emit(self, record) 965. 966. #--------------------------------------------------------------------------- 967. # Manager classes and functions 968. #--------------------------------------------------------------------------- 969. 970. class PlaceHolder(object): 971. """ 972. PlaceHolder instances are used in the Manager logger hierarchy to take 973. the place of nodes for which no loggers have been defined. This class is 974. intended for internal use only and not as part of the public API. 975. """ 976. def __init__(self, alogger): 977. """ 978. Initialize with the specified logger being a child of this placeholder. 979. """ 980. #self.loggers = [alogger] 981. self.loggerMap = { alogger : None } 982. 983. def append(self, alogger): 984. """ 985. Add the specified logger as a child of this placeholder. 986. """ 987. #if alogger not in self.loggers: 988. if alogger not in self.loggerMap: 989. #self.loggers.append(alogger) 990. self.loggerMap[alogger] = None 991. 992. # 993. # Determine which class to use when instantiating loggers. 994. # 995. _loggerClass = None 996. 997. def setLoggerClass(klass): 998. """ 999. Set the class to be used when instantiating a logger. The class should 1000. define __init__() such that only a name argument is required, and the 1001. __init__() should call Logger.__init__() 1002. """ 1003. if klass != Logger: 1004. if not issubclass(klass, Logger): 1005. raise TypeError("logger not derived from logging.Logger: " 1006. + klass.__name__) 1007. global _loggerClass 1008. _loggerClass = klass 1009. 1010. def getLoggerClass(): 1011. """ 1012. Return the class to be used when instantiating a logger. 1013. """ 1014. 1015. return _loggerClass 1016. 1017. class Manager(object): 1018. """ 1019. There is [under normal circumstances] just one Manager instance, which 1020. holds the hierarchy of loggers. 1021. """ 1022. def __init__(self, rootnode): 1023. """ 1024. Initialize the manager with the root node of the logger hierarchy. 1025. """ 1026. self.root = rootnode 1027. self.disable = 0 1028. self.emittedNoHandlerWarning = 0 1029. self.loggerDict = {} 1030. self.loggerClass = None 1031. 1032. def getLogger(self, name): 1033. """ 1034. Get a logger with the specified name (channel name), creating it 1035. if it doesn't yet exist. This name is a dot-separated hierarchical 1036. name, such as "a", "a.b", "a.b.c" or similar. 1037. 1038. If a PlaceHolder existed for the specified name [i.e. the logger 1039. didn't exist but a child of it did], replace it with the created 1040. logger and fix up the parent/child references which pointed to the 1041. placeholder to now point to the logger. 1042. """ 1043. rv = None 1044. if not isinstance(name, basestring): 1045. raise TypeError('A logger name must be string or Unicode') 1046. if isinstance(name, unicode): 1047. name = name.encode('utf-8') 1048. _acquireLock() 1049. try: 1050. if name in self.loggerDict: 1051. rv = self.loggerDict[name] 1052. if isinstance(rv, PlaceHolder): 1053. ph = rv 1054. rv = (self.loggerClass or _loggerClass)(name) 1055. rv.manager = self 1056. self.loggerDict[name] = rv 1057. self._fixupChildren(ph, rv) 1058. self._fixupParents(rv) 1059. else: 1060. rv = (self.loggerClass or _loggerClass)(name) 1061. rv.manager = self 1062. self.loggerDict[name] = rv 1063. self._fixupParents(rv) 1064. finally: 1065. _releaseLock() 1066. return rv 1067. 1068. def setLoggerClass(self, klass): 1069. """ 1070. Set the class to be used when instantiating a logger with this Manager. 1071. """ 1072. if klass != Logger: 1073. if not issubclass(klass, Logger): 1074. raise TypeError("logger not derived from logging.Logger: " 1075. + klass.__name__) 1076. self.loggerClass = klass 1077. 1078. def _fixupParents(self, alogger): 1079. """ 1080. Ensure that there are either loggers or placeholders all the way 1081. from the specified logger to the root of the logger hierarchy. 1082. """ 1083. name = alogger.name 1084. i = name.rfind(".") 1085. rv = None 1086. while (i > 0) and not rv: 1087. substr = name[:i] 1088. if substr not in self.loggerDict: 1089. self.loggerDict[substr] = PlaceHolder(alogger) 1090. else: 1091. obj = self.loggerDict[substr] 1092. if isinstance(obj, Logger): 1093. rv = obj 1094. else: 1095. assert isinstance(obj, PlaceHolder) 1096. obj.append(alogger) 1097. i = name.rfind(".", 0, i - 1) 1098. if not rv: 1099. rv = self.root 1100. alogger.parent = rv 1101. 1102. def _fixupChildren(self, ph, alogger): 1103. """ 1104. Ensure that children of the placeholder ph are connected to the 1105. specified logger. 1106. """ 1107. name = alogger.name 1108. namelen = len(name) 1109. for c in ph.loggerMap.keys(): 1110. #The if means ... if not c.parent.name.startswith(nm) 1111. if c.parent.name[:namelen] != name: 1112. alogger.parent = c.parent 1113. c.parent = alogger 1114. 1115. #--------------------------------------------------------------------------- 1116. # Logger classes and functions 1117. #--------------------------------------------------------------------------- 1118. 1119. class Logger(Filterer): 1120. """ 1121. Instances of the Logger class represent a single logging channel. A 1122. "logging channel" indicates an area of an application. Exactly how an 1123. "area" is defined is up to the application developer. Since an 1124. application can have any number of areas, logging channels are identified 1125. by a unique string. Application areas can be nested (e.g. an area 1126. of "input processing" might include sub-areas "read CSV files", "read 1127. XLS files" and "read Gnumeric files"). To cater for this natural nesting, 1128. channel names are organized into a namespace hierarchy where levels are 1129. separated by periods, much like the Java or Python package namespace. So 1130. in the instance given above, channel names might be "input" for the upper 1131. level, and "input.csv", "input.xls" and "input.gnu" for the sub-levels. 1132. There is no arbitrary limit to the depth of nesting. 1133. """ 1134. def __init__(self, name, level=NOTSET): 1135. """ 1136. Initialize the logger with a name and an optional level. 1137. """ 1138. Filterer.__init__(self) 1139. self.name = name 1140. self.level = _checkLevel(level) 1141. self.parent = None 1142. self.propagate = 1 1143. self.handlers = [] 1144. self.disabled = 0 1145. 1146. def setLevel(self, level): 1147. """ 1148. Set the logging level of this logger. 1149. """ 1150. self.level = _checkLevel(level) 1151. 1152. def debug(self, msg, *args, **kwargs): 1153. """ 1154. Log 'msg % args' with severity 'DEBUG'. 1155. 1156. To pass exception information, use the keyword argument exc_info with 1157. a true value, e.g. 1158. 1159. logger.debug("Houston, we have a %s", "thorny problem", exc_info=1) 1160. """ 1161. if self.isEnabledFor(DEBUG): 1162. self._log(DEBUG, msg, args, **kwargs) 1163. 1164. def info(self, msg, *args, **kwargs): 1165. """ 1166. Log 'msg % args' with severity 'INFO'. 1167. 1168. To pass exception information, use the keyword argument exc_info with 1169. a true value, e.g. 1170. 1171. logger.info("Houston, we have a %s", "interesting problem", exc_info=1) 1172. """ 1173. if self.isEnabledFor(INFO): 1174. self._log(INFO, msg, args, **kwargs) 1175. 1176. def warning(self, msg, *args, **kwargs): 1177. """ 1178. Log 'msg % args' with severity 'WARNING'. 1179. 1180. To pass exception information, use the keyword argument exc_info with 1181. a true value, e.g. 1182. 1183. logger.warning("Houston, we have a %s", "bit of a problem", exc_info=1) 1184. """ 1185. if self.isEnabledFor(WARNING): 1186. self._log(WARNING, msg, args, **kwargs) 1187. 1188. warn = warning 1189. 1190. def error(self, msg, *args, **kwargs): 1191. """ 1192. Log 'msg % args' with severity 'ERROR'. 1193. 1194. To pass exception information, use the keyword argument exc_info with 1195. a true value, e.g. 1196. 1197. logger.error("Houston, we have a %s", "major problem", exc_info=1) 1198. """ 1199. if self.isEnabledFor(ERROR): 1200. self._log(ERROR, msg, args, **kwargs) 1201. 1202. def exception(self, msg, *args, **kwargs): 1203. """ 1204. Convenience method for logging an ERROR with exception information. 1205. """ 1206. kwargs['exc_info'] = 1 1207. self.error(msg, *args, **kwargs) 1208. 1209. def critical(self, msg, *args, **kwargs): 1210. """ 1211. Log 'msg % args' with severity 'CRITICAL'. 1212. 1213. To pass exception information, use the keyword argument exc_info with 1214. a true value, e.g. 1215. 1216. logger.critical("Houston, we have a %s", "major disaster", exc_info=1) 1217. """ 1218. if self.isEnabledFor(CRITICAL): 1219. self._log(CRITICAL, msg, args, **kwargs) 1220. 1221. fatal = critical 1222. 1223. def log(self, level, msg, *args, **kwargs): 1224. """ 1225. Log 'msg % args' with the integer severity 'level'. 1226. 1227. To pass exception information, use the keyword argument exc_info with 1228. a true value, e.g. 1229. 1230. logger.log(level, "We have a %s", "mysterious problem", exc_info=1) 1231. """ 1232. if not isinstance(level, (int, long)): 1233. if raiseExceptions: 1234. raise TypeError("level must be an integer") 1235. else: 1236. return 1237. if self.isEnabledFor(level): 1238. self._log(level, msg, args, **kwargs) 1239. 1240. def findCaller(self): 1241. """ 1242. Find the stack frame of the caller so that we can note the source 1243. file name, line number and function name. 1244. """ 1245. f = currentframe() 1246. #On some versions of IronPython, currentframe() returns None if 1247. #IronPython isn't run with -X:Frames. 1248. if f is not None: 1249. f = f.f_back 1250. rv = "(unknown file)", 0, "(unknown function)" 1251. while hasattr(f, "f_code"): 1252. co = f.f_code 1253. filename = os.path.normcase(co.co_filename) 1254. if filename == _srcfile: 1255. f = f.f_back 1256. continue 1257. rv = (co.co_filename, f.f_lineno, co.co_name) 1258. break 1259. return rv 1260. 1261. def makeRecord(self, name, level, fn, lno, msg, args, exc_info, func=None, extra=None): 1262. """ 1263. A factory method which can be overridden in subclasses to create 1264. specialized LogRecords. 1265. """ 1266. rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func) 1267. if extra is not None: 1268. for key in extra: 1269. if (key in ["message", "asctime"]) or (key in rv.__dict__): 1270. raise KeyError("Attempt to overwrite %r in LogRecord" % key) 1271. rv.__dict__[key] = extra[key] 1272. return rv 1273. 1274. def _log(self, level, msg, args, exc_info=None, extra=None): 1275. """ 1276. Low-level logging routine which creates a LogRecord and then calls 1277. all the handlers of this logger to handle the record. 1278. """ 1279. if _srcfile: 1280. #IronPython doesn't track Python frames, so findCaller raises an 1281. #exception on some versions of IronPython. We trap it here so that 1282. #IronPython can use logging. 1283. try: 1284. fn, lno, func = self.findCaller() 1285. except ValueError: 1286. fn, lno, func = "(unknown file)", 0, "(unknown function)" 1287. else: 1288. fn, lno, func = "(unknown file)", 0, "(unknown function)" 1289. if exc_info: 1290. if not isinstance(exc_info, tuple): 1291. exc_info = sys.exc_info() 1292. record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra) 1293. self.handle(record) 1294. 1295. def handle(self, record): 1296. """ 1297. Call the handlers for the specified record. 1298. 1299. This method is used for unpickled records received from a socket, as 1300. well as those created locally. Logger-level filtering is applied. 1301. """ 1302. if (not self.disabled) and self.filter(record): 1303. self.callHandlers(record) 1304. 1305. def addHandler(self, hdlr): 1306. """ 1307. Add the specified handler to this logger. 1308. """ 1309. _acquireLock() 1310. try: 1311. if not (hdlr in self.handlers): 1312. self.handlers.append(hdlr) 1313. finally: 1314. _releaseLock() 1315. 1316. def removeHandler(self, hdlr): 1317. """ 1318. Remove the specified handler from this logger. 1319. """ 1320. _acquireLock() 1321. try: 1322. if hdlr in self.handlers: 1323. self.handlers.remove(hdlr) 1324. finally: 1325. _releaseLock() 1326. 1327. def callHandlers(self, record): 1328. """ 1329. Pass a record to all relevant handlers. 1330. 1331. Loop through all handlers for this logger and its parents in the 1332. logger hierarchy. If no handler was found, output a one-off error 1333. message to sys.stderr. Stop searching up the hierarchy whenever a 1334. logger with the "propagate" attribute set to zero is found - that 1335. will be the last logger whose handlers are called. 1336. """ 1337. c = self 1338. found = 0 1339. while c: 1340. for hdlr in c.handlers: 1341. found = found + 1 1342. if record.levelno >= hdlr.level: 1343. hdlr.handle(record) 1344. if not c.propagate: 1345. c = None #break out 1346. else: 1347. c = c.parent 1348. if (found == 0) and raiseExceptions and not self.manager.emittedNoHandlerWarning: 1349. sys.stderr.write("No handlers could be found for logger" 1350. " \"%s\"\n" % self.name) 1351. self.manager.emittedNoHandlerWarning = 1 1352. 1353. def getEffectiveLevel(self): 1354. """ 1355. Get the effective level for this logger. 1356. 1357. Loop through this logger and its parents in the logger hierarchy, 1358. looking for a non-zero logging level. Return the first one found. 1359. """ 1360. logger = self 1361. while logger: 1362. if logger.level: 1363. return logger.level 1364. logger = logger.parent 1365. return NOTSET 1366. 1367. def isEnabledFor(self, level): 1368. """ 1369. Is this logger enabled for level 'level'? 1370. """ 1371. if self.manager.disable >= level: 1372. return 0 1373. return level >= self.getEffectiveLevel() 1374. 1375. def getChild(self, suffix): 1376. """ 1377. Get a logger which is a descendant to this one. 1378. 1379. This is a convenience method, such that 1380. 1381. logging.getLogger('abc').getChild('def.ghi') 1382. 1383. is the same as 1384. 1385. logging.getLogger('abc.def.ghi') 1386. 1387. It's useful, for example, when the parent logger is named using 1388. __name__ rather than a literal string. 1389. """ 1390. if self.root is not self: 1391. suffix = '.'.join((self.name, suffix)) 1392. return self.manager.getLogger(suffix) 1393. 1394. class RootLogger(Logger): 1395. """ 1396. A root logger is not that different to any other logger, except that 1397. it must have a logging level and there is only one instance of it in 1398. the hierarchy. 1399. """ 1400. def __init__(self, level): 1401. """ 1402. Initialize the logger with the name "root". 1403. """ 1404. Logger.__init__(self, "root", level) 1405. 1406. _loggerClass = Logger 1407. 1408. class LoggerAdapter(object): 1409. """ 1410. An adapter for loggers which makes it easier to specify contextual 1411. information in logging output. 1412. """ 1413. 1414. def __init__(self, logger, extra): 1415. """ 1416. Initialize the adapter with a logger and a dict-like object which 1417. provides contextual information. This constructor signature allows 1418. easy stacking of LoggerAdapters, if so desired. 1419. 1420. You can effectively pass keyword arguments as shown in the 1421. following example: 1422. 1423. adapter = LoggerAdapter(someLogger, dict(p1=v1, p2="v2")) 1424. """ 1425. self.logger = logger 1426. self.extra = extra 1427. 1428. def process(self, msg, kwargs): 1429. """ 1430. Process the logging message and keyword arguments passed in to 1431. a logging call to insert contextual information. You can either 1432. manipulate the message itself, the keyword args or both. Return 1433. the message and kwargs modified (or not) to suit your needs. 1434. 1435. Normally, you'll only need to override this one method in a 1436. LoggerAdapter subclass for your specific needs. 1437. """ 1438. kwargs["extra"] = self.extra 1439. return msg, kwargs 1440. 1441. def debug(self, msg, *args, **kwargs): 1442. """ 1443. Delegate a debug call to the underlying logger, after adding 1444. contextual information from this adapter instance. 1445. """ 1446. msg, kwargs = self.process(msg, kwargs) 1447. self.logger.debug(msg, *args, **kwargs) 1448. 1449. def info(self, msg, *args, **kwargs): 1450. """ 1451. Delegate an info call to the underlying logger, after adding 1452. contextual information from this adapter instance. 1453. """ 1454. msg, kwargs = self.process(msg, kwargs) 1455. self.logger.info(msg, *args, **kwargs) 1456. 1457. def warning(self, msg, *args, **kwargs): 1458. """ 1459. Delegate a warning call to the underlying logger, after adding 1460. contextual information from this adapter instance. 1461. """ 1462. msg, kwargs = self.process(msg, kwargs) 1463. self.logger.warning(msg, *args, **kwargs) 1464. 1465. def error(self, msg, *args, **kwargs): 1466. """ 1467. Delegate an error call to the underlying logger, after adding 1468. contextual information from this adapter instance. 1469. """ 1470. msg, kwargs = self.process(msg, kwargs) 1471. self.logger.error(msg, *args, **kwargs) 1472. 1473. def exception(self, msg, *args, **kwargs): 1474. """ 1475. Delegate an exception call to the underlying logger, after adding 1476. contextual information from this adapter instance. 1477. """ 1478. msg, kwargs = self.process(msg, kwargs) 1479. kwargs["exc_info"] = 1 1480. self.logger.error(msg, *args, **kwargs) 1481. 1482. def critical(self, msg, *args, **kwargs): 1483. """ 1484. Delegate a critical call to the underlying logger, after adding 1485. contextual information from this adapter instance. 1486. """ 1487. msg, kwargs = self.process(msg, kwargs) 1488. self.logger.critical(msg, *args, **kwargs) 1489. 1490. def log(self, level, msg, *args, **kwargs): 1491. """ 1492. Delegate a log call to the underlying logger, after adding 1493. contextual information from this adapter instance. 1494. """ 1495. msg, kwargs = self.process(msg, kwargs) 1496. self.logger.log(level, msg, *args, **kwargs) 1497. 1498. def isEnabledFor(self, level): 1499. """ 1500. See if the underlying logger is enabled for the specified level. 1501. """ 1502. return self.logger.isEnabledFor(level) 1503. 1504. root = RootLogger(WARNING) 1505. Logger.root = root 1506. Logger.manager = Manager(Logger.root) 1507. 1508. #--------------------------------------------------------------------------- 1509. # Configuration classes and functions 1510. #--------------------------------------------------------------------------- 1511. 1512. BASIC_FORMAT = "%(levelname)s:%(name)s:%(message)s" 1513. 1514. def basicConfig(**kwargs): 1515. """ 1516. Do basic configuration for the logging system. 1517. 1518. This function does nothing if the root logger already has handlers 1519. configured. It is a convenience method intended for use by simple scripts 1520. to do one-shot configuration of the logging package. 1521. 1522. The default behaviour is to create a StreamHandler which writes to 1523. sys.stderr, set a formatter using the BASIC_FORMAT format string, and 1524. add the handler to the root logger. 1525. 1526. A number of optional keyword arguments may be specified, which can alter 1527. the default behaviour. 1528. 1529. filename Specifies that a FileHandler be created, using the specified 1530. filename, rather than a StreamHandler. 1531. filemode Specifies the mode to open the file, if filename is specified 1532. (if filemode is unspecified, it defaults to 'a'). 1533. format Use the specified format string for the handler. 1534. datefmt Use the specified date/time format. 1535. level Set the root logger level to the specified level. 1536. stream Use the specified stream to initialize the StreamHandler. Note 1537. that this argument is incompatible with 'filename' - if both 1538. are present, 'stream' is ignored. 1539. 1540. Note that you could specify a stream created using open(filename, mode) 1541. rather than passing the filename and mode in. However, it should be 1542. remembered that StreamHandler does not close its stream (since it may be 1543. using sys.stdout or sys.stderr), whereas FileHandler closes its stream 1544. when the handler is closed. 1545. """ 1546. # Add thread safety in case someone mistakenly calls 1547. # basicConfig() from multiple threads 1548. _acquireLock() 1549. try: 1550. if len(root.handlers) == 0: 1551. filename = kwargs.get("filename") 1552. if filename: 1553. mode = kwargs.get("filemode", 'a') 1554. hdlr = FileHandler(filename, mode) 1555. else: 1556. stream = kwargs.get("stream") 1557. hdlr = StreamHandler(stream) 1558. fs = kwargs.get("format", BASIC_FORMAT) 1559. dfs = kwargs.get("datefmt", None) 1560. fmt = Formatter(fs, dfs) 1561. hdlr.setFormatter(fmt) 1562. root.addHandler(hdlr) 1563. level = kwargs.get("level") 1564. if level is not None: 1565. root.setLevel(level) 1566. finally: 1567. _releaseLock() 1568. 1569. #--------------------------------------------------------------------------- 1570. # Utility functions at module level. 1571. # Basically delegate everything to the root logger. 1572. #--------------------------------------------------------------------------- 1573. 1574. def getLogger(name=None): 1575. """ 1576. Return a logger with the specified name, creating it if necessary. 1577. 1578. If no name is specified, return the root logger. 1579. """ 1580. if name: 1581. return Logger.manager.getLogger(name) 1582. else: 1583. return root 1584. 1585. #def getRootLogger(): 1586. # """ 1587. # Return the root logger. 1588. # 1589. # Note that getLogger('') now does the same thing, so this function is 1590. # deprecated and may disappear in the future. 1591. # """ 1592. # return root 1593. 1594. def critical(msg, *args, **kwargs): 1595. """ 1596. Log a message with severity 'CRITICAL' on the root logger. 1597. """ 1598. if len(root.handlers) == 0: 1599. basicConfig() 1600. root.critical(msg, *args, **kwargs) 1601. 1602. fatal = critical 1603. 1604. def error(msg, *args, **kwargs): 1605. """ 1606. Log a message with severity 'ERROR' on the root logger. 1607. """ 1608. if len(root.handlers) == 0: 1609. basicConfig() 1610. root.error(msg, *args, **kwargs) 1611. 1612. def exception(msg, *args, **kwargs): 1613. """ 1614. Log a message with severity 'ERROR' on the root logger, 1615. with exception information. 1616. """ 1617. kwargs['exc_info'] = 1 1618. error(msg, *args, **kwargs) 1619. 1620. def warning(msg, *args, **kwargs): 1621. """ 1622. Log a message with severity 'WARNING' on the root logger. 1623. """ 1624. if len(root.handlers) == 0: 1625. basicConfig() 1626. root.warning(msg, *args, **kwargs) 1627. 1628. warn = warning 1629. 1630. def info(msg, *args, **kwargs): 1631. """ 1632. Log a message with severity 'INFO' on the root logger. 1633. """ 1634. if len(root.handlers) == 0: 1635. basicConfig() 1636. root.info(msg, *args, **kwargs) 1637. 1638. def debug(msg, *args, **kwargs): 1639. """ 1640. Log a message with severity 'DEBUG' on the root logger. 1641. """ 1642. if len(root.handlers) == 0: 1643. basicConfig() 1644. root.debug(msg, *args, **kwargs) 1645. 1646. def log(level, msg, *args, **kwargs): 1647. """ 1648. Log 'msg % args' with the integer severity 'level' on the root logger. 1649. """ 1650. if len(root.handlers) == 0: 1651. basicConfig() 1652. root.log(level, msg, *args, **kwargs) 1653. 1654. def disable(level): 1655. """ 1656. Disable all logging calls of severity 'level' and below. 1657. """ 1658. root.manager.disable = level 1659. 1660. def shutdown(handlerList=_handlerList): 1661. """ 1662. Perform any cleanup actions in the logging system (e.g. flushing 1663. buffers). 1664. 1665. Should be called at application exit. 1666. """ 1667. for wr in reversed(handlerList[:]): 1668. #errors might occur, for example, if files are locked 1669. #we just ignore them if raiseExceptions is not set 1670. try: 1671. h = wr() 1672. if h: 1673. try: 1674. h.acquire() 1675. h.flush() 1676. h.close() 1677. except (IOError, ValueError): 1678. # Ignore errors which might be caused 1679. # because handlers have been closed but 1680. # references to them are still around at 1681. # application exit. 1682. pass 1683. finally: 1684. h.release() 1685. except: 1686. if raiseExceptions: 1687. raise 1688. #else, swallow 1689. 1690. #Let's try and shutdown automatically on application exit... 1691. import atexit 1692. atexit.register(shutdown) 1693. 1694. # Null handler 1695. 1696. class NullHandler(Handler): 1697. """ 1698. This handler does nothing. It's intended to be used to avoid the 1699. "No handlers could be found for logger XXX" one-off warning. This is 1700. important for library code, which may contain code to log events. If a user 1701. of the library does not configure logging, the one-off warning might be 1702. produced; to avoid this, the library developer simply needs to instantiate 1703. a NullHandler and add it to the top-level logger of the library module or 1704. package. 1705. """ 1706. def handle(self, record): 1707. pass 1708. 1709. def emit(self, record): 1710. pass 1711. 1712. def createLock(self): 1713. self.lock = None 1714. 1715. # Warnings integration 1716. 1717. _warnings_showwarning = None 1718. 1719. def _showwarning(message, category, filename, lineno, file=None, line=None): 1720. """ 1721. Implementation of showwarnings which redirects to logging, which will first 1722. check to see if the file parameter is None. If a file is specified, it will 1723. delegate to the original warnings implementation of showwarning. Otherwise, 1724. it will call warnings.formatwarning and will log the resulting string to a 1725. warnings logger named "py.warnings" with level logging.WARNING. 1726. """ 1727. if file is not None: 1728. if _warnings_showwarning is not None: 1729. _warnings_showwarning(message, category, filename, lineno, file, line) 1730. else: 1731. s = warnings.formatwarning(message, category, filename, lineno, line) 1732. logger = getLogger("py.warnings") 1733. if not logger.handlers: 1734. logger.addHandler(NullHandler()) 1735. logger.warning("%s", s) 1736. 1737. def captureWarnings(capture): 1738. """ 1739. If capture is true, redirect all warnings to the logging package. 1740. If capture is False, ensure that warnings are not redirected to logging 1741. but to their original destinations. 1742. """ 1743. global _warnings_showwarning 1744. if capture: 1745. if _warnings_showwarning is None: 1746. _warnings_showwarning = warnings.showwarning 1747. warnings.showwarning = _showwarning 1748. else: 1749. if _warnings_showwarning is not None: 1750. warnings.showwarning = _warnings_showwarning 1751. _warnings_showwarning = None