How to use log method of is Package

Best Is code snippet using is.log

Run Is automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

constants.go

Source: constants.go Github

copy
1/*
2http://www.apache.org/licenses/LICENSE-2.0.txt
3
4
5Copyright 2017 Intel Corporation
6
7Licensed under the Apache License, Version 2.0 (the "License");
8you may not use this file except in compliance with the License.
9You may obtain a copy of the License at
10
11    http://www.apache.org/licenses/LICENSE-2.0
12
13Unless required by applicable law or agreed to in writing, software
14distributed under the License is distributed on an "AS IS" BASIS,
15WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16See the License for the specific language governing permissions and
17limitations under the License.
18*/
19
20package nvdimm
21
22import (
23	log "github.com/Sirupsen/logrus"
24)
25
26// #cgo LDFLAGS: -L/lib64 -lixpdimm
27// #include <nvm_management.h>
28// #include <nvm_types.h>
29import "C"
30
31//go:generate stringer -type=EncryptionString
32//go:generate stringer -type=PoolHealthString
33//go:generate stringer -type=InterleaveSetHealth
34//go:generate stringer -type=TypeNamespace
35//go:generate stringer -type=HealthNamespace
36//go:generate stringer -type=StateNamespace
37
38type EncryptionString int
39type PoolHealthString int
40type InterleaveSetHealth int
41type TypeNamespace int
42type HealthNamespace int
43type StateNamespace int
44
45const (
46	NVM_ENCRYPTION_OFF    EncryptionString    = 0
47	NVM_ENCRYPTION_ON     EncryptionString    = 1
48	NVM_ENCRYPTION_IGNORE EncryptionString    = 2
49	UNKNOWN               PoolHealthString    = 0 // The pool health cannot be determined.
50	NORMAL                PoolHealthString    = 1 // All underlying AEP DIMM Persistent memory capacity is available.
51	PENDING               PoolHealthString    = 2 // A new memory allocation goal has been created but not applied.
52	ERROR                 PoolHealthString    = 3 // There is an issue with some or all of the underlying
53	LOCKED                PoolHealthString    = 4 // One or more of the underlying AEP DIMMs are locked.
54	HEALTH_UNKNOWN        InterleaveSetHealth = 0
55	HEALTH_NORMAL         InterleaveSetHealth = 1 // Available and underlying AEP DIMMs have good health.
56	DEGRADED              InterleaveSetHealth = 2 // In danger of failure, may have degraded performance.
57	FAILED                InterleaveSetHealth = 3 // Interleave set has failed and is unavailable.
58
59	TYPE_UNKNOWN    TypeNamespace = 0 // Type cannot be determined
60	TYPE_STORAGE    TypeNamespace = 1 // Storage namespace
61	TYPE_APP_DIRECT TypeNamespace = 2 // App Direct namespace
62
63	NAMESPACE_HEALTH_UNKNOWN      HealthNamespace = 0     // Namespace health cannot be determined
64	NAMESPACE_HEALTH_NORMAL       HealthNamespace = 5     // Namespace is OK
65	NAMESPACE_HEALTH_NONCRITICAL  HealthNamespace = 10    // Non-critical health issue
66	NAMESPACE_HEALTH_CRITICAL     HealthNamespace = 25    // Critical health issue
67	NAMESPACE_HEALTH_BROKENMIRROR HealthNamespace = 65535 // Broken mirror
68
69	STATE_UNKNOWN  StateNamespace = 0 // Cannot be determined
70	STATE_ENABLED  StateNamespace = 2 // Exposed to OS
71	STATE_DISABLED StateNamespace = 3 // Hidden from OS
72)
73
74func logError(code int) {
75	switch code {
76	case C.NVM_ERR_INVALIDPERMISSIONS:
77		log.Error("Invalid permissions")
78	case C.NVM_ERR_NOTSUPPORTED:
79		log.Error("This method is not supported in the current context")
80	case C.NVM_ERR_NOMEMORY:
81		log.Error("Not enough memory to complete the requested operation")
82	case C.NVM_ERR_UNKNOWN:
83		log.Error("An unknown error occurred")
84	case C.NVM_ERR_NOSIMULATOR:
85		log.Error("No simulator is loaded")
86	case C.NVM_ERR_BADDRIVER:
87		log.Error("The underlying software is missing or incompatible")
88	case C.NVM_ERR_NOTMANAGEABLE:
89		log.Error("The device is not manageable by the management software")
90	case C.NVM_ERR_DATATRANSFERERROR:
91		log.Error("There was an error in the data transfer")
92	case C.NVM_SUCCESS:
93		log.Debug("Success")
94	case C.NVM_ERR_BADERRORCODE:
95		log.Error("The return code was not valid")
96	case C.NVM_ERR_DEVICEERROR:
97		log.Error("There was an internal error in the device")
98	case C.NVM_ERR_DEVICEBUSY:
99		log.Error("The device is currently busy processing a long operation command")
100	case C.NVM_ERR_BADPASSPHRASE:
101		log.Error("The passphrase is not valid")
102	case C.NVM_ERR_INVALIDPASSPHRASE:
103		log.Error("The new passphrase does not meet the minimum requirements")
104	case C.NVM_ERR_SECURITYFROZEN:
105		log.Error("No changes can be made to the security state of the device")
106	case C.NVM_ERR_LIMITPASSPHRASE:
107		log.Error("The maximum passphrase submission limit has been reached")
108	case C.NVM_ERR_SECURITYDISABLED:
109		log.Error("Data at rest security is not enabled")
110	case C.NVM_ERR_BADDEVICE:
111		log.Error("The device identifier is not valid")
112	case C.NVM_ERR_ARRAYTOOSMALL:
113		log.Error("The array is not big enough")
114	case C.NVM_ERR_BADCALLBACK:
115		log.Error("The callback identifier is not valid")
116	case C.NVM_ERR_BADFILE:
117		log.Error("The file is not valid")
118	case C.NVM_ERR_BADPOOL:
119		log.Error("The pool identifier is not valid")
120	case C.NVM_ERR_BADNAMESPACE:
121		log.Error("The namespace identifier is not valid")
122	case C.NVM_ERR_BADBLOCKSIZE:
123		log.Error("The specified block size is not valid")
124	case C.NVM_ERR_BADSIZE:
125		log.Error("The size specified is not valid")
126	case C.NVM_ERR_BADFIRMWARE:
127		log.Error("The firmware image is not valid for the device")
128	case C.NVM_ERR_DRIVERFAILED:
129		log.Error("The device driver failed the requested operation")
130	case C.NVM_ERR_BADSOCKET:
131		log.Error("The processor socket identifier is not valid")
132	case C.NVM_ERR_BADSECURITYSTATE:
133		log.Error("Device security state does not permit the request")
134	case C.NVM_ERR_REQUIRESFORCE:
135		log.Error("This method requires the force flag to proceed")
136	case C.NVM_ERR_NAMESPACESEXIST:
137		log.Error("Existing namespaces must be deleted first")
138	case C.NVM_ERR_NOTFOUND:
139		log.Error("The requested item was not found")
140	case C.NVM_ERR_BADDEVICECONFIG:
141		log.Error("The configuration data is invalid or unrecognized.")
142	case C.NVM_ERR_DRIVERNOTALLOWED:
143		log.Error("Driver is not allowing this command")
144	case C.NVM_ERR_BADALIGNMENT:
145		log.Error("The specified size does not have the required alignment")
146	case C.NVM_ERR_BADTHRESHOLD:
147		log.Error("The threshold value is invalid.")
148	case C.NVM_ERR_EXCEEDSMAXSUBSCRIBERS:
149		log.Error("Exceeded maximum number of notify subscribers")
150	case C.NVM_ERR_BADNAMESPACETYPE:
151		log.Error("The specified namespace type is not valid")
152	case C.NVM_ERR_BADNAMESPACEENABLESTATE:
153		log.Error("The specified namespace enable state is not valid")
154	case C.NVM_ERR_BADNAMESPACESETTINGS:
155		log.Error("Could not create ns with specified settings")
156	case C.NVM_ERR_BADPCAT:
157		log.Error("The PCAT table is invalid")
158	case C.NVM_ERR_TOOMANYNAMESPACES:
159		log.Error("The maximum number of namespaces is already present")
160	case C.NVM_ERR_CONFIGNOTSUPPORTED:
161		log.Error("The requested configuration is not supported")
162	case C.NVM_ERR_SKUVIOLATION:
163		log.Error("The method is not supported because of a license violation")
164	case C.NVM_ERR_ARSINPROGRESS:
165		log.Error("Address range scrub in progress")
166	case C.NVM_ERR_BADSECURITYGOAL:
167		log.Error("No dimm found with matching security goal to create a NS")
168	case C.NVM_ERR_INVALIDPASSPHRASEFILE:
169		log.Error("The passphrase file is invalid")
170	case C.NVM_ERR_GOALPENDING:
171		log.Error("Memory allocation goal is pending reboot")
172	case C.NVM_ERR_BADPOOLHEALTH:
173		log.Error("Underlying persistent memory is unavailable")
174	case C.NVM_ERR_INVALIDMEMORYTYPE:
175		log.Error("The address does not match the specified memory type")
176	case C.NVM_ERR_INCOMPATIBLEFW:
177		log.Error("The firmware image is not compatible with this version of software")
178	case C.NVM_ERR_NAMESPACEBUSY:
179		log.Error("The namespace cannot be changed because it is in use by a file system")
180	case C.NVM_ERR_FWALREADYSTAGED:
181		log.Error("A firmware image is already staged for execution. A power cycle is required before another can be staged.")
182	case C.NVM_ERR_BADNFIT:
183		log.Error("The NFIT table is invalid")
184	default:
185		log.Error("Unrecognized error code. Please notify us.")
186	}
187}
188
189func convertSensorUnits(unit int) string {
190	var unit_name string
191	switch unit {
192	case 1: // UNIT_COUNT
193		unit_name = ""
194	case 2: // UNIT_CELSIUS
195		unit_name = "C"
196	case 21: // UNIT_SECONDS
197		unit_name = "s"
198	case 22: // UNIT_MINUTES
199		unit_name = "m"
200	case 23: // UNIT_HOURS
201		unit_name = "h"
202	case 39: // UNIT_CYCLES
203		unit_name = ""
204	case 65: // UNIT_PERCENT
205		unit_name = "%"
206	}
207	return unit_name
208}
209
Full Screen

