aliyun.log package

Submodules

aliyun.log.acl_config module

class aliyun.log.acl_config.AclConfig(aliyun_id, privilege_list=[])[source]
from_json(json_value)[source]
to_json()[source]

aliyun.log.acl_response module

class aliyun.log.acl_response.ListAclResponse(resp, header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the get_project_acl/get_logstore_acl API from log.

Parameters:header (dict) – GetAclResponse HTTP response header
get_acl_count()[source]
get_acl_list()[source]
log_print()[source]
class aliyun.log.acl_response.UpdateAclResponse(header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the update_projecta_acl/update_logstore_acl API from log.

Parameters:header (dict) – UpdateAclResponse HTTP response header
log_print()[source]

aliyun.log.cursor_response module

class aliyun.log.cursor_response.GetCursorResponse(resp, header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the get_cursor API from log.

Parameters:
  • header (dict) – ListShardResponse HTTP response header
  • resp (dict) – the HTTP response body
get_cursor()[source]
log_print()[source]

aliyun.log.gethistogramsrequest module

class aliyun.log.gethistogramsrequest.GetHistogramsRequest(project=None, logstore=None, fromTime=None, toTime=None, topic=None, query=None)[source]

Bases: aliyun.log.logrequest.LogRequest

The request used to get histograms of a query from log.

Parameters:
  • project (string) – project name
  • logstore (string) – logstore name
  • fromTime (int) – the begin time
  • toTime (int) – the end time
  • topic (string) – topic name of logs
  • query (string) – user defined query
get_from()[source]

Get begin time

Returns:int, begin time
get_logstore()[source]

Get logstore name

Returns:string, logstore name.
get_query()[source]

Get user defined query

Returns:string, user defined query
get_to()[source]

Get end time

Returns:int, end time
get_topic()[source]

Get topic name

Returns:string, topic name
set_from(fromTime)[source]

Set begin time

Parameters:fromTime (int) – begin time
set_logstore(logstore)[source]

Set logstore name

Parameters:logstore (string) – logstore name
set_query(query)[source]

Set user defined query

Parameters:query (string) – user defined query
set_to(toTime)[source]

Set end time

Parameters:toTime (int) – end time
set_topic(topic)[source]

Set topic name

Parameters:topic (string) – topic name

aliyun.log.gethistogramsresponse module

class aliyun.log.gethistogramsresponse.GetHistogramsResponse(resp, header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the GetHistograms API from log.

Parameters:
  • resp (dict) – GetHistogramsResponse HTTP response body
  • header (dict) – GetHistogramsResponse HTTP response header
get_histograms()[source]

Get histograms on the requested time range: [from, to)

Returns:Histogram list, histograms on the requested time range: [from, to)
get_total_count()[source]

Get total logs’ count that current query hits

Returns:int, total logs’ count that current query hits
is_completed()[source]

Check if the histogram is completed

Returns:bool, true if this histogram is completed
log_print()[source]

aliyun.log.getlogsrequest module

class aliyun.log.getlogsrequest.GetLogsRequest(project=None, logstore=None, fromTime=None, toTime=None, topic=None, query=None, line=None, offset=None, reverse=None)[source]

Bases: aliyun.log.logrequest.LogRequest

The request used to get logs by a query from log.

Parameters:
  • project (string) – project name
  • logstore (string) – logstore name
  • fromTime (int) – the begin time
  • toTime (int) – the end time
  • topic (string) – topic name of logs
  • query (string) – user defined query
  • line (int) – max line number of return logs
  • offset (int) – line offset of return logs
  • reverse (bool) – if reverse is set to true, the query will return the latest logs first
get_from()[source]

Get begin time

Returns:int, begin time
get_line()[source]

Get max line number of return logs

Returns:int, max line number of return logs
get_logstore()[source]

Get logstore name

Returns:string, logstore name
get_offset()[source]

Get line offset of return logs

Returns:int, line offset of return logs
get_query()[source]

Get user defined query

Returns:string, user defined query
get_reverse()[source]

Get request reverse flag

Returns:bool, reverse flag
get_to()[source]

Get end time

Returns:int, end time
get_topic()[source]

Get topic name

Returns:string, topic name
set_from(fromTime)[source]

Set begin time

Parameters:fromTime (int) – begin time
set_line(line)[source]

Set max line number of return logs

Parameters:line (int) – max line number of return logs
set_logstore(logstore)[source]

Set logstore name

Parameters:logstore (string) – logstore name
set_offset(offset)[source]

Set line offset of return logs

Parameters:offset (int) – line offset of return logs
set_query(query)[source]

Set user defined query

Parameters:query (string) – user defined query
set_reverse(reverse)[source]

Set request reverse flag

Parameters:reverse (bool) – reverse flag
set_to(toTime)[source]

Set end time

Parameters:toTime (int) – end time
set_topic(topic)[source]

Set topic name

Parameters:topic (string) – topic name

aliyun.log.getlogsresponse module

class aliyun.log.getlogsresponse.GetLogsResponse(resp, header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the GetLog API from log.

Parameters:
  • resp (dict) – GetLogsResponse HTTP response body
  • header (dict) – GetLogsResponse HTTP response header
get_count()[source]

Get log number from the response

Returns:int, log number
get_logs()[source]

Get all logs from the response

Returns:QueriedLog list, all log data
is_completed()[source]

Check if the get logs query is completed

Returns:bool, true if this logs query is completed
log_print()[source]

aliyun.log.histogram module

class aliyun.log.histogram.Histogram(fromTime, toTime, count, progress)[source]

The class used to present the result of log histogram status. For every log histogram, it contains : from/to time range, hit log count and query completed status.

Parameters:
  • fromTime (int) – the begin time
  • toTime (int) – the end time
  • count (int) – log count of histogram that query hits
  • progress (string) – histogram query status(Complete or InComplete)
get_count()[source]

Get log count of histogram that query hits

Returns:int, log count of histogram that query hits
get_from()[source]

Get begin time

Returns:int, begin time
get_to()[source]

Get end time

Returns:int, end time
is_completed()[source]

Check if the histogram is completed

Returns:bool, true if this histogram is completed
log_print()[source]

aliyun.log.index_config module

class aliyun.log.index_config.IndexConfig(ttl=1, line_config=None, key_config_list={}, all_keys_config=None)[source]

The index config of a logstore :type ttl : int :param ttl : the indexed data life cycle in days, only support 7, 30, 90

:type line_config : IndexLineConfig :param line_config : the index config of the whole log line

:type key_config_list : dict (string => IndexKeyConfig) :param key_config_list: the index key configs of the keys

:type all_keys_config : IndexKeyConfig :param all_keys_config : the key config of all keys, the new create logstore should never user this param, it only used to compatible with old config

from_json(json_value)[source]
to_json()[source]
class aliyun.log.index_config.IndexKeyConfig(token_list=[], case_sensitive=False)[source]
The index config of a special log key
type token_list:
 string list
param token_list:
 the token config list, e.g [”,” , ” ” , “

” , ” ” , ”;”]

type case_sensitive:
 bool
param case_sensitive:
 True if the value in the log keys is case sensitive, False other wise
from_json(json_value)[source]
to_json()[source]
class aliyun.log.index_config.IndexLineConfig(token_list=[], case_sensitive=False, include_keys=None, exclude_keys=None)[source]
The index config of the log line
type token_list:
 string list
param token_list:
 the token config list, e.g [”,” , ” ” , “

” , ” ” , ”;”]

type case_sensitive:
 bool
param case_sensitive:
 True if the value in the log keys is case sensitive, False other wise
type include_keys:
 string list
param include_kyes:
 only the keys in include_keys should to be indexed, only one of include_keys and exclude_keys could exist at the same time, if bothe include_keys and exclude_keys are empty, then the full line will be indexed
type exclude_keys:
 string list
param exclude_keys:
 the keys in the exclude_keys list will not be indexed, others keys will be indexed
from_json(json_value)[source]
to_json()[source]

aliyun.log.index_config_response module

class aliyun.log.index_config_response.CreateIndexResponse(header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the create_index API from log.

Parameters:header (dict) – CreateIndexResponse HTTP response header
log_print()[source]
class aliyun.log.index_config_response.DeleteIndexResponse(header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the delete_index API from log.

Parameters:header (dict) – DeleteIndexResponse HTTP response header
log_print()[source]
class aliyun.log.index_config_response.GetIndexResponse(resp, header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the get_index_config API from log.

Parameters:
  • header (dict) – GetIndexResponse HTTP response header
  • resp (dict) – the HTTP response body
get_index_config()[source]
log_print()[source]
class aliyun.log.index_config_response.UpdateIndexResponse(header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the update_index API from log.

Parameters:header (dict) – UpdateIndexResponse HTTP response header
log_print()[source]

aliyun.log.listlogstoresrequest module

class aliyun.log.listlogstoresrequest.ListLogstoresRequest(project=None)[source]

Bases: aliyun.log.logrequest.LogRequest

The request used to list log store from log.

Parameters:project (string) – project name

aliyun.log.listlogstoresresponse module

class aliyun.log.listlogstoresresponse.ListLogstoresResponse(resp, header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the ListLogstores API from log.

Parameters:
  • resp (dict) – ListLogstoresResponse HTTP response body
  • header (dict) – ListLogstoresResponse HTTP response header
get_count()[source]

Get total count of logstores from the response

Returns:int, the number of total logstores from the response
get_logstores()[source]

Get all the logstores from the response

Returns:list, all logstores
log_print()[source]

aliyun.log.listtopicsrequest module

class aliyun.log.listtopicsrequest.ListTopicsRequest(project=None, logstore=None, token=None, line=None)[source]

Bases: aliyun.log.logrequest.LogRequest

The request used to get topics of a query from log.

Parameters:
  • project (string) – project name
  • logstore (string) – logstore name
  • token (string) – the start token to list topics
  • line (int) – max topic counts to return
get_line()[source]

Get max topic counts to return

Returns:int, max topic counts to return
get_logstore()[source]

Get logstore name

Returns:string, logstore name.
get_token()[source]

Get start token to list topics

Returns:string, start token to list topics
set_line(line)[source]

Set max topic counts to return

Parameters:line (int) – max topic counts to return
set_logstore(logstore)[source]

Set logstore name

Parameters:logstore (string) – logstore name
set_token(token)[source]

Set start token to list topics

Parameters:token (string) – start token to list topics

aliyun.log.listtopicsresponse module

class aliyun.log.listtopicsresponse.ListTopicsResponse(resp, header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the ListTopic API from log.

Parameters:
  • resp (dict) – ListTopicsResponse HTTP response body
  • header (dict) – ListTopicsResponse HTTP response header
get_count()[source]

Get the number of all the topics from the response

Returns:int, the number of all the topics from the response
get_next_token()[source]

Return the next token from the response. If there is no more topic to list, it will return None

Returns:string, next token used to list more topics
get_topics()[source]

Get all the topics from the response

Returns:list, topic list
log_print()[source]

aliyun.log.log_logs.pb2 module

aliyun.log.log_logs_pb2 module

class aliyun.log.log_logs_pb2.Log(**kwargs)[source]

Bases: google.protobuf.message.Message

ByteSize()
CONTENTS_FIELD_NUMBER = 2
Clear()
ClearField(field_name)
class Content(**kwargs)[source]

Bases: google.protobuf.message.Message

ByteSize()
Clear()
ClearField(field_name)
DESCRIPTOR = <google.protobuf.descriptor.Descriptor object at 0x0217FDB0>
FindInitializationErrors()

Finds required fields which are not initialized.

Returns:
A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. “foo.bar[5].baz”.
static FromString(s)
HasField(field_name)
IsInitialized(errors=None)

Checks if all required fields of a message are set.

Args:
errors: A list which, if provided, will be populated with the field
paths of all missing required fields.
Returns:
True iff the specified message has all required fields set.
KEY_FIELD_NUMBER = 1
Key

Magic attribute generated for “Key” proto field.

ListFields()
MergeFrom(msg)
MergeFromString(serialized)
static RegisterExtension(extension_handle)
SerializePartialToString()
SerializeToString()
SetInParent()

Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.

VALUE_FIELD_NUMBER = 2
Value

Magic attribute generated for “Value” proto field.

WhichOneof(oneof_name)

Returns the name of the currently set field inside a oneof, or None.

Log.Contents

Magic attribute generated for “Contents” proto field.

Log.DESCRIPTOR = <google.protobuf.descriptor.Descriptor object at 0x0217FE10>
Log.FindInitializationErrors()

Finds required fields which are not initialized.

Returns:
A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. “foo.bar[5].baz”.
static Log.FromString(s)
Log.HasField(field_name)
Log.IsInitialized(errors=None)

Checks if all required fields of a message are set.

Args:
errors: A list which, if provided, will be populated with the field
paths of all missing required fields.
Returns:
True iff the specified message has all required fields set.
Log.ListFields()
Log.MergeFrom(msg)
Log.MergeFromString(serialized)
static Log.RegisterExtension(extension_handle)
Log.SerializePartialToString()
Log.SerializeToString()
Log.SetInParent()

Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.

Log.TIME_FIELD_NUMBER = 1
Log.Time

Magic attribute generated for “Time” proto field.

Log.WhichOneof(oneof_name)

Returns the name of the currently set field inside a oneof, or None.

class aliyun.log.log_logs_pb2.LogGroup(**kwargs)[source]

Bases: google.protobuf.message.Message

ByteSize()
Clear()
ClearField(field_name)
DESCRIPTOR = <google.protobuf.descriptor.Descriptor object at 0x0217FEB0>
FindInitializationErrors()

Finds required fields which are not initialized.

Returns:
A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. “foo.bar[5].baz”.
static FromString(s)
HasField(field_name)
IsInitialized(errors=None)

Checks if all required fields of a message are set.

Args:
errors: A list which, if provided, will be populated with the field
paths of all missing required fields.
Returns:
True iff the specified message has all required fields set.
LOGS_FIELD_NUMBER = 1
ListFields()
Logs

Magic attribute generated for “Logs” proto field.

MergeFrom(msg)
MergeFromString(serialized)
RESERVED_FIELD_NUMBER = 2
static RegisterExtension(extension_handle)
Reserved

Magic attribute generated for “Reserved” proto field.

SOURCE_FIELD_NUMBER = 4
SerializePartialToString()
SerializeToString()
SetInParent()

Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.

Source

Magic attribute generated for “Source” proto field.

TOPIC_FIELD_NUMBER = 3
Topic

Magic attribute generated for “Topic” proto field.

WhichOneof(oneof_name)

Returns the name of the currently set field inside a oneof, or None.

class aliyun.log.log_logs_pb2.LogGroupList(**kwargs)[source]

Bases: google.protobuf.message.Message

ByteSize()
Clear()
ClearField(field_name)
DESCRIPTOR = <google.protobuf.descriptor.Descriptor object at 0x0217FEF0>
FindInitializationErrors()

Finds required fields which are not initialized.

Returns:
A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. “foo.bar[5].baz”.
static FromString(s)
HasField(field_name)
IsInitialized(errors=None)

Checks if all required fields of a message are set.

Args:
errors: A list which, if provided, will be populated with the field
paths of all missing required fields.
Returns:
True iff the specified message has all required fields set.
LOGGROUPS_FIELD_NUMBER = 1
ListFields()
LogGroups

Magic attribute generated for “LogGroups” proto field.

MergeFrom(msg)
MergeFromString(serialized)
static RegisterExtension(extension_handle)
SerializePartialToString()
SerializeToString()
SetInParent()

Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.

WhichOneof(oneof_name)

Returns the name of the currently set field inside a oneof, or None.

aliyun.log.logclient module

class aliyun.log.logclient.LogClient(endpoint, accessKeyId, accessKey)[source]

Bases: object

Construct the LogClient with endpoint, accessKeyId, accessKey.

Parameters:
  • endpoint (string) – log service host name, for example, http://ch-hangzhou.sls.aliyuncs.com
  • accessKeyId (string) – aliyun accessKeyId
  • accessKey (string) – aliyun accessKey
Version = '0.6.0'
apply_config_to_machine_group(project_name, config_name, group_name)[source]

apply a logtail config to a machine group Unsuccessful opertaion will cause an LogException.

Parameters:
  • project_name (string) – the Project name
  • config_name (string) – the logtail config name to apply
  • group_name (string) – the machine group name
Returns:

ApplyConfigToMachineGroupResponse

Raise:

LogException

create_index(project_name, logstore_name, index_detail)[source]

create index for a logstore Unsuccessful opertaion will cause an LogException.

Parameters:
  • project_name (string) – the Project name
  • logstore_name (string) – the logstore name
  • index_detail (index_config.IndexConfig) – the index config detail used to create index
Returns:

CreateIndexResponse

Raise:

LogException

create_logstore(project_name, logstore_name, ttl, shard_count)[source]

create log store Unsuccessful opertaion will cause an LogException. :type project_name: string :param project_name: the Project name

Parameters:
  • logstore_name (string) – the logstore name
  • ttl (int) – the life cycle of log in the logstore in days
  • shard_count (int) – the shard count of the logstore to create
Returns:

CreateLogStoreResponse

Raise:

LogException

create_logtail_config(project_name, config_detail)[source]

create logtail config in a project Unsuccessful opertaion will cause an LogException.

Parameters:
Returns:

CreateLogtailConfigResponse

Raise:

LogException

create_machine_group(project_name, group_detail)[source]

create machine group in a project Unsuccessful opertaion will cause an LogException.

Parameters:
Returns:

CreateMachineGroupResponse

Raise:

LogException

delete_index(project_name, logstore_name)[source]

delete index of a logstore Unsuccessful opertaion will cause an LogException.

Parameters:
  • project_name (string) – the Project name
  • logstore_name (string) – the logstore name
Returns:

DeleteIndexResponse

Raise:

LogException

delete_logstore(project_name, logstore_name)[source]

delete log store Unsuccessful opertaion will cause an LogException.

Parameters:
  • project_name (string) – the Project name
  • logstore_name (string) – the logstore name
Returns:

DeleteLogStoreResponse

Raise:

LogException

delete_logtail_config(project_name, config_name)[source]

delete logtail config in a project Unsuccessful opertaion will cause an LogException.

Parameters:
  • project_name (string) – the Project name
  • config_name (string) – the logtail config name
Returns:

DeleteLogtailConfigResponse

Raise:

LogException

delete_machine_group(project_name, group_name)[source]

delete machine group in a project Unsuccessful opertaion will cause an LogException.

Parameters:
  • project_name (string) – the Project name
  • group_name (string) – the group name
Returns:

DeleteMachineGroupResponse

Raise:

LogException

get_begin_cursor(project_name, logstore_name, shard_id)[source]

Get begin cursor from log service for batch pull logs Unsuccessful opertaion will cause an LogException. :type project_name: string :param project_name: the Project name

Parameters:
  • logstore_name (string) – the logstore name
  • shard_id (int) – the shard id
Returns:

GetLogsResponse

Raise:

LogException

get_config_applied_machine_groups(project_name, config_name)[source]

get machine group names where the logtail config applies to Unsuccessful opertaion will cause an LogException.

Parameters:
  • project_name (string) – the Project name
  • config_name (string) – the logtail config name used to apply
Returns:

GetConfigAppliedMachineGroupsResponse

Raise:

LogException

get_cursor(project_name, logstore_name, shard_id, start_time)[source]

Get cursor from log service for batch pull logs Unsuccessful opertaion will cause an LogException. :type project_name: string :param project_name: the Project name

Parameters:
  • logstore_name (string) – the logstore name
  • shard_id (int) – the shard id
  • start_time (int) – the start time of cursor, e.g 1441093445
Returns:

GetLogsResponse

Raise:

LogException

get_end_cursor(project_name, logstore_name, shard_id)[source]

Get end cursor from log service for batch pull logs Unsuccessful opertaion will cause an LogException. :type project_name: string :param project_name: the Project name

Parameters:
  • logstore_name (string) – the logstore name
  • shard_id (int) – the shard id
Returns:

GetLogsResponse

Raise:

LogException

get_histograms(request)[source]

Get histograms of requested query from log service. Unsuccessful opertaion will cause an LogException.

Parameters:request (GetHistogramsRequest) – the GetHistograms request parameters class.
Returns:GetHistogramsResponse
Raise:LogException
get_index_config(project_name, logstore_name)[source]

get index config detail of a logstore Unsuccessful opertaion will cause an LogException.

Parameters:
  • project_name (string) – the Project name
  • logstore_name (string) – the logstore name
Returns:

GetIndexResponse

Raise:

LogException

get_logs(request)[source]

Get logs from log service. Unsuccessful opertaion will cause an LogException.

Parameters:request (GetLogsRequest) – the GetLogs request parameters class.
Returns:GetLogsResponse
Raise:LogException
get_logstore(project_name, logstore_name)[source]

get the logstore meta info Unsuccessful opertaion will cause an LogException.

Parameters:
  • project_name (string) – the Project name
  • logstore_name (string) – the logstore name
Returns:

GetLogStoreResponse

Raise:

LogException

get_logtail_config(project_name, config_name)[source]

get logtail config in a project Unsuccessful opertaion will cause an LogException.

Parameters:
  • project_name (string) – the Project name
  • config_name (string) – the logtail config name
Returns:

GetLogtailConfigResponse

Raise:

LogException

get_machine_group(project_name, group_name)[source]

get machine group in a project Unsuccessful opertaion will cause an LogException.

Parameters:
  • project_name (string) – the Project name
  • group_name (string) – the group name to get
Returns:

GetMachineGroupResponse

Raise:

LogException

get_machine_group_applied_configs(project_name, group_name)[source]

get the logtail config names applied in a machine group Unsuccessful opertaion will cause an LogException.

Parameters:
  • project_name (string) – the Project name
  • group_name (string) – the group name list
Returns:

GetMachineGroupAppliedConfigResponse

Raise:

LogException

get_unicode(key)[source]
list_logstore(project_name, logstore_name_pattern=None, offset=0, size=100)[source]

list the logstore in a project Unsuccessful opertaion will cause an LogException.

Parameters:
  • project_name (string) – the Project name
  • logstore_name_pattern (string) – the sub name logstore, used for the server to return logstore names contain this sub name
  • offset (int) – the offset of all the matched names
  • size (int) – the max return names count
Returns:

ListLogStoreResponse

Raise:

LogException

list_logstores(request)[source]

List all logstores of requested project. Unsuccessful opertaion will cause an LogException.

Parameters:request (ListLogstoresRequest) – the ListLogstores request parameters class.
Returns:ListLogStoresResponse
Raise:LogException
list_logtail_config(project_name, offset=0, size=100)[source]

list logtail config name in a project Unsuccessful opertaion will cause an LogException.

Parameters:
  • project_name (string) – the Project name
  • offset (int) – the offset of all config names
  • size (int) – the max return names count
Returns:

ListLogtailConfigResponse

Raise:

LogException

list_machine_group(project_name, offset=0, size=100)[source]

list machine group names in a project Unsuccessful opertaion will cause an LogException.

Parameters:
  • project_name (string) – the Project name
  • offset (int) – the offset of all group name
  • size (int) – the max return names count
Returns:

ListMachineGroupResponse

Raise:

LogException

list_machines(project_name, group_name, offset=0, size=100)[source]

list machines in a machine group Unsuccessful opertaion will cause an LogException.

Parameters:
  • project_name (string) – the Project name
  • group_name (string) – the group name to list
  • offset (int) – the offset of all group name
  • size (int) – the max return names count
Returns:

ListMachinesResponse

Raise:

LogException

list_shards(project_name, logstore_name)[source]

list the shard meta of a logstore Unsuccessful opertaion will cause an LogException.

Parameters:
  • project_name (string) – the Project name
  • logstore_name (string) – the logstore name
Returns:

ListShardResponse

Raise:

LogException

list_topics(request)[source]

List all topics in a logstore. Unsuccessful opertaion will cause an LogException.

Parameters:request (ListTopicsRequest) – the ListTopics request parameters class.
Returns:ListTopicsResponse
Raise:LogException
pull_logs(project_name, logstore_name, shard_id, cursor, count=1000)[source]

batch pull log data from log service Unsuccessful opertaion will cause an LogException. :type project_name: string :param project_name: the Project name

Parameters:
  • logstore_name (string) – the logstore name
  • shard_id (int) – the shard id
  • cursor (string) – the start to cursor to get data
  • count (int) – the required pull log package count, default 1000 packages
Returns:

PullLogResponse

Raise:

LogException

put_logs(request)[source]

Put logs to log service. Unsuccessful opertaion will cause an LogException.

Parameters:request (PutLogsRequest) – the PutLogs request parameters class
Returns:PutLogsResponse
Raise:LogException
remove_config_to_machine_group(project_name, config_name, group_name)[source]

remove a logtail config to a machine group Unsuccessful opertaion will cause an LogException.

Parameters:
  • project_name (string) – the Project name
  • config_name (string) – the logtail config name to apply
  • group_name (string) – the machine group name
Returns:

RemoveConfigToMachineGroupResponse

Raise:

LogException

update_index(project_name, logstore_name, index_detail)[source]

update index for a logstore Unsuccessful opertaion will cause an LogException.

Parameters:
  • project_name (string) – the Project name
  • logstore_name (string) – the logstore name
  • index_detail (index_config.IndexConfig) – the index config detail used to update index
Returns:

UpdateIndexResponse

Raise:

LogException

update_logstore(project_name, logstore_name, ttl, shard_count)[source]

update the logstore meta info Unsuccessful opertaion will cause an LogException.

Parameters:
  • project_name (string) – the Project name
  • logstore_name (string) – the logstore name
  • ttl (int) – the life cycle of log in the logstore in days
  • shard_count (int) – the shard count of the logstore to create
Returns:

UpdateLogStoreResponse

Raise:

LogException

update_logtail_config(project_name, config_detail)[source]

update logtail config in a project Unsuccessful opertaion will cause an LogException.

Parameters:
Returns:

UpdateLogtailConfigResponse

Raise:

LogException

update_machine_group(project_name, group_detail)[source]

update machine group in a project Unsuccessful opertaion will cause an LogException.

Parameters:
Returns:

UpdateMachineGroupResponse

Raise:

LogException

aliyun.log.logclient.USER_AGENT = 'log-python-sdk-v-0.6.0'

LogClient class is the main class in the SDK. It can be used to communicate with log service server to put/get data.

Author:log_dev

aliyun.log.logexception module

exception aliyun.log.logexception.LogException(errorCode, errorMessage, requestId='')[source]

Bases: exceptions.Exception

The Exception of the log request & response.

Parameters:
  • errorCode (string) – log service error code
  • errorMessage (string) – detailed information for the exception
  • requestId (string) – the request id of the response, ‘’ is set if client error
get_error_code()[source]

return error code of exception

Returns:string, error code of exception.
get_error_message()[source]

return error message of exception

Returns:string, error message of exception.
get_request_id()[source]

return request id of exception. if client exception, request id is empty string

Returns:string, request id of exception.

aliyun.log.logitem module

class aliyun.log.logitem.LogItem(timestamp=None, contents=None)[source]

LogItem used to present a log, it contains log time and multiple key/value pairs to present the log contents.

Parameters:
  • timestamp (int) – time of the log item, the default time is the now time.
  • contents (tuple(key-value) list) – the data of the log item, including many (key,value) pairs.
get_contents()[source]

Get log contents

Returns:tuple(key-value) list, log contents.
get_time()[source]

Get log time

Returns:int, log time
log_print()[source]
push_back(key, value)[source]

Append a key/value pair as a log content to the log

Parameters:
  • key (string) – log content key
  • value (string) – log content value
set_contents(contents)[source]

Set log contents

Parameters:contents (tuple(key-value) list) – log contents (key-value pair list)
set_time(timestamp)[source]

Set log time

Parameters:timestamp (int) – log time

aliyun.log.logrequest module

class aliyun.log.logrequest.LogRequest(project)[source]

The base request of all log request.

Parameters:project (string) – project name
get_project()[source]

Get project name

Returns:string, project name.
set_project(project)[source]

Set project name

Parameters:project (string) – project name

aliyun.log.logresponse module

class aliyun.log.logresponse.LogResponse(headers)[source]

The base response class of all log response.

Parameters:headers (dict) – HTTP response header
get_all_headers()[source]

Get all http header of the response

Returns:dict, response header
get_header(key)[source]

Get specified http header of the response, ‘’ will be return if not set.

Parameters:key (string) – the key to get header
Returns:string, response header
get_request_id()[source]

Get the request id of the response. ‘’ will be return if not set.

Returns:string, request id
log_print()[source]

aliyun.log.logstore_config_response module

class aliyun.log.logstore_config_response.CreateLogStoreResponse(header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the create_logstore API from log.

Parameters:header (dict) – CreateLogStoreResponse HTTP response header
log_print()[source]
class aliyun.log.logstore_config_response.DeleteLogStoreResponse(header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the delete_logstore API from log.

Parameters:header (dict) – DeleteLogStoreResponse HTTP response header
log_print()[source]
class aliyun.log.logstore_config_response.GetLogStoreResponse(resp, header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the get_logstore API from log.

Parameters:
  • header (dict) – GetLogStoreResponse HTTP response header
  • resp (dict) – the HTTP response body
get_shard_count()[source]
get_ttl()[source]
log_print()[source]
class aliyun.log.logstore_config_response.ListLogStoreResponse(resp, header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the list_logstore API from log.

Parameters:
  • header (dict) – ListLogStoreResponse HTTP response header
  • resp (dict) – the HTTP response body
get_logstores()[source]
get_logstores_count()[source]
log_print()[source]
class aliyun.log.logstore_config_response.UpdateLogStoreResponse(header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the update_logstore API from log.

Parameters:header (dict) – UpdateLogStoreResponse HTTP response header
log_print()[source]

aliyun.log.logtail_config_detail module

class aliyun.log.logtail_config_detail.CommonRegLogConfigDetail(config_name, logstore_name, endpoint, log_path, file_pattern, time_format, log_begin_regex, log_parse_regex, reg_keys, topic_format='none', filter_keys=[], filter_keys_reg=[])[source]

Bases: aliyun.log.logtail_config_detail.LogtailConfigDetail

The logtail config for common_reg_log :type config_name : string :param config_name : the config name

Parameters:logstore_name (string) – the logstore name for the config

:type endpoint : string :param endpoint : log data endpoint, it should base on the region of this project

:type log_path : string :param log_path : the log file dir path

:param file_pattern : the log file name pattern, e.g *.LOG , access.log

:type time_format : string :parma time_format : the time format of the logs, e.g. “%Y-%m-%d %M:%H:%S”

:type log_begin_regex : string :param log_begin_regex : the regular express to match the first line of a log

:param log_parse_regex : the regular express to match a log, e.g (d+-d+d+ d+:d+:d+) (S+) (.*)

:type reg_keys : string list :param reg_keys : the key for every captured value in log_parse_reg, e.g [“time”, “level”, “message”]

:type topic_format : string :param topic_format: “none” or “group_topic”

:param filter_keys : string list :param filter_keys : the keys used to filter logs, e.g [“key_1”, “key_2”]

:param filter_keys_reg : string list :param filter_keys_reg : the regex for filter_keys to filter the log, filter_keys_reg[i] is for filter_keys[i]. The size of filter_keys_reg and filter_keys should be same. If a log is matched only if the size of filter_keys is 0, or all the value of the related keys in filter_keys, match the regex set in filter_keys_reg

to_json()[source]
class aliyun.log.logtail_config_detail.LogtailConfigDetail(config_name, logstore_name, endpoint, log_path, file_pattern, log_begin_regex, topic_format, filter_keys, filter_keys_reg)[source]

The common parts of logtail config :type config_name : string :param config_name : the config name

Parameters:logstore_name (string) – the logstore name for the config

:type endpoint : string :param endpoint : log data endpoint, it should base on the region of this project

:type log_path : string :param log_path : the log file dir path

:param file_pattern : the log file name pattern, e.g *.LOG , access.log

:type log_begin_regex : string :param log_begin_regex : the regular express to match the first line of a log

:type topic_format : string :param topic_format: “none” or “group_topic”

:param filter_keys : string list :param filter_keys : the keys used to filter logs, e.g [“key_1”, “key_2”]

:param filter_keys_reg : string list :param filter_keys_reg : the regex for filter_keys to filter the log, filter_keys_reg[i] is for filter_keys[i]. The size of filter_keys_reg and filter_keys should be same.

If a log is matched only if the size of filter_keys is 0, or all the value of the related keys in filter_keys, match the regex set in filter_keys_reg
set_create_time(create_time)[source]
set_last_modify_time(last_modify_time)[source]
class aliyun.log.logtail_config_detail.LogtailConfigHelper[source]
static generate_common_reg_log_config(json_value)[source]
static generate_logtail_config(json_value)[source]

aliyun.log.logtail_config_response module

class aliyun.log.logtail_config_response.CreateLogtailConfigResponse(header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the create_logtail_config API from log.

Parameters:header (dict) – CreateLogtailConfigResponse HTTP response header
log_print()[source]
class aliyun.log.logtail_config_response.DeleteLogtailConfigResponse(header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the delete_logtail_config API from log.

Parameters:header (dict) – DeleteLogtailConfigResponse HTTP response header
log_print()[source]
class aliyun.log.logtail_config_response.GetLogtailConfigResponse(resp, header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the get_logtail_config API from log.

Parameters:
  • header (dict) – GetLogtailConfigResponse HTTP response header
  • resp (dict) – the HTTP response body
log_print()[source]
class aliyun.log.logtail_config_response.ListLogtailConfigResponse(resp, header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the list_logtail_config API from log.

Parameters:
  • header (dict) – ListLogtailConfigResponse HTTP response header
  • resp (dict) – the HTTP response body
get_configs()[source]
get_configs_count()[source]
log_print()[source]
class aliyun.log.logtail_config_response.UpdateLogtailConfigResponse(header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the update_logtail_config API from log.

Parameters:header (dict) – UpdateLogtailConfigResponse HTTP response header
log_print()[source]

aliyun.log.machine_group_detail module

class aliyun.log.machine_group_detail.MachineGroupDetail(group_name, machine_type, machine_list, group_type='', group_attribute={})[source]

The machine group detail info :type group_name: string :param group_name: group name

:type machine_type : string :param machine_type : “ip” or “userdefined”

:type machine_list : string list :param machine_list: the list of machine ips or machine userdefined, e.g [“127.0.0.1”, “127.0.0.2”]

:type gruop_type : string “” or “Armory” :param group_type : the machine group type

:type group_attribute : dict :param group_attribute : the attributes in group, it contains two optional key :

  1. “externalName” : only used if the group_type is “Armory”, its the Armory name
  2. “groupTopic” : group topic value
from_json(json_value)[source]
to_json()[source]
class aliyun.log.machine_group_detail.MachineStatus(ip, machine_unique_id, user_defined_id, heartbeat_time)[source]

the machine status :type ip: string :param ip: the machine ip

Parameters:
  • machine_unique_id (string) – the machine unique id
  • user_defined_id (string) – the user defined id

:param heartbeat_time : last updated heartbeat_time

aliyun.log.machinegroup_response module

class aliyun.log.machinegroup_response.ApplyConfigToMachineGroupResponse(header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the apply_config_to_machine_group API from log.

Parameters:header (dict) – ApplyConfigToMachineGroupResponse HTTP response header
log_print()[source]
class aliyun.log.machinegroup_response.CreateMachineGroupResponse(header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the create_machine_group API from log.

Parameters:header (dict) – CreateMachineGroupResponse HTTP response header
log_print()[source]
class aliyun.log.machinegroup_response.DeleteMachineGroupResponse(header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the delete_machine_group API from log.

Parameters:header (dict) – DeleteMachineGroupResponse HTTP response header
log_print()[source]
class aliyun.log.machinegroup_response.GetConfigAppliedMachineGroupsResponse(resp, header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the get_config_applied_machine_group API from log.

Parameters:
  • header (dict) – GetConfigAppliedMachineGroupsResponse HTTP response header
  • resp (dict) – the HTTP response body
get_machine_group_count()[source]
get_machine_groups()[source]
log_print()[source]
class aliyun.log.machinegroup_response.GetMachineGroupAppliedConfigResponse(resp, header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the get_machine_group_applied_config API from log.

Parameters:
  • header (dict) – GetMachineGroupAppliedConfigResponse HTTP response header
  • resp (dict) – the HTTP response body
get_config_count()[source]
get_configs()[source]
log_print()[source]
class aliyun.log.machinegroup_response.GetMachineGroupResponse(resp, header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the get_machine_group API from log.

Parameters:
  • header (dict) – GetMachineGroupResponse HTTP response header
  • resp (dict) – the HTTP response body
get_machine_group()[source]
log_print()[source]
class aliyun.log.machinegroup_response.ListMachineGroupResponse(resp, header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the list_machine_group API from log.

Parameters:
  • header (dict) – ListMachineGroupResponse HTTP response header
  • resp (dict) – the HTTP response body
get_machine_group()[source]
get_machine_group_count()[source]
get_machine_group_total()[source]
log_print()[source]
class aliyun.log.machinegroup_response.ListMachinesResponse(resp, header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the list_machines API from log.

Parameters:
  • header (dict) – ListMachinesResponse HTTP response header
  • resp (dict) – the HTTP response body
get_machine_count()[source]
get_machine_total()[source]
get_machines()[source]
log_print()[source]
class aliyun.log.machinegroup_response.RemoveConfigToMachineGroupResponse(header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the remove_config_to_machine_group API from log.

Parameters:header (dict) – RemoveConfigToMachineGroupResponse HTTP response header
log_print()[source]
class aliyun.log.machinegroup_response.UpdateMachineGroupResponse(header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the update_machine_group API from log.

Parameters:header (dict) – UpdateMachineGroupResponse HTTP response header
log_print()[source]

aliyun.log.pulllog_response module

class aliyun.log.pulllog_response.PullLogResponse(resp, header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the pull_logs API from log.

Parameters:
  • header (dict) – PullLogResponse HTTP response header
  • resp (dict) – the HTTP response body
get_log_count()[source]
get_loggroup(index)[source]
get_loggroup_count()[source]
get_loggroup_json_list()[source]
get_loggroup_list()[source]
get_next_cursor()[source]
log_print()[source]

aliyun.log.putlogsrequest module

class aliyun.log.putlogsrequest.PutLogsRequest(project=None, logstore=None, topic=None, source=None, logitems=None)[source]

Bases: aliyun.log.logrequest.LogRequest

The request used to send data to log.

Parameters:
  • project (string) – project name
  • logstore (string) – logstore name
  • topic (string) – topic name
  • source (string) – source of the logs
  • logitems (list<LogItem>) – log data
get_log_items()[source]

Get all the log data

Returns:LogItem list, log data
get_logstore()[source]

Get logstore name

Returns:string, logstore name
get_source()[source]

Get log source

Returns:string, log source
get_topic()[source]

Get topic name

Returns:string, topic name
set_log_items(logitems)[source]

Set the log data

Parameters:logitems (LogItem list) – log data
set_logstore(logstore)[source]

Set logstore name

Parameters:logstore (string) – logstore name
set_source(source)[source]

Set log source

Parameters:source (string) – log source
set_topic(topic)[source]

Set topic name

Parameters:topic (string) – topic name

aliyun.log.putlogsresponse module

class aliyun.log.putlogsresponse.PutLogsResponse(header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the PutLogs API from log.

Parameters:header (dict) – PutLogsResponse HTTP response header
log_print()[source]

aliyun.log.queriedlog module

class aliyun.log.queriedlog.QueriedLog(timestamp, source, contents)[source]

The QueriedLog is a log of the GetLogsResponse which obtained from the log.

Parameters:
  • timestamp (int) – log timestamp
  • source (string) – log source
  • contents (dict) – log contents, content many key/value pair
get_contents()[source]

Get log contents

Returns:dict, log contents
get_source()[source]

Get log source

Returns:string, log source
get_time()[source]

Get log time

Returns:int, log time
log_print()[source]

aliyun.log.shard_response module

class aliyun.log.shard_response.ListShardResponse(resp, header)[source]

Bases: aliyun.log.logresponse.LogResponse

The response of the list_shard API from log.

Parameters:
  • header (dict) – ListShardResponse HTTP response header
  • resp (dict) – the HTTP response body
get_shards_info()[source]
log_print()[source]

aliyun.log.util module

class aliyun.log.util.Util[source]
static cal_md5(content)[source]
static canonicalized_log_headers(headers)[source]
static canonicalized_resource(resource, params)[source]
static compress_data(data)[source]
static convert_unicode_to_str(data)[source]
static get_host_ip(logHost)[source]

If it is not match your local ip, you should fill the PutLogsRequest parameter source by yourself.

static get_json_value(json_map, key, default_value=None)[source]
static get_request_authorization(method, resource, key, params, headers)[source]
static hmac_sha1(content, key)[source]
static is_row_ip(ip)[source]
static url_encode(params)[source]

Module contents