logs.go

Source: logs.go Github

copy
1// THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.
2
3// Package logs provides a client for Amazon CloudWatch Logs.
4package logs
5
6import (
7	"net/http"
8	"time"
9
10	"github.com/awslabs/aws-sdk-go/aws"
11	"github.com/awslabs/aws-sdk-go/gen/endpoints"
12)
13
14// Logs is a client for Amazon CloudWatch Logs.
15type Logs struct {
16	client *aws.JSONClient
17}
18
19// New returns a new Logs client.
20func New(creds aws.CredentialsProvider, region string, client *http.Client) *Logs {
21	if client == nil {
22		client = http.DefaultClient
23	}
24
25	endpoint, service, region := endpoints.Lookup("logs", region)
26
27	return &Logs{
28		client: &aws.JSONClient{
29			Context: aws.Context{
30				Credentials: creds,
31				Service:     service,
32				Region:      region,
33			}, Client: client,
34			Endpoint:     endpoint,
35			JSONVersion:  "1.1",
36			TargetPrefix: "Logs_20140328",
37		},
38	}
39}
40
41// CreateLogGroup creates a new log group with the specified name. The name
42// of the log group must be unique within a region for an AWS account. You
43// can create up to 500 log groups per account. You must use the following
44// guidelines when naming a log group: Log group names can be between 1 and
45// 512 characters long. Allowed characters are a-z, 0-9, '_' (underscore),
46// '-' (hyphen), '/' (forward slash), and '.' (period).
47func (c *Logs) CreateLogGroup(req *CreateLogGroupRequest) (err error) {
48	// NRE
49	err = c.client.Do("CreateLogGroup", "POST", "/", req, nil)
50	return
51}
52
53// CreateLogStream creates a new log stream in the specified log group. The
54// name of the log stream must be unique within the log group. There is no
55// limit on the number of log streams that can exist in a log group. You
56// must use the following guidelines when naming a log stream: Log stream
57// names can be between 1 and 512 characters long. The ':' colon character
58// is not allowed.
59func (c *Logs) CreateLogStream(req *CreateLogStreamRequest) (err error) {
60	// NRE
61	err = c.client.Do("CreateLogStream", "POST", "/", req, nil)
62	return
63}
64
65// DeleteLogGroup deletes the log group with the specified name and
66// permanently deletes all the archived log events associated with it.
67func (c *Logs) DeleteLogGroup(req *DeleteLogGroupRequest) (err error) {
68	// NRE
69	err = c.client.Do("DeleteLogGroup", "POST", "/", req, nil)
70	return
71}
72
73// DeleteLogStream deletes a log stream and permanently deletes all the
74// archived log events associated with it.
75func (c *Logs) DeleteLogStream(req *DeleteLogStreamRequest) (err error) {
76	// NRE
77	err = c.client.Do("DeleteLogStream", "POST", "/", req, nil)
78	return
79}
80
81// DeleteMetricFilter deletes a metric filter associated with the specified
82// log group.
83func (c *Logs) DeleteMetricFilter(req *DeleteMetricFilterRequest) (err error) {
84	// NRE
85	err = c.client.Do("DeleteMetricFilter", "POST", "/", req, nil)
86	return
87}
88
89// DeleteRetentionPolicy deletes the retention policy of the specified log
90// group. Log events would not expire if they belong to log groups without
91// a retention policy.
92func (c *Logs) DeleteRetentionPolicy(req *DeleteRetentionPolicyRequest) (err error) {
93	// NRE
94	err = c.client.Do("DeleteRetentionPolicy", "POST", "/", req, nil)
95	return
96}
97
98// DescribeLogGroups returns all the log groups that are associated with
99// the AWS account making the request. The list returned in the response is
100// ASCII-sorted by log group name. By default, this operation returns up to
101// 50 log groups. If there are more log groups to list, the response would
102// contain a nextToken value in the response body. You can also limit the
103// number of log groups returned in the response by specifying the limit
104// parameter in the request.
105func (c *Logs) DescribeLogGroups(req *DescribeLogGroupsRequest) (resp *DescribeLogGroupsResponse, err error) {
106	resp = &DescribeLogGroupsResponse{}
107	err = c.client.Do("DescribeLogGroups", "POST", "/", req, resp)
108	return
109}
110
111// DescribeLogStreams returns all the log streams that are associated with
112// the specified log group. The list returned in the response is
113// ASCII-sorted by log stream name. By default, this operation returns up
114// to 50 log streams. If there are more log streams to list, the response
115// would contain a nextToken value in the response body. You can also limit
116// the number of log streams returned in the response by specifying the
117// limit parameter in the request.
118func (c *Logs) DescribeLogStreams(req *DescribeLogStreamsRequest) (resp *DescribeLogStreamsResponse, err error) {
119	resp = &DescribeLogStreamsResponse{}
120	err = c.client.Do("DescribeLogStreams", "POST", "/", req, resp)
121	return
122}
123
124// DescribeMetricFilters returns all the metrics filters associated with
125// the specified log group. The list returned in the response is
126// ASCII-sorted by filter name. By default, this operation returns up to 50
127// metric filters. If there are more metric filters to list, the response
128// would contain a nextToken value in the response body. You can also limit
129// the number of metric filters returned in the response by specifying the
130// limit parameter in the request.
131func (c *Logs) DescribeMetricFilters(req *DescribeMetricFiltersRequest) (resp *DescribeMetricFiltersResponse, err error) {
132	resp = &DescribeMetricFiltersResponse{}
133	err = c.client.Do("DescribeMetricFilters", "POST", "/", req, resp)
134	return
135}
136
137// GetLogEvents retrieves log events from the specified log stream. You can
138// provide an optional time range to filter the results on the event
139// timestamp . By default, this operation returns as much log events as can
140// fit in a response size of 1MB, up to 10,000 log events. The response
141// will always include a nextForwardToken and a nextBackwardToken in the
142// response body. You can use any of these tokens in subsequent
143// GetLogEvents requests to paginate through events in either forward or
144// backward direction. You can also limit the number of log events returned
145// in the response by specifying the limit parameter in the request.
146func (c *Logs) GetLogEvents(req *GetLogEventsRequest) (resp *GetLogEventsResponse, err error) {
147	resp = &GetLogEventsResponse{}
148	err = c.client.Do("GetLogEvents", "POST", "/", req, resp)
149	return
150}
151
152// PutLogEvents uploads a batch of log events to the specified log stream.
153// Every PutLogEvents request must include the sequenceToken obtained from
154// the response of the previous request. An upload in a newly created log
155// stream does not require a sequenceToken . The batch of events must
156// satisfy the following constraints: The maximum batch size is 32,768
157// bytes, and this size is calculated as the sum of all event messages in
158// UTF-8, plus 26 bytes for each log event. None of the log events in the
159// batch can be more than 2 hours in the future. None of the log events in
160// the batch can be older than 14 days or the retention period of the log
161// group. The log events in the batch must be in chronological ordered by
162// their timestamp The maximum number of log events in a batch is 1,000.
163func (c *Logs) PutLogEvents(req *PutLogEventsRequest) (resp *PutLogEventsResponse, err error) {
164	resp = &PutLogEventsResponse{}
165	err = c.client.Do("PutLogEvents", "POST", "/", req, resp)
166	return
167}
168
169// PutMetricFilter creates or updates a metric filter and associates it
170// with the specified log group. Metric filters allow you to configure
171// rules to extract metric data from log events ingested through
172// PutLogEvents requests.
173func (c *Logs) PutMetricFilter(req *PutMetricFilterRequest) (err error) {
174	// NRE
175	err = c.client.Do("PutMetricFilter", "POST", "/", req, nil)
176	return
177}
178
179// PutRetentionPolicy sets the retention of the specified log group. A
180// retention policy allows you to configure the number of days you want to
181// retain log events in the specified log group.
182func (c *Logs) PutRetentionPolicy(req *PutRetentionPolicyRequest) (err error) {
183	// NRE
184	err = c.client.Do("PutRetentionPolicy", "POST", "/", req, nil)
185	return
186}
187
188// TestMetricFilter tests the filter pattern of a metric filter against a
189// sample of log event messages. You can use this operation to validate the
190// correctness of a metric filter pattern.
191func (c *Logs) TestMetricFilter(req *TestMetricFilterRequest) (resp *TestMetricFilterResponse, err error) {
192	resp = &TestMetricFilterResponse{}
193	err = c.client.Do("TestMetricFilter", "POST", "/", req, resp)
194	return
195}
196
197// CreateLogGroupRequest is undocumented.
198type CreateLogGroupRequest struct {
199	LogGroupName aws.StringValue `json:"logGroupName"`
200}
201
202// CreateLogStreamRequest is undocumented.
203type CreateLogStreamRequest struct {
204	LogGroupName  aws.StringValue `json:"logGroupName"`
205	LogStreamName aws.StringValue `json:"logStreamName"`
206}
207
208// DeleteLogGroupRequest is undocumented.
209type DeleteLogGroupRequest struct {
210	LogGroupName aws.StringValue `json:"logGroupName"`
211}
212
213// DeleteLogStreamRequest is undocumented.
214type DeleteLogStreamRequest struct {
215	LogGroupName  aws.StringValue `json:"logGroupName"`
216	LogStreamName aws.StringValue `json:"logStreamName"`
217}
218
219// DeleteMetricFilterRequest is undocumented.
220type DeleteMetricFilterRequest struct {
221	FilterName   aws.StringValue `json:"filterName"`
222	LogGroupName aws.StringValue `json:"logGroupName"`
223}
224
225// DeleteRetentionPolicyRequest is undocumented.
226type DeleteRetentionPolicyRequest struct {
227	LogGroupName aws.StringValue `json:"logGroupName"`
228}
229
230// DescribeLogGroupsRequest is undocumented.
231type DescribeLogGroupsRequest struct {
232	Limit              aws.IntegerValue `json:"limit,omitempty"`
233	LogGroupNamePrefix aws.StringValue  `json:"logGroupNamePrefix,omitempty"`
234	NextToken          aws.StringValue  `json:"nextToken,omitempty"`
235}
236
237// DescribeLogGroupsResponse is undocumented.
238type DescribeLogGroupsResponse struct {
239	LogGroups []LogGroup      `json:"logGroups,omitempty"`
240	NextToken aws.StringValue `json:"nextToken,omitempty"`
241}
242
243// DescribeLogStreamsRequest is undocumented.
244type DescribeLogStreamsRequest struct {
245	Limit               aws.IntegerValue `json:"limit,omitempty"`
246	LogGroupName        aws.StringValue  `json:"logGroupName"`
247	LogStreamNamePrefix aws.StringValue  `json:"logStreamNamePrefix,omitempty"`
248	NextToken           aws.StringValue  `json:"nextToken,omitempty"`
249}
250
251// DescribeLogStreamsResponse is undocumented.
252type DescribeLogStreamsResponse struct {
253	LogStreams []LogStream     `json:"logStreams,omitempty"`
254	NextToken  aws.StringValue `json:"nextToken,omitempty"`
255}
256
257// DescribeMetricFiltersRequest is undocumented.
258type DescribeMetricFiltersRequest struct {
259	FilterNamePrefix aws.StringValue  `json:"filterNamePrefix,omitempty"`
260	Limit            aws.IntegerValue `json:"limit,omitempty"`
261	LogGroupName     aws.StringValue  `json:"logGroupName"`
262	NextToken        aws.StringValue  `json:"nextToken,omitempty"`
263}
264
265// DescribeMetricFiltersResponse is undocumented.
266type DescribeMetricFiltersResponse struct {
267	MetricFilters []MetricFilter  `json:"metricFilters,omitempty"`
268	NextToken     aws.StringValue `json:"nextToken,omitempty"`
269}
270
271// GetLogEventsRequest is undocumented.
272type GetLogEventsRequest struct {
273	EndTime       aws.LongValue    `json:"endTime,omitempty"`
274	Limit         aws.IntegerValue `json:"limit,omitempty"`
275	LogGroupName  aws.StringValue  `json:"logGroupName"`
276	LogStreamName aws.StringValue  `json:"logStreamName"`
277	NextToken     aws.StringValue  `json:"nextToken,omitempty"`
278	StartFromHead aws.BooleanValue `json:"startFromHead,omitempty"`
279	StartTime     aws.LongValue    `json:"startTime,omitempty"`
280}
281
282// GetLogEventsResponse is undocumented.
283type GetLogEventsResponse struct {
284	Events            []OutputLogEvent `json:"events,omitempty"`
285	NextBackwardToken aws.StringValue  `json:"nextBackwardToken,omitempty"`
286	NextForwardToken  aws.StringValue  `json:"nextForwardToken,omitempty"`
287}
288
289// InputLogEvent is undocumented.
290type InputLogEvent struct {
291	Message   aws.StringValue `json:"message"`
292	Timestamp aws.LongValue   `json:"timestamp"`
293}
294
295// LogGroup is undocumented.
296type LogGroup struct {
297	ARN               aws.StringValue  `json:"arn,omitempty"`
298	CreationTime      aws.LongValue    `json:"creationTime,omitempty"`
299	LogGroupName      aws.StringValue  `json:"logGroupName,omitempty"`
300	MetricFilterCount aws.IntegerValue `json:"metricFilterCount,omitempty"`
301	RetentionInDays   aws.IntegerValue `json:"retentionInDays,omitempty"`
302	StoredBytes       aws.LongValue    `json:"storedBytes,omitempty"`
303}
304
305// LogStream is undocumented.
306type LogStream struct {
307	ARN                 aws.StringValue `json:"arn,omitempty"`
308	CreationTime        aws.LongValue   `json:"creationTime,omitempty"`
309	FirstEventTimestamp aws.LongValue   `json:"firstEventTimestamp,omitempty"`
310	LastEventTimestamp  aws.LongValue   `json:"lastEventTimestamp,omitempty"`
311	LastIngestionTime   aws.LongValue   `json:"lastIngestionTime,omitempty"`
312	LogStreamName       aws.StringValue `json:"logStreamName,omitempty"`
313	StoredBytes         aws.LongValue   `json:"storedBytes,omitempty"`
314	UploadSequenceToken aws.StringValue `json:"uploadSequenceToken,omitempty"`
315}
316
317// MetricFilter is undocumented.
318type MetricFilter struct {
319	CreationTime          aws.LongValue          `json:"creationTime,omitempty"`
320	FilterName            aws.StringValue        `json:"filterName,omitempty"`
321	FilterPattern         aws.StringValue        `json:"filterPattern,omitempty"`
322	MetricTransformations []MetricTransformation `json:"metricTransformations,omitempty"`
323}
324
325// MetricFilterMatchRecord is undocumented.
326type MetricFilterMatchRecord struct {
327	EventMessage    aws.StringValue   `json:"eventMessage,omitempty"`
328	EventNumber     aws.LongValue     `json:"eventNumber,omitempty"`
329	ExtractedValues map[string]string `json:"extractedValues,omitempty"`
330}
331
332// MetricTransformation is undocumented.
333type MetricTransformation struct {
334	MetricName      aws.StringValue `json:"metricName"`
335	MetricNamespace aws.StringValue `json:"metricNamespace"`
336	MetricValue     aws.StringValue `json:"metricValue"`
337}
338
339// OutputLogEvent is undocumented.
340type OutputLogEvent struct {
341	IngestionTime aws.LongValue   `json:"ingestionTime,omitempty"`
342	Message       aws.StringValue `json:"message,omitempty"`
343	Timestamp     aws.LongValue   `json:"timestamp,omitempty"`
344}
345
346// PutLogEventsRequest is undocumented.
347type PutLogEventsRequest struct {
348	LogEvents     []InputLogEvent `json:"logEvents"`
349	LogGroupName  aws.StringValue `json:"logGroupName"`
350	LogStreamName aws.StringValue `json:"logStreamName"`
351	SequenceToken aws.StringValue `json:"sequenceToken,omitempty"`
352}
353
354// PutLogEventsResponse is undocumented.
355type PutLogEventsResponse struct {
356	NextSequenceToken aws.StringValue `json:"nextSequenceToken,omitempty"`
357}
358
359// PutMetricFilterRequest is undocumented.
360type PutMetricFilterRequest struct {
361	FilterName            aws.StringValue        `json:"filterName"`
362	FilterPattern         aws.StringValue        `json:"filterPattern"`
363	LogGroupName          aws.StringValue        `json:"logGroupName"`
364	MetricTransformations []MetricTransformation `json:"metricTransformations"`
365}
366
367// PutRetentionPolicyRequest is undocumented.
368type PutRetentionPolicyRequest struct {
369	LogGroupName    aws.StringValue  `json:"logGroupName"`
370	RetentionInDays aws.IntegerValue `json:"retentionInDays"`
371}
372
373// TestMetricFilterRequest is undocumented.
374type TestMetricFilterRequest struct {
375	FilterPattern    aws.StringValue `json:"filterPattern"`
376	LogEventMessages []string        `json:"logEventMessages"`
377}
378
379// TestMetricFilterResponse is undocumented.
380type TestMetricFilterResponse struct {
381	Matches []MetricFilterMatchRecord `json:"matches,omitempty"`
382}
383
384// avoid errors if the packages aren't referenced
385var _ time.Time
386
Full Screen

shim_test.go

Source: shim_test.go Github

copy
1/*
2Copyright IBM Corp. 2016 All Rights Reserved.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8     http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package shim
18
19import (
20	"os"
21	"testing"
22
23	"github.com/op/go-logging"
24)
25
26// Test Go shim functionality that can be tested outside of a real chaincode
27// context.
28
29// TestShimLogging simply tests that the APIs are working. These tests test
30// for correct control over the shim's logging object and the LogLevel
31// function.
32func TestShimLogging(t *testing.T) {
33	SetLoggingLevel(LogCritical)
34	if shimLoggingLevel != LogCritical {
35		t.Errorf("shimLoggingLevel is not LogCritical as expected")
36	}
37	if chaincodeLogger.IsEnabledFor(logging.DEBUG) {
38		t.Errorf("The chaincodeLogger should not be enabled for DEBUG")
39	}
40	if !chaincodeLogger.IsEnabledFor(logging.CRITICAL) {
41		t.Errorf("The chaincodeLogger should be enabled for CRITICAL")
42	}
43	var level LoggingLevel
44	var err error
45	level, err = LogLevel("debug")
46	if err != nil {
47		t.Errorf("LogLevel(debug) failed")
48	}
49	if level != LogDebug {
50		t.Errorf("LogLevel(debug) did not return LogDebug")
51	}
52	level, err = LogLevel("INFO")
53	if err != nil {
54		t.Errorf("LogLevel(INFO) failed")
55	}
56	if level != LogInfo {
57		t.Errorf("LogLevel(INFO) did not return LogInfo")
58	}
59	level, err = LogLevel("Notice")
60	if err != nil {
61		t.Errorf("LogLevel(Notice) failed")
62	}
63	if level != LogNotice {
64		t.Errorf("LogLevel(Notice) did not return LogNotice")
65	}
66	level, err = LogLevel("WaRnInG")
67	if err != nil {
68		t.Errorf("LogLevel(WaRnInG) failed")
69	}
70	if level != LogWarning {
71		t.Errorf("LogLevel(WaRnInG) did not return LogWarning")
72	}
73	level, err = LogLevel("ERRor")
74	if err != nil {
75		t.Errorf("LogLevel(ERRor) failed")
76	}
77	if level != LogError {
78		t.Errorf("LogLevel(ERRor) did not return LogError")
79	}
80	level, err = LogLevel("critiCAL")
81	if err != nil {
82		t.Errorf("LogLevel(critiCAL) failed")
83	}
84	if level != LogCritical {
85		t.Errorf("LogLevel(critiCAL) did not return LogCritical")
86	}
87	level, err = LogLevel("foo")
88	if err == nil {
89		t.Errorf("LogLevel(foo) did not fail")
90	}
91	if level != LogError {
92		t.Errorf("LogLevel(foo) did not return LogError")
93	}
94}
95
96// TestChaincodeLogging tests the logging APIs for chaincodes.
97func TestChaincodeLogging(t *testing.T) {
98
99	// From start() - We can't call start() from this test
100	format := logging.MustStringFormatter("%{time:15:04:05.000} [%{module}] %{level:.4s} : %{message}")
101	backend := logging.NewLogBackend(os.Stderr, "", 0)
102	backendFormatter := logging.NewBackendFormatter(backend, format)
103	logging.SetBackend(backendFormatter).SetLevel(logging.Level(shimLoggingLevel), "shim")
104
105	foo := NewLogger("foo")
106	bar := NewLogger("bar")
107
108	foo.Debugf("Foo is debugging: %d", 10)
109	bar.Infof("Bar is informational? %s.", "Yes")
110	foo.Noticef("NOTE NOTE NOTE")
111	bar.Warningf("Danger, Danger %s %s", "Will", "Robinson!")
112	foo.Errorf("I'm sorry Dave, I'm afraid I can't do that.")
113	bar.Criticalf("PI is not equal to 3.14, we computed it as %.2f", 4.13)
114
115	bar.Debug("Foo is debugging:", 10)
116	foo.Info("Bar is informational?", "Yes.")
117	bar.Notice("NOTE NOTE NOTE")
118	foo.Warning("Danger, Danger", "Will", "Robinson!")
119	bar.Error("I'm sorry Dave, I'm afraid I can't do that.")
120	foo.Critical("PI is not equal to", 3.14, ", we computed it as", 4.13)
121
122	foo.SetLevel(LogWarning)
123	if foo.IsEnabledFor(LogDebug) {
124		t.Errorf("'foo' should not be enabled for LogDebug")
125	}
126	if !foo.IsEnabledFor(LogCritical) {
127		t.Errorf("'foo' should be enabled for LogCritical")
128	}
129	bar.SetLevel(LogCritical)
130	if bar.IsEnabledFor(LogDebug) {
131		t.Errorf("'bar' should not be enabled for LogDebug")
132	}
133	if !bar.IsEnabledFor(LogCritical) {
134		t.Errorf("'bar' should be enabled for LogCritical")
135	}
136}
137
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Trigger log code on LambdaTest Cloud Grid

Execute automation tests with log on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)